| 1 | # | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | package WWW::Mechanize::Plugin::FollowMetaRedirect; | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use HTML::TokeParser; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 3 | $VERSION = '0.03'; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 0 | ▶ | sub init { | ||||||||||||||||||||||||||
|
Subroutine
init: not called CC=1 SCAR=0.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 13 | 3 | ▶ | no strict 'refs'; ## no critic | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 0 | *{caller() . '::follow_meta_redirect'} = \&follow_meta_redirect; | |||||||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 19 | ▶ | sub follow_meta_redirect { | ||||||||||||||||||||||||||
|
Subroutine
follow_meta_redirect: called CC=11 SCAR=24.1
Pod
documented
| |||||||||||||||||||||||||||||
| 18 | 19 | my ($mech, %args) = @_; | |||||||||||||||||||||||||||
| 19 | 19 | ▶ | my $waiting = ( defined $args{ignore_wait} and $args{ignore_wait} ) ? 0 : 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $args{"ignore_wait"} and $args{"ignore_wait"}
MC/DC100%2/2
defined $args{"ignore_wait"} and $args{"ignore_wait"}
defined $args{"ignore_wait"}
$args{"ignore_wait"}
Truth table100%3/3
A and B
A= defined $args{"ignore_wait"}B= $args{"ignore_wait"}
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 19 | ▶ | my $p = HTML::TokeParser->new( \ $mech->content ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | or return; | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 19 | ▶ | while( my $token = $p->get_token ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | # the line should emerge before </head> | ||||||||||||||||||||||||||||
| 26 | 163 | ▶ | last if $token->[0] eq 'E' && $token->[1] eq 'head'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$token->[0] eq "E" and $token->[1] eq "head"
MC/DC100%2/2
$token->[0] eq "E" and $token->[1] eq "head"
$token->[0] eq "E"
$token->[1] eq "head"
Truth table100%3/3
A and B
A= $token->[0] eq "E"B= $token->[1] eq "head"
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 161 | my ($url, $sec) = &_extract( $token ); | |||||||||||||||||||||||||||
| 29 | 161 | ▶ | next if ! defined $url || $url eq ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $url or $url eq ""
MC/DC50%1/2
not defined $url or $url eq ""
not defined $url
$url eq ""
Truth table66%2/3
not(A) or B
A= not defined $urlB= $url eq ""
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 17 | ▶ | if( $waiting and defined $sec ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$waiting and defined $sec
MC/DC50%1/2
$waiting and defined $sec
$waiting
defined $sec
Truth table66%2/3
A and B
A= $waitingB= defined $sec
| |||||||||||||||||||||||||||||
| 32 | 2 | sleep int $sec; | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 17 | return $mech->get( $url ); | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 2 | return; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 3 | *WWW::Mechanize::follow_meta_redirect = \&follow_meta_redirect; | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 161 | ▶ | sub _extract { | ||||||||||||||||||||||||||
|
Subroutine
_extract: called CC=9 SCAR=22.9
| |||||||||||||||||||||||||||||
| 44 | 161 | my $token = shift; | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 161 | ▶ | if( $token->[0] eq 'S' and $token->[1] eq 'meta' ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$token->[0] eq "S" and $token->[1] eq "meta"
MC/DC100%2/2
$token->[0] eq "S" and $token->[1] eq "meta"
$token->[0] eq "S"
$token->[1] eq "meta"
Truth table100%3/3
A and B
A= $token->[0] eq "S"B= $token->[1] eq "meta"
| |||||||||||||||||||||||||||||
| 47 | 26 | ▶ | if( defined $token->[2] and ref $token->[2] eq 'HASH' ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $token->[2] and ref $token->[2] eq "HASH"
MC/DC0%0/2
defined $token->[2] and ref $token->[2] eq "HASH"
defined $token->[2]
ref $token->[2] eq "HASH"
Truth table33%1/3
A and B
A= defined $token->[2]B= ref $token->[2] eq "HASH"
| |||||||||||||||||||||||||||||
| 48 | 26 | ▶ | if( defined $token->[2]->{'http-equiv'} and $token->[2]->{'http-equiv'} =~ /^refresh$/io ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $token->[2]{"http-equiv"} and $token->[2]{"http-equiv"} =~ /^refresh$/io
MC/DC100%2/2
defined $token->[2]{"http-equiv"} and $token->[2]{"http-equiv"} =~ /^refresh$/io
defined $token->[2]{"http-equiv"}
$token->[2]{"http-equiv"} =~ /^refresh$/io
Truth table100%3/3
A and B
A= defined $token->[2]{"http-equiv"}B= $token->[2]{"http-equiv"} =~ /^refresh$/io
| |||||||||||||||||||||||||||||
| 49 | 17 | ▶ | if( defined $token->[2]->{'content'} and $token->[2]->{'content'} =~ m|^(([0-9]+)\s*;\s*)*url\='?([^']+)'?$|io ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $token->[2]{"content"} and $token->[2]{"content"} =~ /^(([0-9]+)\s*;\s*)*url\='?([^']+)'?$/io
MC/DC0%0/2
defined $token->[2]{"content"} and $token->[2]{"content"} =~ /^(([0-9]+)\s*;\s*)*url\='?([^']+)'?$/io
defined $token->[2]{"content"}
$token->[2]{"content"} =~ /^(([0-9]+)\s*;\s*)*url\='?([^']+)'?$/io
Truth table33%1/3
A and B
A= defined $token->[2]{"content"}B= $token->[2]{"content"} =~ /^(([0-9]+)\s*;\s*)*url\='?([^']+)'?$/io
| |||||||||||||||||||||||||||||
| 50 | 17 | return ($3, $2); | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 144 | return; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 3 | 1; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | __END__ | ||||||||||||||||||||||||||||