Plugin/WWW/GetPageTitle.pm

filter: Statementstmt 35.7% 20 / 56 Branchbran 0.0% 0 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 46.1% 6 / 13 Podpod n/a totaltotal 29.8% 26 / 87 CC 11 SCAR 25.3
CC
11
Cov
27%
_make_poco_call
30.0
_make_response_message
20.0
_make_response_event
12.0
CRAP 12.6
« Plugin/WWW/HTMLTagAttributeCounter.pm ↑ Summary Plugin/ColorNamer.pm »
1 package POE::Component::IRC::Plugin::WWW::GetPageTitle;
2  
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = '2.001004'; # VERSION
7  
8 1 ▶use base 'POE::Component::IRC::Plugin::BasePoCoWrap';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use POE::Component::WWW::GetPageTitle;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use URI::Find::Schemeless;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 0 ▶sub _make_default_args {
Subroutine _make_default_args: not called CC=1 SCAR=6.9
14 return (
15 0 response_event => 'irc_get_page_title',
16 trigger => qr/^title\s+(?=\S)/i,
17 );
18 }
19  
20 0 ▶sub _make_poco {
Subroutine _make_poco: not called CC=2 SCAR=17.9
21 0 my $self = shift;
22 return POE::Component::WWW::GetPageTitle->spawn(
23 0 ▶ $self->{ua} ? ( ua => $self->{ua} ) : ()
Branch: 1 branch
BranchTrueFalseTotal
$self->{'ua'} ? : 0 0 0
24 );
25 }
26  
27 0 ▶sub _make_response_message {
Subroutine _make_response_message: not called CC=4 SCAR=30.0
28 0 my $self = shift;
29 0 my $in_ref = shift;
30 defined $in_ref->{title}
31 0 ▶ and $in_ref->{title} =~ s/\s/ /g;
Branch: 1 branch
BranchTrueFalseTotal
defined $in_ref->{"title"} and $in_ref->{"title"} =~ s/\s/ /g 0 0 0
32  
33 return [
34 exists $in_ref->{error}
35 ? $in_ref->{error}
36 : '[' . URI->new(
37 $in_ref->{page} =~ m|^https?://|i ? $in_ref->{page} : "http://$in_ref->{page}"
38 )->authority . '] ' . $in_ref->{title}
39 0 ▶ ];
Branch: 2 branches
BranchTrueFalseTotal
exists $in_ref->{'error'} ? : 0 0 0
$in_ref->{'page'} =~ m[^https?://]i ? : 0 0 0
40 }
41  
42 0 ▶sub _make_response_event {
Subroutine _make_response_event: not called CC=3 SCAR=24.8
43 0 my $self = shift;
44 0 my $in_ref = shift;
45  
46 return {
47 ( exists $in_ref->{error}
48 ? ( error => $in_ref->{error} )
49 : (
50 title => '[' . URI->new(
51 $in_ref->{page} =~ m|^https?://|i ? $in_ref->{page}
52 : "http://$in_ref->{page}"
53 )->authority . '] ' . $in_ref->{title}
54 )
55 ),
56  
57 0 ▶ map { $_ => $in_ref->{"_$_"} }
Branch: 2 branches
BranchTrueFalseTotal
exists $in_ref->{'error'} ? : 0 0 0
$in_ref->{'page'} =~ m[^https?://]i ? : 0 0 0
58 qw( who channel message type what ),
59 }
60 }
61  
62 0 ▶sub _make_poco_call {
Subroutine _make_poco_call: not called CC=5 SCAR=34.0
63 0 my $self = shift;
64 0 my $data_ref = shift;
65  
66 0 ▶ if ( $self->{find_uris} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'find_uris'}) { } 0 0 0
67 0 $self->{finder} = [];
68 0 ▶ my $finder = URI::Find::Schemeless->new( sub { $self->_uri_callback(shift) } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
69 0 $finder->find( \ $data_ref->{what} );
70 }
71 else {
72 0 $self->{finder} = [ $data_ref->{what} ];
73 }
74  
75 0 ▶ if ( $self->{max_uris} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"max_uris"}) 0 0 0
76 0 @{ $self->{finder} } = splice @{ $self->{finder} }, 0, $self->{max_uris};
77 }
78  
79 0 ▶ if ( $self->{debug} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"debug"}) 0 0 0
80 print "Going to fetch titles for the following URIs:\n",
81 0 join "\n", @{ $self->{finder} }, '';
82 }
83  
84 0 @{ $self->{finder} } = grep !/^ftp/i, @{ $self->{finder} };
85  
86 0 for ( @{ $self->{finder} } ) {
87 $self->{poco}->get_title( {
88 event => '_poco_done',
89 page => $_,
90 0 map +( "_$_" => $data_ref->{$_} ),
91 keys %$data_ref,
92 }
93 );
94 }
95 }
96  
97 0 ▶sub _uri_callback {
Subroutine _uri_callback: not called CC=1 SCAR=6.9
98 0 my ( $self, $uri ) = @_;
99 0 push @{ $self->{finder} }, $uri;
100 0 $uri;
101 }
102  
103 1 1;
104 __END__
« Plugin/WWW/HTMLTagAttributeCounter.pm ↑ Summary Plugin/ColorNamer.pm »