lib/Bot/BasicBot/Pluggable/Module/Bash.pm

filter: Statementstmt 83.3% 10 / 12 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 87.5% 14 / 16 CC 1 SCAR 0.7
CC
1
Cov
83%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« lib/Bot/BasicBot/Pluggable/Module/Foldoc.pm ↑ Summary
1 package Bot::BasicBot::Pluggable::Module::Bash;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Bot::BasicBot::Pluggable::Module;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use base qw(Bot::BasicBot::Pluggable::Module);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 0 ▶use XML::RSS;
Subroutine BEGIN: called CC=1 SCAR=2.6
8 use LWP::Simple ();
9 use HTML::Entities;
10  
11 sub said {
12 my ($self, $mess, $pri) = @_;
13  
14 my $body = $mess->{body};
15 my $who = $mess->{who};
16  
17 return unless ($pri == 2);
18 return unless $body =~ /^\s*bash\s+(\d+)/i;
19
20 my $id = $1;
21 my $rss = LWP::Simple::get("http://www.bash.org/xml/?$id");
22 return "Couldn't get content from Bash.org" unless defined $rss;
23
24 my $p = XML::RSS->new();
25 $p->parse($rss) || return "Couldn't parse the data I got :(";
26 my $item = shift @{$p->{'items'}} || return "Couldn't parse the data I got :(";
27  
28 my $description = $item->{'description'};
29
30 return "$id is not a valid Bash id apparently" if (!defined $description || $description eq 'The IRC Quote Database');
31  
32 $description = decode_entities($description);
33 $description =~ s!<br\s*\/?>!\n!gi;
34 return "${id}: $description";
35  
36 }
37  
38 sub help {
39 return "Commands: 'bash <id>'";
40 }
41  
42 1;
43  
44 __END__
« lib/Bot/BasicBot/Pluggable/Module/Foldoc.pm ↑ Summary