blib/lib/WWW/Expand/More.pm

filter: Statementstmt 34.2% 12 / 35 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 42.8% 3 / 7 Podpod 100% 2 / 2 totaltotal 26.1% 17 / 65 CC 9 SCAR 22.8
CC
9
Cov
23%
_default_ua
12.0
expand
12.0
expand_all
12.0
CRAP 9.8
↑ Summary
1 package WWW::Expand::More;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 ▶use Furl;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 our $VERSION = '0.02';
8  
9 0 ▶sub _default_ua {
Subroutine _default_ua: not called CC=3 SCAR=24.8
10 0 my $args = shift;
11  
12 Furl->new(
13 timeout => $args->{timeout} || 5,
14 0 ▶ agent => $args->{agent} || __PACKAGE__."/$VERSION",
Condition0%0/4
$args->{'timeout'} || 5
l!l
00
$args->{'agent'} || 'WWW::Expand::More' . "/$WWW::Expand::More::VERSION"
l!l
00
MC/DC0%0/1
$args->{'timeout'} || 5
$args->{'timeout'}
MC/DC0%0/1
$args->{'agent'} || 'WWW::Expand::More' . "/$WWW::Expand::More::VERSION"
$args->{'agent'}
Truth table0%0/2
A
A= $args->{'timeout'}
Aresult
11
00
Truth table0%0/2
A
A= $args->{'agent'}
Aresult
11
00
15 );
16 }
17  
18 2 our %CACHE = ();
19  
20 0 ▶sub expand {
Subroutine expand: not called CC=3 SCAR=24.8
Pod documented
21 0 my ($class, $url, $opt) = @_;
22  
23 0 ▶ return $CACHE{$url} if exists $CACHE{$url};
Branch: 1 branch
BranchTrueFalseTotal
if exists $WWW::Expand::More::CACHE{$url} 0 0 0
24  
25 0 my @urls;
26  
27 0 $class->_expand($url, \@urls);
28  
29 0 ▶ if ($opt->{cache}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{"cache"}) 0 0 0
30 0 $CACHE{$url} = $urls[-1];
31 }
32  
33 0 return $urls[-1];
34 }
35  
36 0 ▶sub expand_all {
Subroutine expand_all: not called CC=3 SCAR=24.8
Pod documented
37 0 my ($class, $url, $opt) = @_;
38  
39 0 ▶ return $CACHE{$url} if exists $CACHE{$url};
Branch: 1 branch
BranchTrueFalseTotal
if exists $WWW::Expand::More::CACHE{$url} 0 0 0
40  
41 0 my @urls;
42  
43 0 $class->_expand($url, \@urls);
44  
45 0 ▶ if ($opt->{cache}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{"cache"}) 0 0 0
46 0 $CACHE{$url} = [@urls];
47 }
48  
49 0 return @urls;
50 }
51  
52 0 ▶sub _expand {
Subroutine _expand: not called CC=3 SCAR=24.8
53 0 my ($class, $url, $urls, $opt) = @_;
54  
55 0 ▶ $opt->{ua} ||= _default_ua();
Condition0%0/3
$opt->{"ua"} ||= _default_ua()
l!l&&r!l&&!r
000
MC/DC0%0/2
$opt->{"ua"} ||= _default_ua()
$opt->{"ua"} _default_ua()
Truth table0%0/3
A ||= B
A= $opt->{"ua"}B= _default_ua()
ABresult
1X1
011
000
56  
57 0 push @{$urls}, $url;
58  
59 my $res = $opt->{ua}->request(
60 0 method => 'HEAD',
61 url => $url,
62 max_redirects => 0,
63 headers => [ Connection => 'close' ],
64 );
65  
66 0 ▶ if (my $next_url = $res->headers->header('location')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $next_url = $res->headers->header("location")) 0 0 0
67 0 return $class->_expand($next_url, $urls, $opt);
68 }
69 }
70  
71 2 1;
72  
73 __END__
↑ Summary