LiBot
view release on metacpan or search on metacpan
lib/LiBot/Handler/PerldocJP.pm view on Meta::CPAN
my $pid = fork();
$pid // do {
close $rh;
close $wh;
die $!;
};
if ($pid) {
# parent
close $wh;
my $ret = '';
my $sweep;
my $timer = AE::timer(
10, 0,
sub {
kill 9, $pid;
}
);
my $child;
$child = AE::child(
$pid,
sub {
undef $timer;
$ret =~ s/NAME\n//;
$ret =~ s/\nDESCRIPTION\n/\n/;
$ret = shorten_scalar( decode_utf8($ret), $self->limit );
if ( $arg =~ /\A[\$\@\%]/ ) {
$ret .= "\n\nhttp://perldoc.jp/perlvar";
}
elsif ( $arg =~ /\A-[a-z]\s+(.+)/ ) {
$ret .= "\n\nhttp://perldoc.jp/$1";
}
else {
$ret .= "\n\nhttp://perldoc.jp/$arg";
}
$cb->($ret);
undef $sweep;
undef $child;
}
);
$sweep = AE::io(
$rh, 0,
sub {
$ret .= scalar(<$rh>);
}
);
}
else {
# child
close $rh;
open STDERR, '>&', $wh
or die "failed to redirect STDERR to logfile";
open STDOUT, '>&', $wh
or die "failed to redirect STDOUT to logfile";
eval {
require Pod::PerldocJp;
local @ARGV = split /\s+/, $arg;
if ( @ARGV == 1 && $ARGV[0] =~ /^[\$\@\%]/ ) {
unshift @ARGV, '-v';
}
unshift @ARGV, '-J';
@ARGV = map { encode_utf8($_) } @ARGV;
Pod::PerldocJp->run();
};
warn $@ if $@;
exit 0;
}
}
);
}
1;
__END__
=encoding utf-8
=head1 NAME
LiBot::Handler::PerldocJP - Tell me link for perldoc.jp
=head1 SYNOPSIS
# config.pl
+{
'handlers' => [
'PerldocJP'
]
}
# script
<hsegawa> perldoc perlre
>bot< perlre - Perl æ£è¦è¡¨ç¾
>bot< ãã®ãã¼ã¸ã§ã¯ Perl ã§ã®æ£è¦è¡¨ç¾ã®æ§æã«ã¤ãã¦èª¬æãã¾ãã
>bot< ããããã¾ã§ã«æ£è¦è¡¨ç¾ã使ã£ããã¨ããªãã®ã§ããã°ã perlrequick ã«ã¯ã¤
>bot< ãã¯ã¹ã¿...
>bot< http://perldoc.jp/perlre
=head1 DESCRIPTION
This bot tell me a link for perldoc.jp.
=head1 CONFIGURATION
=over 4
=item limit
Limit length of pod
=back
( run in 1.884 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )