source: server/trunk/web/lib/Sophie/Model/Chat.pm @ 36

Last change on this file since 36 was 36, checked in by nanardon, 14 years ago
  • propery call fetchdata

command line parsing is done by the Model

  • Property svn:keywords set to Id Revision
File size: 1.3 KB
Line 
1package Sophie::Model::Chat;
2use Moose;
3use namespace::autoclean;
4use Getopt::Long;
5use Text::ParseWords;
6
7extends 'Catalyst::Model';
8
9our $VERSION = (q$Revision 17 $ =~ /(\d+)/)[0];
10
11=head1 NAME
12
13Sophie::Model::Chat - Catalyst Model
14
15=head1 DESCRIPTION
16
17Catalyst Model.
18
19=head1 AUTHOR
20
21Olivier Thauvin
22
23=head1 LICENSE
24
25This library is free software. You can redistribute it and/or modify
26it under the same terms as Perl itself.
27
28=cut
29
30my $cmds = {
31    'me' => {
32        code => sub { return 'Sophie Bot version: ' . $VERSION },
33    },
34    t => {
35        code => sub { 
36            my ($c, $context, @args) = @_;
37            local @ARGV = @args;
38            join(', ', @{ $_[0]->forward('/distrib/list', [ { 
39                distribution => $args[0],
40                release => $args[1],
41                arch => $args[2],
42                }, ]
43            ) });;
44        },
45    },
46};
47
48sub process {
49    my ( $self, $c, $context, $message) = @_;
50
51    my ($cmd, @args) = Text::ParseWords::shellwords($message);
52
53    my $msg;
54    if ($cmd) {
55        if (my $cmdr= $cmds->{$cmd}) {
56            $msg = $cmdr->{code}->($c, $context, @args);
57        } else {
58            $msg = 'No such command';
59        }
60    } else {
61        $msg = 'No command given';
62    }
63
64    return {
65        msg => $msg,
66    };
67}
68
69
70__PACKAGE__->meta->make_immutable;
71
721;
Note: See TracBrowser for help on using the repository browser.