| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 76 | 0 | @{ $self->{finder} } = splice @{ $self->{finder} }, 0, $self->{max_uris}; | |||||||||||||
| 77 | } | ||||||||||||||
| 78 | |||||||||||||||
| 79 | 0 | ▶ | if ( $self->{debug} ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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__ | ||||||||||||||