Mojo-Webqq

 view release on metacpan or  search on metacpan

lib/Mojo/Webqq/Plugin/Perldoc.pm  view on Meta::CPAN

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
my $data = shift;
my $callback = sub{
    my($client,$msg)=@_;
    return if not $msg->allow_plugin;
    if($msg->content =~ /perldoc\s+-(v|f)\s+([^ ]+)/){
        $msg->allow_plugin(0);
        return if $msg->class eq "send" and $msg->from ne "api" and $msg->from ne "irc";
        my($p,$v) = ("-$1",$2);
        $client->spawn(
            cmd  =>sub{
                local @ARGV=($p,$v);
                require 5;
                exit(Pod::Perldoc->run());
            },
            exec_timeout => 5,
            exit_cb => sub {
                my($pid,$res)=@_;
                my $reply;
                if($res->{exit_status}==0){
                    $reply = $client->truncate($res->{stdout},max_lines=>8,max_bytes=>2000);
                    $reply .= "\n查看更多内容: http://perldoc.perl.org/functions/$v.html" if $p eq "-f";



( run in 0.488 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )