| 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
Condition0%0/3
ref $j and ref $j eq "HASH"
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"
| |||||||||||||||||||||||||||||||||||
| 14 | 0 | ▶ | if ( ref $j->{response} && ref $j->{response} eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
ref $j->{"response"} and ref $j->{"response"} eq "ARRAY"
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"
| |||||||||||||||||||||||||||||||||||
| 15 | 0 | ▶ | unless ( scalar @{ $j->{response} }) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 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"}
ref $j->{"response"} and ref $j->{"response"} eq "HASH"
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"}
| |||||||||||||||||||||||||||||||||||
| 20 | defined $j->{response}->{errors} | ||||||||||||||||||||||||||||||||||
| 21 | ) { | ||||||||||||||||||||||||||||||||||
| 22 | 0 | ▶ | if ( ref $j->{response}->{errors} eq 'HASH' && | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
ref $j->{"response"}{"errors"} eq "HASH" and defined $j->{"response"}{"errors"}{"state"}
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"}
| |||||||||||||||||||||||||||||||||||
| 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 | |||||||||||||||||||||||||||||||||||