Changeset 102


Ignore:
Timestamp:
12/09/10 07:01:43 (13 years ago)
Author:
nanardon
Message:
  • support chat command help from POD
Location:
server/trunk/web/lib/Sophie
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • server/trunk/web/lib/Sophie/Controller/Chat/Cmd.pm

    r100 r102  
    2727=head2 REPLY 
    2828 
     29=head1 AVAILLABLE FUNCTIONS 
     30 
    2931=cut 
    3032 
     
    4446} 
    4547 
     48=head2 help [cmd] 
    4649 
     50Return help about command cmd or list availlable command.  
    4751 
     52=cut 
    4853 
    4954sub help : XMLRPC { 
    50     my ( $self, $c, $reqspec, @args ) = @_; 
    51     return $c->{stash}->{xmlrpc} = { 
    52         private_reply => 1, 
    53         message => [ 
    54             'availlable command:', 
    55             join(', ', grep { $_ !~ /^end$/ } @{ $self->_commands }), 
    56         ], 
     55    my ( $self, $c, $reqspec, $cmd ) = @_; 
     56    if ($cmd) { 
     57        my @message = grep { /\S+/ } split(/\n/, 
     58            $c->model('Help::POD')->bot_help_text($cmd) || 'No help availlable'); 
     59        return $c->{stash}->{xmlrpc} = { 
     60            private_reply => 1, 
     61            message => \@message, 
     62        }; 
     63    } else { 
     64        return $c->{stash}->{xmlrpc} = { 
     65            private_reply => 1, 
     66            message => [ 
     67                'availlable command:', 
     68                join(', ', grep { $_ !~ /^end$/ } @{ $self->_commands }), 
     69            ], 
     70        } 
    5771    } 
    5872} 
     73 
     74=head2 asv 
     75 
     76ASV means in french "age, sexe, ville" (age, sex and town). 
     77Return the version of the Chat module version. 
     78 
     79=cut 
    5980 
    6081sub asv : XMLRPC { 
     
    87108        message => \@message, 
    88109    } 
     110} 
     111 
     112sub v : XMLRPC { 
     113    my ($self, $c, @args) = @_; 
     114    $c->forward('version', [ @args ]); 
    89115} 
    90116 
  • server/trunk/web/lib/Sophie/Model/Help/POD.pm

    r62 r102  
    55use Pod::POM; 
    66use Pod::POM::View::HTML; 
     7use Pod::POM::View::Text; 
    78 
    89extends 'Catalyst::Model'; 
     
    3132    return values %{ $self->{pom} } 
    3233} 
     34 
     35sub bot_functions { 
     36    my ($self) = @_; 
     37    my $botpom = $self->{pom}{'Chat::Cmd'}; 
     38    foreach my $head1 ($botpom->content) { 
     39        $head1->title eq 'AVAILLABLE FUNCTIONS' or next; 
     40        return map { $_->title } $head1->content; 
     41    } 
     42} 
     43 
     44sub bot_help_text { 
     45    my ($self, $cmd) = @_; 
     46    my $botpom = $self->{pom}{'Chat::Cmd'}; 
     47    foreach my $head1 ($botpom->content) { 
     48        $head1->title eq 'AVAILLABLE FUNCTIONS' or next; 
     49        foreach ($head1->content) { 
     50            $_->title =~ /^\Q$cmd\E( |$)/ or next; 
     51            my $ppvt = Pod::POM::View::Text->new; 
     52            return $_->present($ppvt); 
     53        } 
     54        last; 
     55    } 
     56    return; 
     57} 
     58 
    3359 
    3460sub xmlrpc_functions { 
Note: See TracChangeset for help on using the changeset viewer.