Mojo-Webqq

 view release on metacpan or  search on metacpan

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

    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 1.211 second using v1.01-cache-2.11-cpan-49f99fa48dc )