mirror of
https://github.com/perlbot/perlbuut
synced 2025-06-09 03:25:41 -04:00
Merge branch 'master' of gitosis@isuckatdomains.net:perlbuut
Conflicts: var/factoids.db var/karma.db
This commit is contained in:
commit
71151d422b
1 changed files with 47 additions and 0 deletions
47
plugins/perldoc.pm
Normal file
47
plugins/perldoc.pm
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
use WWW::Shorten 'Metamark';
|
||||||
|
use URI::Encode qw(uri_encode);
|
||||||
|
|
||||||
|
no warnings 'void';
|
||||||
|
sub {
|
||||||
|
my( $said, $pm ) = @_;
|
||||||
|
|
||||||
|
my $url = "";
|
||||||
|
|
||||||
|
if ($said->{body} =~ /-q\s+(.*)/i) #faq questions
|
||||||
|
{#http://perldoc.perl.org/search.html?q=foo+bar
|
||||||
|
$url = "http://perldoc.perl.org/search.html?q=".uri_encode($1);
|
||||||
|
}
|
||||||
|
elsif ($said->{body} =~ /-f\s+(.*?)\s*/i) #functions, only use the first part of a multiword expression
|
||||||
|
{
|
||||||
|
#http://perldoc.perl.org/functions/abs.html
|
||||||
|
my $func = $1;
|
||||||
|
$func =~ s/^\s*(.*)\s*$/$1/; #trim whitespace
|
||||||
|
$func = lc($func); #all functions are lowercase, except the exception below
|
||||||
|
|
||||||
|
$func = "-X" if ($func eq "-x"); #only case where it isn't lowercase, its easier to test at this point
|
||||||
|
|
||||||
|
$url = "http://perldoc.perl.org/functions/".$1.".html"
|
||||||
|
}
|
||||||
|
elsif ($said->{body} =~ /-m\s+(.*)/i) # got a module!
|
||||||
|
{#http://search.cpan.org/search?query=foo%3ABar&mode=all
|
||||||
|
$url = "http://search.cpan.org/search?query=".uri_encode($1)."&mode=module";
|
||||||
|
}
|
||||||
|
elsif ($said->{body} =~ /::/) #module, go to cpan also
|
||||||
|
{
|
||||||
|
$url = "http://search.cpan.org/search?query=".uri_encode($said->{body})."&mode=module";
|
||||||
|
}
|
||||||
|
else # we've got just a plain word, use it as a doc title
|
||||||
|
{ #http://perldoc.perl.org/perlrun.html
|
||||||
|
if ($said->{body} =~ /\s*(\S+)\s*/)
|
||||||
|
{
|
||||||
|
$url = "http://perldoc.perl.org/$1.html";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
print "Please request a valid section of perl documentation; you may also use, -q, -f, and -m just like on the command line";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
print "Your documentation is available at: ", makeashorterlink($url);
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue