| 1 | package WWW::WebDevout::BrowserSupportInfo; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 2 | our $VERSION = '0.0104'; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use URI; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use overload '%{}' => \&_overload; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 0 | ▶ | sub _overload { | ||||||||||||||||||||||||||
|
Subroutine
_overload: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 14 | 0 | return shift->browser_results; | |||||||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||
| 18 | 1 | my $class = shift; | |||||||||||||||||||||||||||
| 19 | 1 | ▶ | croak "Even number of arguments expected to new()" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | if @_ & 1; | ||||||||||||||||||||||||||||
| 21 | 1 | my %args = @_; | |||||||||||||||||||||||||||
| 22 | 1 | $args{ +uc } = delete $args{ $_ } for keys %args; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 1 | %args = ( | |||||||||||||||||||||||||||
| 25 | LONG => 0, | ||||||||||||||||||||||||||||
| 26 | BROWSERS => [ qw(IE6 IE7 IE8 FX1_5 FX2 FX3 OP8 OP9 KN3_5 SF2) ], | ||||||||||||||||||||||||||||
| 27 | %args, | ||||||||||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||||||||||
| 29 | #IE6-IE7-FX1_5-FX2-OP8-OP9-KN3_5-SF2 | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 1 | ▶ | unless ( exists $args{UA_ARGS}{timeout} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 1 | $args{UA_ARGS}{timeout} = 30; | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 1 | return bless [ \%args ], $class; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | ▶ | sub fetch { | ||||||||||||||||||||||||||
|
Subroutine
fetch: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 39 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 40 | 0 | my $input = shift; | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 0 | ▶ | croak "Undefined argument to fetch()" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | unless defined $input; | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | my $uri = URI->new('http://www.webdevout.net/lookup-support'); | |||||||||||||||||||||||||||
| 46 | $uri->query_form( | ||||||||||||||||||||||||||||
| 47 | 'q' => $input, | ||||||||||||||||||||||||||||
| 48 | 0 | 'uas' => join '-', @{ $self->browsers } | |||||||||||||||||||||||||||
| 49 | ); | ||||||||||||||||||||||||||||
| 50 | 0 | ▶ | my $ua = LWP::UserAgent->new( %{ $self->ua_args || {} } ); | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->ua_args || {}
MC/DC0%0/1
$self->ua_args || {}
$self->ua_args
Truth table0%0/2
A
A= $self->ua_args
| |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | my $response = $ua->get( $uri ); | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 0 | ▶ | if ( $response->is_success ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 0 | return $self->_parse_fetched( $response->content ); | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | else { | ||||||||||||||||||||||||||||
| 58 | 0 | $self->error( $response->status_line ); | |||||||||||||||||||||||||||
| 59 | 0 | return; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 0 | ▶ | sub _parse_fetched { | ||||||||||||||||||||||||||
|
Subroutine
_parse_fetched: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||
| 64 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 65 | 0 | my $content = shift; | |||||||||||||||||||||||||||
| 66 | 0 | ▶ | $content =~ s/^\s+|\s+$//g | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | if defined $content; | ||||||||||||||||||||||||||||
| 68 | 0 | ▶ | if ( not defined $content or not length $content ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $content and length $content
MC/DC0%0/2
defined $content and length $content
defined $content
length $content
Truth table0%0/3
A and B
A= defined $contentB= length $content
| |||||||||||||||||||||||||||||
| 69 | 0 | $self->error('No results'); | |||||||||||||||||||||||||||
| 70 | 0 | return; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | my %results; | |||||||||||||||||||||||||||
| 74 | 0 | ( my ( $what, $uri_info), @results{ @{ $self->browsers } } ) | |||||||||||||||||||||||||||
| 75 | 0 | = grep { defined } split /\n/, $content; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | keys %results; | |||||||||||||||||||||||||||
| 78 | 0 | ▶ | while ( my ( $browser, $info ) = each %results ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 0 | ▶ | $info =~ s/^\s*.+?:\s*// | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | if defined $info; | ||||||||||||||||||||||||||||
| 81 | 0 | $results{ $browser } = $info; | |||||||||||||||||||||||||||
| 82 | 0 | $self->browser_info( $browser => $info ); | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 0 | ▶ | if ( $self->long ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | $results{ $self->make_long_name( $_ ) } | ||||||||||||||||||||||||||||
| 87 | 0 | = delete $results{ $_ } for keys %results; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 0 | $self->browser_results( { %results } ); | |||||||||||||||||||||||||||
| 91 | 0 | $self->what( $what ); | |||||||||||||||||||||||||||
| 92 | 0 | $self->uri_info( $uri_info ); | |||||||||||||||||||||||||||
| 93 | 0 | @results{ qw(what uri_info) } = ( $what, $uri_info ); | |||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 0 | return $self->results( \%results ); | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 0 | ▶ | sub make_long_name { | ||||||||||||||||||||||||||
|
Subroutine
make_long_name: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 99 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 100 | 0 | ▶ | my $short_ua = shift | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | or return; | ||||||||||||||||||||||||||||
| 102 | 0 | my %long_name_for = ( | |||||||||||||||||||||||||||
| 103 | IE6 => 'Internet Explorer 6', | ||||||||||||||||||||||||||||
| 104 | IE7 => 'Internet Explorer 7', | ||||||||||||||||||||||||||||
| 105 | IE8 => 'Internet Explorer 7', | ||||||||||||||||||||||||||||
| 106 | FX1_5 => 'FireFox 1.5', | ||||||||||||||||||||||||||||
| 107 | FX2 => 'FireFox 2', | ||||||||||||||||||||||||||||
| 108 | FX3 => 'FireFox 3', | ||||||||||||||||||||||||||||
| 109 | OP8 => 'Opera 8', | ||||||||||||||||||||||||||||
| 110 | OP9 => 'Opera 9', | ||||||||||||||||||||||||||||
| 111 | KN3_5 => 'Konqueror 3.5', | ||||||||||||||||||||||||||||
| 112 | SF2 => 'Safari 2', | ||||||||||||||||||||||||||||
| 113 | ); | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 0 | return $long_name_for{ $short_ua }; | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | ###### ACCESSORS/MUTATORS | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 0 | ▶ | sub browser_info { | ||||||||||||||||||||||||||
|
Subroutine
browser_info: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 121 | 0 | my ( $self, $browser ) = splice @_, 0, 2; | |||||||||||||||||||||||||||
| 122 | 0 | ▶ | if ( @_ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | 0 | $self->[0]{INFO}{ $browser } = shift; | |||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | 0 | return $self->[0]{INFO}{ $browser }; | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 0 | ▶ | sub error { | ||||||||||||||||||||||||||
|
Subroutine
error: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 129 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 130 | 0 | ▶ | if ( @_ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | 0 | $self->[0]{ ERROR } = shift; | |||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | 0 | return $self->[0]{ ERROR }; | |||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 0 | ▶ | sub ua_args { | ||||||||||||||||||||||||||
|
Subroutine
ua_args: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 137 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 138 | 0 | ▶ | if ( @_ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 139 | 0 | $self->[0]{ UA_ARGS } = shift; | |||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | 0 | return $self->[0]{ UA_ARGS }; | |||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 0 | ▶ | sub long { | ||||||||||||||||||||||||||
|
Subroutine
long: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 145 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 146 | 0 | ▶ | if ( @_ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 147 | 0 | $self->[0]{ LONG } = shift; | |||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | 0 | return $self->[0]{ LONG }; | |||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 0 | ▶ | sub results { | ||||||||||||||||||||||||||
|
Subroutine
results: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 153 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 154 | 0 | ▶ | if ( @_ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 155 | 0 | $self->[0]{ RESULTS } = shift; | |||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | 0 | return $self->[0]{ RESULTS }; | |||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 0 | ▶ | sub browser_results { | ||||||||||||||||||||||||||
|
Subroutine
browser_results: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 161 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 162 | 0 | ▶ | if ( @_ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 163 | 0 | $self->[0]{ BROWSER_RESULTS } = shift; | |||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | 0 | return $self->[0]{ BROWSER_RESULTS }; | |||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | 0 | ▶ | sub what { | ||||||||||||||||||||||||||
|
Subroutine
what: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 170 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 171 | 0 | ▶ | if ( @_ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 172 | 0 | $self->[0]{ WHAT } = shift; | |||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||
| 174 | 0 | return $self->[0]{ WHAT }; | |||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | 0 | ▶ | sub uri_info { | ||||||||||||||||||||||||||
|
Subroutine
uri_info: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 179 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 180 | 0 | ▶ | if ( @_ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 181 | 0 | $self->[0]{ URI_INFO } = shift; | |||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | 0 | return $self->[0]{ URI_INFO }; | |||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | 0 | ▶ | sub browsers { | ||||||||||||||||||||||||||
|
Subroutine
browsers: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 187 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 188 | 0 | ▶ | if ( @_ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 189 | 0 | $self->[0]{ BROWSERS } = shift; | |||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||
| 191 | 0 | return $self->[0]{ BROWSERS }; | |||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | 2 | 1; | |||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | __END__ | ||||||||||||||||||||||||||||