source: server/trunk/web/lib/Sophie/Controller/Chat.pm @ 72

Last change on this file since 72 was 72, checked in by nanardon, 14 years ago
  • always add user's config in Chat query
File size: 1.6 KB
Line 
1package Sophie::Controller::Chat;
2use Moose;
3use namespace::autoclean;
4use Getopt::Long;
5use Text::ParseWords;
6
7BEGIN {extends 'Catalyst::Controller'; }
8
9=head1 NAME
10
11Sophie::Controller::Chat - Catalyst Controller
12
13=head1 DESCRIPTION
14
15Catalyst Controller.
16
17=head1 METHODS
18
19=cut
20
21
22=head2 index
23
24=cut
25
26sub index :Path :Args(0) {
27    my ( $self, $c ) = @_;
28
29
30}
31
32sub message : XMLRPC {
33    my ($self, $c, $contexts, $message, @msgargs) = @_;
34   
35    my $reqspec = {};
36    my @contexts = grep { $_ } (
37        $c->user_exists
38        ? ( 'default',
39            (ref $contexts
40                ? (@$contexts)
41                : ($contexts)
42            ),
43        )
44        : ()
45    );
46
47    foreach my $co (@contexts) {
48        if (ref($co) eq 'HASH') {
49            foreach (keys %$co) {
50                $reqspec->{$_} = $co->{$_};
51            }
52        } else {
53            if (my $coo = $c->forward('/user/fetchdata', [ $co ])) {
54                foreach (keys %$coo) { 
55                    $reqspec->{$_} = $coo->{$_};
56                }
57            }
58        }
59    }
60
61    my ($cmd, @args) = @msgargs
62        ? ($message, @msgargs)
63        : Text::ParseWords::shellwords($message);
64
65    if ($c->get_action( $cmd, '/chat/cmd' )) {
66        return $c->go('/chat/cmd/' . $cmd, [ $reqspec, @args ]);
67    } else {
68        $c->stash->{xmlrpc} = {
69            error => 'No such command',
70        };
71    }
72}
73
74=head1 AUTHOR
75
76Olivier Thauvin
77
78=head1 LICENSE
79
80This library is free software. You can redistribute it and/or modify
81it under the same terms as Perl itself.
82
83=cut
84
85__PACKAGE__->meta->make_immutable;
86
871;
Note: See TracBrowser for help on using the repository browser.