File Coverage

blib/lib/WWW/Google/Cloud/Messaging/Response.pm
Criterion Covered Total %
statement 45 46 97.8
branch 2 2 100.0
condition 1 2 50.0
subroutine 15 16 93.7
pod 3 4 75.0
total 66 70 94.2


line stmt bran cond sub pod time code
1             package WWW::Google::Cloud::Messaging::Response;
2              
3 3     3   14 use strict;
  3         6  
  3         124  
4 3     3   15 use warnings;
  3         5  
  3         92  
5 3     3   14 use JSON qw(decode_json);
  3         5  
  3         20  
6              
7 3     3   2094 use WWW::Google::Cloud::Messaging::Response::ResultSet;
  3         8  
  3         550  
8              
9             sub new {
10 5     5 1 17 my ($class, $http_response) = @_;
11              
12 5         62 my $is_success = $http_response->is_success;
13 5         304 my $content = $http_response->content;
14 5         206 my $reg_ids = [];
15              
16 5 100       32 if ($is_success) {
17 4         263 $content = decode_json $content;
18 4         18 $reg_ids = decode_json($http_response->request->content)->{registration_ids};
19             }
20             else {
21 1         22 $content = { error => $content };
22             }
23              
24 5         745 bless {
25             is_success => $is_success,
26             content => $content,
27             reg_ids => $reg_ids,
28             http_response => $http_response,
29             }, $class;
30             }
31              
32             sub http_response {
33 15     15 0 299 shift->{http_response};
34             }
35              
36             sub is_success {
37 5     5 1 66 shift->{is_success};
38             }
39              
40             for my $method (qw{success failure multicast_id canonical_ids error}) {
41 3     3   17 no strict 'refs';
  3         5  
  3         116  
42             *{$method} = sub {
43 3     3   14 use strict;
  3         6  
  3         507  
44 25     25   26131 shift->{content}{$method};
45             };
46             }
47              
48             sub results {
49 4     4 1 11535 my $self = shift;
50 4   50     30 my $results = $self->{content}{results} || return;
51 4         83 WWW::Google::Cloud::Messaging::Response::ResultSet->new($results, $self->{reg_ids});
52             }
53              
54 0     0   0 sub DESTROY {}
55             sub AUTOLOAD {
56 1     1   141 (my $method = our $AUTOLOAD) =~ s/.*:://;
57 3     3   15 no strict 'refs';
  3         4  
  3         124  
58 1         15 *{$AUTOLOAD} = sub {
59 3     3   18 use strict;
  3         6  
  3         318  
60 5     5   15 my $self = shift;
61 5         102 $self->{http_response}->$method(@_);
62 1         8 };
63 1         9 goto &$AUTOLOAD;
64             }
65              
66             1;
67             __END__