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