HTTPDeferred/Deferred.pm

filter: Statementstmt 37.1% 13 / 35 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 27.2% 3 / 11 Podpod 100% 7 / 7 totaltotal 40.3% 23 / 57 CC 5 SCAR 17.6
CC
5
Cov
33%
callback
12.0
errback
12.0
__ANON__
2.0
CRAP 5.8
↑ Summary HTTPDeferred.pm »
1 package POE::Component::Client::HTTPDeferred::Deferred;
2 2 ▶use Any::Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 2 ▶use POE;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 has request => (
7 is => 'rw',
8 isa => 'HTTP::Request',
9 weak_ref => 1,
10 required => 1,
11 );
12  
13 2 has client_alias => (
14 is => 'rw',
15 isa => 'Str',
16 required => 1,
17 );
18  
19 has callbacks => (
20 is => 'rw',
21 isa => 'ArrayRef',
22 lazy => 1,
23 0 ▶ default => sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
24 2 );
25  
26 2 ▶no Any::Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 =head1 NAME
29  
30 POE::Component::Client::HTTPDeferred::Deferred - Deferred class for POE::Component::Client::HTTPDeferred.
31  
32 =head1 SEE ALSO
33  
34 L<POE::Component::Client::HTTPDeferred>.
35  
36 =head1 METHOD
37  
38 =head2 new
39  
40 my $d = POE::Component::Client::HTTPDeferred::Deferred->new;
41  
42 Create deferred object.
43  
44 =head2 cancel
45  
46 $d->cancel;
47  
48 Cancel HTTP Request.
49  
50 =cut
51  
52 0 ▶sub cancel {
Subroutine cancel: not called CC=1 SCAR=6.9
Pod documented
53 0 my $self = shift;
54 0 $poe_kernel->post( $self->client_alias => cancel => $self->request );
55  
56 0 $self;
57 }
58  
59 =head2 callback
60  
61 $d->callback($response);
62  
63 An normal response callback method. This is called when http request is successful.
64  
65 =cut
66  
67 0 ▶sub callback {
Subroutine callback: not called CC=3 SCAR=24.8
Pod documented
68 0 my ($self, $res) = @_;
69  
70 0 for my $cb (@{ $self->callbacks }) {
71 0 ▶ $cb->[0]->($res) if $cb->[0];
Branch: 1 branch
BranchTrueFalseTotal
if $cb->[0] 0 0 0
72 }
73 }
74  
75 =head2 errback
76  
77 $d->errback($response);
78  
79 An error response callback. This is called when http request is failed.
80  
81 =cut
82  
83 0 ▶sub errback {
Subroutine errback: not called CC=3 SCAR=24.8
Pod documented
84 0 my ($self, $res) = @_;
85  
86 0 for my $cb (@{ $self->callbacks }) {
87 0 ▶ $cb->[1]->($res) if $cb->[1];
Branch: 1 branch
BranchTrueFalseTotal
if $cb->[1] 0 0 0
88 }
89 }
90  
91 =head2 addBoth
92  
93 $d->addBoth($callback);
94  
95 Add $callback to both callback and errback.
96  
97 This is same as following:
98  
99 $d->addCallbacks($callback, $callback);
100  
101 =cut
102  
103 0 ▶sub addBoth {
Subroutine addBoth: not called CC=1 SCAR=6.9
Pod documented
104 0 my ($self, $cb) = @_;
105 0 $self->addCallbacks($cb, $cb);
106 }
107  
108 =head2 addCallback
109  
110 $d->addCallback($callback);
111  
112 Add $callback to normal callback.
113  
114 =cut
115  
116 0 ▶sub addCallback {
Subroutine addCallback: not called CC=1 SCAR=6.9
Pod documented
117 0 my ($self, $cb) = @_;
118 0 $self->addCallbacks($cb, undef);
119 }
120  
121 =head2 addCallbacks
122  
123 $d->addCallbacks( $callback, $errback );
124  
125 Add $callback to normal callback, and $errback to error callback.
126  
127 =cut
128  
129 0 ▶sub addCallbacks {
Subroutine addCallbacks: not called CC=1 SCAR=6.9
Pod documented
130 0 my ($self, $cb, $eb) = @_;
131 0 push @{ $self->callbacks }, [ $cb, $eb ];
132  
133 0 $self;
134 }
135  
136 =head2 addErrback
137  
138 $d->addErrback( $errback );
139  
140 Add $errback to error callback.
141  
142 =cut
143  
144 0 ▶sub addErrback {
Subroutine addErrback: not called CC=1 SCAR=6.9
Pod documented
145 0 my ($self, $eb) = @_;
146 0 $self->addCallbacks(undef, $eb);
147 }
148  
149 =head1 AUTHOR
150  
151 Daisuke Murase <typester@cpan.org>
152  
153 =head1 COPYRIGHT
154  
155 This program is free software; you can redistribute
156 it and/or modify it under the same terms as Perl itself.
157  
158 The full text of the license can be found in the
159 LICENSE file included with this module.
160  
161 =cut
162  
163 2 __PACKAGE__->meta->make_immutable;
↑ Summary HTTPDeferred.pm »