line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::Chain; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:GETTY'; |
3
|
|
|
|
|
|
|
# ABSTRACT: A web request chain |
4
|
|
|
|
|
|
|
$WWW::Chain::VERSION = '0.006'; |
5
|
|
|
|
|
|
|
|
6
|
5
|
|
|
5
|
|
434724
|
use Moo; |
|
5
|
|
|
|
|
54536
|
|
|
5
|
|
|
|
|
25
|
|
7
|
5
|
|
|
5
|
|
9642
|
use MooX::Types::MooseLike::Base qw(:all); |
|
5
|
|
|
|
|
33472
|
|
|
5
|
|
|
|
|
1649
|
|
8
|
5
|
|
|
5
|
|
2319
|
use Safe::Isa; |
|
5
|
|
|
|
|
2314
|
|
|
5
|
|
|
|
|
597
|
|
9
|
5
|
|
|
5
|
|
2139
|
use WWW::Chain::UA::LWP; |
|
5
|
|
|
|
|
20
|
|
|
5
|
|
|
|
|
3868
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has stash => ( |
12
|
|
|
|
|
|
|
isa => HashRef, |
13
|
|
|
|
|
|
|
is => 'lazy', |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
|
16
|
4
|
|
|
4
|
|
3053
|
sub _build_stash {{}} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has next_requests => ( |
19
|
|
|
|
|
|
|
isa => ArrayRef, |
20
|
|
|
|
|
|
|
is => 'rwp', |
21
|
|
|
|
|
|
|
clearer => 1, |
22
|
|
|
|
|
|
|
required => 1, |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
has next_coderef => ( |
26
|
|
|
|
|
|
|
#isa => CodeRef, |
27
|
|
|
|
|
|
|
is => 'rwp', |
28
|
|
|
|
|
|
|
clearer => 1, |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
has done => ( |
32
|
|
|
|
|
|
|
isa => Bool, |
33
|
|
|
|
|
|
|
is => 'rwp', |
34
|
|
|
|
|
|
|
default => sub { 0 }, |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
has request_count => ( |
38
|
|
|
|
|
|
|
isa => Num, |
39
|
|
|
|
|
|
|
is => 'rwp', |
40
|
|
|
|
|
|
|
default => sub { 0 }, |
41
|
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
has result_count => ( |
44
|
|
|
|
|
|
|
isa => Num, |
45
|
|
|
|
|
|
|
is => 'rwp', |
46
|
|
|
|
|
|
|
default => sub { 0 }, |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub BUILDARGS { |
50
|
4
|
|
|
4
|
0
|
62682
|
my $self = shift; |
51
|
4
|
50
|
33
|
|
|
30
|
return $_[0] if (scalar @_ == 1 && ref $_[0] eq 'HASH'); |
52
|
4
|
|
|
|
|
24
|
my ( $next_requests, $next_coderef, @args ) = $self->parse_chain(@_); |
53
|
|
|
|
|
|
|
return { |
54
|
|
|
|
|
|
|
next_requests => $next_requests, |
55
|
|
|
|
|
|
|
next_coderef => $next_coderef, |
56
|
4
|
|
|
|
|
13
|
request_count => scalar @{$next_requests}, |
|
4
|
|
|
|
|
97
|
|
57
|
|
|
|
|
|
|
@args, |
58
|
|
|
|
|
|
|
}; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub request_with_lwp { |
62
|
1
|
|
|
1
|
0
|
51
|
my ( $self ) = @_; |
63
|
1
|
|
|
|
|
25
|
return WWW::Chain::UA::LWP->new->request_chain($self); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub parse_chain { |
67
|
8
|
|
|
8
|
0
|
31
|
my ( $self, @args ) = @_; |
68
|
8
|
|
|
|
|
19
|
my $coderef; |
69
|
|
|
|
|
|
|
my @requests; |
70
|
8
|
|
|
|
|
36
|
while (@args) { |
71
|
16
|
|
|
|
|
32
|
my $arg = shift @args; |
72
|
16
|
100
|
|
|
|
84
|
if ( $arg->$_isa('HTTP::Request') ) { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
73
|
8
|
|
|
|
|
258
|
push @requests, $arg; |
74
|
|
|
|
|
|
|
} elsif (ref $arg eq 'CODE') { |
75
|
6
|
|
|
|
|
67
|
$coderef = $arg; |
76
|
6
|
|
|
|
|
15
|
last; |
77
|
|
|
|
|
|
|
} elsif (ref $arg eq '') { |
78
|
2
|
50
|
|
|
|
29
|
die "".(ref $self)."->parse_chain '".$arg."' is not a known function" unless $self->can($arg); |
79
|
2
|
|
|
|
|
5
|
$coderef = $arg; |
80
|
2
|
|
|
|
|
3
|
last; |
81
|
|
|
|
|
|
|
} else { |
82
|
0
|
0
|
|
|
|
0
|
die "".(ref $self)."->parse_chain got unparseable element".(defined $arg ? " ".$arg : "" ); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
8
|
50
|
|
|
|
37
|
die "".(ref $self)."->parse_chain found no HTTP::Request objects" unless @requests; |
86
|
8
|
|
|
|
|
36
|
return [@requests], $coderef, @args; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub next_responses { |
90
|
8
|
|
|
8
|
0
|
2243
|
my ( $self, @responses ) = @_; |
91
|
8
|
50
|
|
|
|
58
|
die "".(ref $self)."->next_responses can't be called on chain which is done." if $self->done; |
92
|
8
|
|
|
|
|
18
|
my $amount = scalar @{$self->next_requests}; |
|
8
|
|
|
|
|
29
|
|
93
|
8
|
50
|
|
|
|
30
|
die "".(ref $self)."->next_responses would need ".$amount." HTTP::Response objects to proceed" |
94
|
|
|
|
|
|
|
unless scalar @responses == $amount; |
95
|
|
|
|
|
|
|
die "".(ref $self)."->next_responses only takes HTTP::Response objects" |
96
|
8
|
50
|
|
|
|
22
|
if grep { !$_->isa('HTTP::Response') } @responses; |
|
8
|
|
|
|
|
81
|
|
97
|
8
|
|
|
|
|
221
|
$self->clear_next_requests; |
98
|
8
|
|
|
|
|
90
|
my @result = $self->${\$self->next_coderef}(@responses); |
|
8
|
|
|
|
|
61
|
|
99
|
8
|
|
|
|
|
15889
|
$self->clear_next_coderef; |
100
|
8
|
|
|
|
|
300
|
$self->_set_result_count($self->result_count + 1); |
101
|
8
|
100
|
|
|
|
411
|
if ( $result[0]->$_isa('HTTP::Request') ) { |
102
|
4
|
|
|
|
|
114
|
my ( $next_requests, $next_coderef, @args ) = $self->parse_chain(@result); |
103
|
4
|
50
|
|
|
|
18
|
die "".(ref $self)."->next_responses can't parse the result, more arguments after CodeRef" if @args; |
104
|
4
|
|
|
|
|
102
|
$self->_set_next_requests($next_requests); |
105
|
4
|
|
|
|
|
249
|
$self->_set_next_coderef($next_coderef); |
106
|
4
|
|
|
|
|
19
|
$self->_set_request_count($self->request_count + scalar @{$next_requests}); |
|
4
|
|
|
|
|
89
|
|
107
|
4
|
|
|
|
|
241
|
return 0; |
108
|
|
|
|
|
|
|
} |
109
|
4
|
|
|
|
|
128
|
$self->_set_done(1); |
110
|
4
|
|
|
|
|
285
|
return $self->stash; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
1; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
__END__ |