| 1 | package 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 = '0.0104'; | |||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 1 | ▶ | use LWP::UserAgent; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 1 | ▶ | use HTML::Entities; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 1 | ▶ | use base 'Class::Data::Accessor'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 1 | __PACKAGE__->mk_classaccessors( qw/ | |||||||||||||||||||
| 12 | error | ||||||||||||||||||||
| 13 | title | ||||||||||||||||||||
| 14 | ua | ||||||||||||||||||||
| 15 | uri | ||||||||||||||||||||
| 16 | /); | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 0 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 19 | 0 | my ( $class, %args ) = @_; | |||||||||||||||||||
| 20 | 0 | my $self = bless {}, $class; | |||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | $self->ua( | ||||||||||||||||||||
| 23 | $args{ua} | ||||||||||||||||||||
| 24 | || | ||||||||||||||||||||
| 25 | 0 | ▶ | LWP::UserAgent->new( | ||||||||||||||||||
|
Condition0%0/3
$args{'ua'} || 'LWP::UserAgent'->new('agent', 'Mozilla', 'timeout', 30, 'max_size', 2000)
MC/DC0%0/2
$args{'ua'} || 'LWP::UserAgent'->new('agent', 'Mozilla', 'timeout', 30, 'max_size', 2000)
$args{'ua'}
'LWP::UserAgent'->new('agent', 'Mozilla', 'timeout', 30, 'max_size', 2000)
Truth table0%0/3
A || B
A= $args{'ua'}B= 'LWP::UserAgent'->new('agent', 'Mozilla', 'timeout', 30, 'max_size', 2000)
| |||||||||||||||||||||
| 26 | agent => "Mozilla", | ||||||||||||||||||||
| 27 | timeout => 30, | ||||||||||||||||||||
| 28 | max_size => 2000, | ||||||||||||||||||||
| 29 | ) | ||||||||||||||||||||
| 30 | ); | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 0 | return $self; | |||||||||||||||||||
| 33 | } | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 0 | ▶ | sub get_title { | ||||||||||||||||||
|
Subroutine
get_title: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||
| 36 | 0 | my ( $self, $uri ) = @_; | |||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 0 | ▶ | $uri = "http://$uri" | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 39 | unless $uri =~ m{^(?:https?|ftps?)://}i; | ||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 0 | $self->uri( $uri ); | |||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | $self->$_(undef) | ||||||||||||||||||||
| 44 | 0 | for qw/title error/; | |||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | 0 | my $response = $self->ua->get($uri); | |||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 0 | ▶ | unless ( $response->is_success ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 49 | 0 | $self->error("Network error: " . $response->status_line ); | |||||||||||||||||||
| 50 | 0 | return; | |||||||||||||||||||
| 51 | } | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 0 | my $title = $response->title; | |||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 0 | ▶ | unless ( defined $title ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 56 | 0 | ( $title ) = $response->decoded_content =~ m|<title[^>]*>(.+?)</title>|si; | |||||||||||||||||||
| 57 | 0 | ▶ | decode_entities( $title ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 58 | if defined $title; | ||||||||||||||||||||
| 59 | } | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | 0 | ▶ | $title = 'N/A' | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 62 | unless defined $title; | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 0 | return $self->title( $title ); | |||||||||||||||||||
| 65 | } | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | 1 | 1; | |||||||||||||||||||
| 68 | __END__ | ||||||||||||||||||||