Tumblr/ResponseError.pm

filter: Statementstmt 42.3% 11 / 26 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 60.0% 3 / 5 Podpod 100% 2 / 2 totaltotal 23.1% 16 / 69 CC 12 SCAR 47.6
CC
12
Cov
21%
reasons
156.0
code
2.0
BEGIN
1.0
CRAP 117.3
↑ Summary Tumblr/Authentication/OAuth.pm »
1 package WWW::Tumblr::ResponseError;
2  
3 16 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 16 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 16 ▶use JSON 'decode_json';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 16 has 'response', is => 'rw', isa => 'HTTP::Response';
8  
9 0 ▶sub code { $_[0]->response->code }
Subroutine code: not called CC=1 SCAR=6.9
Pod documented
10 sub reasons {
11 0 ▶ my $self = $_[0];
Subroutine reasons: not called CC=12 SCAR=50.5
Pod documented
12 0 my $j = decode_json( $_[0]->response->decoded_content);
13 0 ▶ if ( ref $j && ref $j eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $j and ref $j eq 'HASH') { } 0 0 0
Condition0%0/3
ref $j and ref $j eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $j and ref $j eq "HASH"
ref $j ref $j eq "HASH"
Truth table0%0/3
A and B
A= ref $jB= ref $j eq "HASH"
ABresult
0X0
100
111
14 0 ▶ if ( ref $j->{response} && ref $j->{response} eq 'ARRAY' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $j->{'response'} and ref $j->{'response'} eq 'ARRAY') { } 0 0 0
elsif (ref $j->{'response'} and ref $j->{'response'} eq 'HASH' and defined $j->{'response'}{'errors'}) { } 0 0 0
Condition0%0/3
ref $j->{"response"} and ref $j->{"response"} eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $j->{"response"} and ref $j->{"response"} eq "ARRAY"
ref $j->{"response"} ref $j->{"response"} eq "ARRAY"
Truth table0%0/3
A and B
A= ref $j->{"response"}B= ref $j->{"response"} eq "ARRAY"
ABresult
0X0
100
111
15 0 ▶ unless ( scalar @{ $j->{response} }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @{$j->{"response"};}) 0 0 0
16 0 return [ $self->response->message ]
17 }
18 0 return $j->{response};
19 ▶ } elsif ( ref $j->{response} && ref $j->{response} eq 'HASH' &&
Condition0%0/6
ref $j->{"response"} and ref $j->{"response"} eq "HASH" and defined $j->{"response"}{"errors"}
!ll&&!rl&&r
000
ref $j->{"response"} and ref $j->{"response"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/3
ref $j->{"response"} and ref $j->{"response"} eq "HASH" and defined $j->{"response"}{"errors"}
ref $j->{"response"} ref $j->{"response"} eq "HASH" defined $j->{"response"}{"errors"}
Truth table0%0/4
A and B and C
A= ref $j->{"response"}B= ref $j->{"response"} eq "HASH"C= defined $j->{"response"}{"errors"}
ABCresult
0XX0
10X0
1100
1111
20 defined $j->{response}->{errors}
21 ) {
22 0 ▶ if ( ref $j->{response}->{errors} eq 'HASH' &&
Branch: 2 branches
BranchTrueFalseTotal
if (ref $j->{'response'}{'errors'} eq 'HASH' and defined $j->{'response'}{'errors'}{'state'}) { } 0 0 0
elsif (ref $j->{'response'}{'errors'} eq 'ARRAY') { } 0 0 0
Condition0%0/3
ref $j->{"response"}{"errors"} eq "HASH" and defined $j->{"response"}{"errors"}{"state"}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $j->{"response"}{"errors"} eq "HASH" and defined $j->{"response"}{"errors"}{"state"}
ref $j->{"response"}{"errors"} eq "HASH" defined $j->{"response"}{"errors"}{"state"}
Truth table0%0/3
A and B
A= ref $j->{"response"}{"errors"} eq "HASH"B= defined $j->{"response"}{"errors"}{"state"}
ABresult
0X0
100
111
23 defined $j->{response}->{errors}->{state} ) {
24 return [
25 $j->{response}->{errors}->{0},
26 $j->{response}->{errors}->{state}
27 0 ];
28 } elsif ( ref $j->{response}->{errors} eq 'ARRAY' ) {
29 0 return $j->{response}->{errors};
30 } else {
31 0 Carp::croak "Unimplemented";
32 }
33 } else {
34 0 Carp::croak "Unimplemented";
35 }
36 } else {
37 0 Carp::croak "Unimplemented";
38 }
39 }
40  
41 16 1;
42  
43 =pod
44  
45 =head1 NAME
46  
47 WWW::Tumblr::ResponseError
48  
49 =head1 SYNOPSIS
50  
51 my $posts = $tumblr->blog('stupidshit.tumblr.com')->posts;
52  
53 die "Couldn't get posts! " . Dumper( $tumblr->error->reasons ) unless $posts;
54  
55 =head1 DESCRIPTION
56  
57 This a class representing L<WWW::Tumblr>'s C<error> method. It contains the
58 response from upstream Tumblr API.
59  
60 =head1 METHODS
61  
62 =head2 error
63  
64 Callable from a model context, usually L<WWW::Tumblr>.
65  
66 print Dumper $tumblr->error unless $post;
67  
68 =head2 code
69  
70 HTTP response code for the error:
71  
72 my $info = $blog->info;
73 print $blog->error->code . ' nono :(' unless $info;
74  
75 =head2 reasons
76  
77 Commodity method to display reasons why the error ocurred. It returns an array
78 reference:
79  
80 unless ( $some_tumblr_action ) {
81 print "Errors! \n";
82 print $_, "\n" for @{ $tumblr->error->reasons || [] };
83 }
84  
85 =head1 BUGS
86  
87 Please refer to L<WWW::Tumblr>.
88  
89 =head1 AUTHOR(S)
90  
91 The same folks as L<WWW::Tumblr>.
92  
93 =head1 SEE ALSO
94  
95 L<WWW::Tumblr>, L<WWW::Tumblr::ResponseError>.
96  
97 =head1 COPYRIGHT and LICENSE
98  
99 Same as L<WWW::Tumblr>.
100  
101 =cut
102  
↑ Summary Tumblr/Authentication/OAuth.pm »