Chain.pm

filter: Statementstmt 97.0% 66 / 68 Branchbran 57.6% 15 / 26 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 91.6% 11 / 12 Podpod 0.0% 0 / 4 totaltotal 80.8% 93 / 115 SCAR 27.6
CC
15
Cov
85%
parse_chain
9.0
next_responses
6.1
BUILDARGS
3.2
CRAP 15.8
↑ Summary Chain/UA/LWP.pm »
1 package WWW::Chain;
2 5 our $AUTHORITY = 'cpan:GETTY';
3 # ABSTRACT: A web request chain
4 5 $WWW::Chain::VERSION = '0.006';
5  
6 5 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use MooX::Types::MooseLike::Base qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use Safe::Isa;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use WWW::Chain::UA::LWP;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 5 has stash => (
12 isa => HashRef,
13 is => 'lazy',
14 );
15  
16 4 ▶sub _build_stash {{}}
Subroutine _build_stash: called CC=1 SCAR=0.0
17  
18 5 has next_requests => (
19 isa => ArrayRef,
20 is => 'rwp',
21 clearer => 1,
22 required => 1,
23 );
24  
25 5 has next_coderef => (
26 #isa => CodeRef,
27 is => 'rwp',
28 clearer => 1,
29 );
30  
31 has done => (
32 isa => Bool,
33 is => 'rwp',
34 4 ▶ default => sub { 0 },
Subroutine __ANON__: called CC=1 SCAR=0.0
35 5 );
36  
37 has request_count => (
38 isa => Num,
39 is => 'rwp',
40 0 ▶ default => sub { 0 },
Subroutine __ANON__: not called CC=1 SCAR=6.9
41 5 );
42  
43 has result_count => (
44 isa => Num,
45 is => 'rwp',
46 4 ▶ default => sub { 0 },
Subroutine __ANON__: called CC=1 SCAR=0.0
47 5 );
48  
49 sub BUILDARGS {
50 4 ▶ my $self = shift;
Subroutine BUILDARGS: called CC=3 SCAR=11.8
Pod undocumented
51 4 ▶ return $_[0] if (scalar @_ == 1 && ref $_[0] eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ == 1 and ref $_[0] eq "HASH" 0 4 4
Condition33%1/3
scalar @_ == 1 and ref $_[0] eq "HASH"
!ll&&!rl&&r
400
MC/DC0%0/2
scalar @_ == 1 and ref $_[0] eq "HASH"
scalar @_ == 1 ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= scalar @_ == 1B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
52 4 my ( $next_requests, $next_coderef, @args ) = $self->parse_chain(@_);
53 return {
54 next_requests => $next_requests,
55 next_coderef => $next_coderef,
56 4 request_count => scalar @{$next_requests},
57 @args,
58 };
59 }
60  
61 sub request_with_lwp {
62 1 ▶ my ( $self ) = @_;
Subroutine request_with_lwp: called CC=1 SCAR=0.0
Pod undocumented
63 1 return WWW::Chain::UA::LWP->new->request_chain($self);
64 }
65  
66 sub parse_chain {
67 8 ▶ my ( $self, @args ) = @_;
Subroutine parse_chain: called CC=8 SCAR=22.0
Pod undocumented
68 8 my $coderef;
69 my @requests;
70 8 ▶ while (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 16 0 16
71 16 my $arg = shift @args;
72 16 ▶ if ( $arg->$_isa('HTTP::Request') ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($arg->$WWW::Chain::_isa('HTTP::Request')) { } 8 8 16
elsif (ref $arg eq 'CODE') { } 6 2 8
elsif (ref $arg eq '') { } 2 0 2
73 8 push @requests, $arg;
74 } elsif (ref $arg eq 'CODE') {
75 6 $coderef = $arg;
76 6 last;
77 } elsif (ref $arg eq '') {
78 2 ▶ die "".(ref $self)."->parse_chain '".$arg."' is not a known function" unless $self->can($arg);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->can($arg) 0 2 2
79 2 $coderef = $arg;
80 2 last;
81 } else {
82 0 ▶ die "".(ref $self)."->parse_chain got unparseable element".(defined $arg ? " ".$arg : "" );
Branch: 1 branch
BranchTrueFalseTotal
defined $arg ? : 0 0 0
83 }
84 }
85 8 ▶ die "".(ref $self)."->parse_chain found no HTTP::Request objects" unless @requests;
Branch: 1 branch
BranchTrueFalseTotal
unless @requests 0 8 8
86 8 return [@requests], $coderef, @args;
87 }
88  
89 sub next_responses {
90 8 ▶ my ( $self, @responses ) = @_;
Subroutine next_responses: called CC=6 SCAR=18.0
Pod undocumented
91 8 ▶ die "".(ref $self)."->next_responses can't be called on chain which is done." if $self->done;
Branch: 1 branch
BranchTrueFalseTotal
if $self->done 0 8 8
92 8 my $amount = scalar @{$self->next_requests};
93 8 ▶ die "".(ref $self)."->next_responses would need ".$amount." HTTP::Response objects to proceed"
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @responses == $amount 0 8 8
94 unless scalar @responses == $amount;
95 die "".(ref $self)."->next_responses only takes HTTP::Response objects"
96 8 ▶ if grep { !$_->isa('HTTP::Response') } @responses;
Branch: 1 branch
BranchTrueFalseTotal
if grep {not $_->isa("HTTP::Response");} @responses 0 8 8
97 8 $self->clear_next_requests;
98 8 my @result = $self->${\$self->next_coderef}(@responses);
99 8 $self->clear_next_coderef;
100 8 $self->_set_result_count($self->result_count + 1);
101 8 ▶ if ( $result[0]->$_isa('HTTP::Request') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result[0]->$WWW::Chain::_isa("HTTP::Request")) 4 4 8
102 4 my ( $next_requests, $next_coderef, @args ) = $self->parse_chain(@result);
103 4 ▶ die "".(ref $self)."->next_responses can't parse the result, more arguments after CodeRef" if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 4 4
104 4 $self->_set_next_requests($next_requests);
105 4 $self->_set_next_coderef($next_coderef);
106 4 $self->_set_request_count($self->request_count + scalar @{$next_requests});
107 4 return 0;
108 }
109 4 $self->_set_done(1);
110 4 return $self->stash;
111 }
112  
113 5 1;
114  
115 __END__
↑ Summary Chain/UA/LWP.pm »