File Coverage

blib/lib/POE/Component/IRC/Plugin/WWW/OhNoRobotCom/Search.pm
Criterion Covered Total %
statement 7 9 77.7
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 10 12 83.3


line stmt bran cond sub pod time code
1             package POE::Component::IRC::Plugin::WWW::OhNoRobotCom::Search;
2              
3 1     1   37140 use warnings;
  1         3  
  1         34  
4 1     1   5 use strict;
  1         2  
  1         52  
5              
6             our $VERSION = '0.002';
7              
8 1     1   418 use POE::Component::WWW::OhNoRobotCom::Search;
  0            
  0            
9             use base 'POE::Component::IRC::Plugin::BasePoCoWrap';
10              
11             sub _make_default_args {
12             return (
13             response_event => 'irc_ohnorobot_results',
14             trigger => qr/^comics?\s+(?=\S+)/i,
15             obj_args => { },
16             max_results => 3,
17             );
18             }
19              
20             sub _make_poco {
21             my $self = shift;
22             return POE::Component::WWW::OhNoRobotCom::Search->spawn(
23             %{ $self->{obj_args} || {} }
24             );
25             }
26              
27             sub _make_response_message {
28             my ( $self, $in_ref ) = @_;
29             my @out = exists $in_ref->{error}
30             ? $in_ref->{error}
31             : sort keys %{ $in_ref->{results} };
32              
33             @out = splice @out, 0, $self->{max_results};
34              
35             return [ join ' ', @out ];
36             }
37              
38             sub _make_response_event {
39             my $self = shift;
40             my $in_ref = shift;
41              
42             return {
43             ( exists $in_ref->{error}
44             ? ( error => $in_ref->{error} )
45             : ( results => $in_ref->{results} )
46             ),
47             term => $in_ref->{term},
48             map { $_ => $in_ref->{"_$_"} }
49             qw( who channel message type ),
50             }
51             }
52              
53             sub _make_poco_call {
54             my ( $self, $data_ref ) = @_;
55              
56             $self->{poco}->search({
57             event => '_poco_done',
58             term => delete $data_ref->{what},
59             map( +( exists $self->{$_} ? ( $_ => $self->{$_} ) : () ),
60             qw(max_results comic_id include lucky)
61             ),
62             map +( "_$_" => $data_ref->{$_} ),
63             keys %$data_ref,
64             }
65             );
66             }
67              
68             1;
69             __END__