Graph/Response.pm

filter: Statementstmt 50.0% 15 / 30 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 42.8% 3 / 7 Podpod n/a totaltotal 41.8% 18 / 43 CC 4 SCAR 17.0
CC
4
Cov
42%
__ANON__
12.0
__ANON__
6.0
__ANON__
2.0
CRAP 5.5
« Graph.pm ↑ Summary Graph/Publish/Comment.pm »
1 package Facebook::Graph::Response;
2 4 $Facebook::Graph::Response::VERSION = '1.1205';
3 4 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use Ouch;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 has response => (
8 is => 'rw',
9 0 ▶ isa => sub {ouch(442,"$_[0] is not an HTTP::Response object") unless ref $_[0] eq 'HTTP::Response'},
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] eq "HTTP::Response" 0 0 0
10 4 required=> 1,
11 );
12  
13 has as_string => (
14 is => 'ro',
15 lazy => 1,
16 0 ▶ default => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
17 0 my $self = shift;
18 0 return $self->response->content;
19 },
20 4 );
21  
22 has as_json => (
23 is => 'ro',
24 lazy => 1,
25 0 ▶ default => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
26 0 my $self = shift;
27 0 my $response = $self->response;
28 0 ▶ if ($response->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->is_success) { } 0 0 0
29 0 return $response->content;
30 }
31 else {
32 0 my $message = $response->message;
33 0 my $error = eval { JSON->new->decode($response->content) };
34 0 ▶ unless ($@) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($@) 0 0 0
35 0 $message = $error->{error}{type} . ' - ' . $error->{error}{message};
36 }
37 0 ouch $response->code, 'Could not execute request ('.$response->request->uri->as_string.'): '.$message, $response->request->uri->as_string;
38 }
39 },
40 4 );
41  
42 has as_hashref => (
43 is => 'ro',
44 lazy => 1,
45 0 ▶ default => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
46 0 my $self = shift;
47 0 return JSON->new->decode($self->as_json);
48 },
49 4 );
50  
51 4 1;
52  
53 =head1 NAME
54  
55 Facebook::Graph::Response - Handling of a Facebook::Graph response documents.
56  
57 =head1 VERSION
58  
59 version 1.1205
60  
61 =head1 DESCRIPTION
62  
63 You'll be given one of these as a result of calling the C<request> method on a L<Facebook::Graph::Query> or others, or C<publish> on any of the L<Facebook::Graph::Publish> modules.
64  
65 =head1 METHODS
66  
67 Returns the response as a string. Does not throw an exception of any kind.
68  
69 =head2 as_json ()
70  
71 Returns the response from Facebook as a JSON string.
72  
73 =head2 as_hashref ()
74  
75 Returns the response from Facebook as a hash reference.
76  
77 =head2 as_string ()
78  
79 No processing what so ever. Just returns the raw body string that was received from Facebook.
80  
81 =head2 response ()
82  
83 Direct access to the L<HTTP::Response> object.
84  
85 =head1 LEGAL
86  
87 Facebook::Graph is Copyright 2010 - 2017 Plain Black Corporation (L<http://www.plainblack.com>) and is licensed under the same terms as Perl itself.
88  
89 =cut
« Graph.pm ↑ Summary Graph/Publish/Comment.pm »