Last change
on this file since 36 was
36,
checked in by nanardon, 14 years ago
|
command line parsing is done by the Model
|
-
Property svn:keywords set to
Id Revision
|
File size:
1.3 KB
|
Line | |
---|
1 | package Sophie::Model::Chat; |
---|
2 | use Moose; |
---|
3 | use namespace::autoclean; |
---|
4 | use Getopt::Long; |
---|
5 | use Text::ParseWords; |
---|
6 | |
---|
7 | extends 'Catalyst::Model'; |
---|
8 | |
---|
9 | our $VERSION = (q$Revision 17 $ =~ /(\d+)/)[0]; |
---|
10 | |
---|
11 | =head1 NAME |
---|
12 | |
---|
13 | Sophie::Model::Chat - Catalyst Model |
---|
14 | |
---|
15 | =head1 DESCRIPTION |
---|
16 | |
---|
17 | Catalyst Model. |
---|
18 | |
---|
19 | =head1 AUTHOR |
---|
20 | |
---|
21 | Olivier Thauvin |
---|
22 | |
---|
23 | =head1 LICENSE |
---|
24 | |
---|
25 | This library is free software. You can redistribute it and/or modify |
---|
26 | it under the same terms as Perl itself. |
---|
27 | |
---|
28 | =cut |
---|
29 | |
---|
30 | my $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 | |
---|
48 | sub 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 | |
---|
72 | 1; |
---|
Note: See
TracBrowser
for help on using the repository browser.