File Coverage

blib/lib/Flickr/API/Reflection.pm
Criterion Covered Total %
statement 12 62 19.3
branch 0 8 0.0
condition n/a
subroutine 4 8 50.0
pod 3 3 100.0
total 19 81 23.4


line stmt bran cond sub pod time code
1             package Flickr::API::Reflection;
2              
3 1     1   90077 use strict;
  1         2  
  1         32  
4 1     1   4 use warnings;
  1         7  
  1         49  
5 1     1   4 use Carp;
  1         1  
  1         64  
6              
7 1     1   361 use parent qw( Flickr::API );
  1         254  
  1         26  
8             our $VERSION = '1.28';
9              
10              
11             sub _initialize {
12              
13 0     0     my $self = shift;
14 0           $self->_set_status(1,'API::Reflection initialized');
15 0           return;
16              
17             }
18              
19              
20             sub methods_list {
21              
22 0     0 1   my $self = shift;
23 0           my $rsp = $self->execute_method('flickr.reflection.getMethods');
24 0           $rsp->_propagate_status($self->{flickr}->{status});
25 0           my $listref = ();
26              
27 0 0         if ($rsp->success() == 1) {
28              
29 0           $listref = $rsp->as_hash()->{methods}->{method};
30 0           $self->_set_status(1,"flickr.reflection.getMethods returned " . $#{$listref} . " methods.")
  0            
31              
32             }
33             else {
34              
35 0           $self->_set_status(0,"Flickr::API::Reflection Methods list/hash failed with response error");
36 0           carp "Flickr::API::Reflection Methods list/hash failed with error code: ",$rsp->error_code()," \n ",
37             $rsp->error_message(),"\n";
38              
39 0           my $listref = ();
40             }
41              
42 0           return $listref;
43             }
44              
45              
46              
47              
48             sub methods_hash {
49              
50 0     0 1   my $self = shift;
51 0           my $arrayref = $self->methods_list();
52 0           my $hashref;
53              
54              
55 0 0         if ($arrayref) {
56              
57 0           %{$hashref} = map {$_ => 1} @{$arrayref};
  0            
  0            
  0            
58              
59             }
60             else {
61              
62 0           $hashref = {};
63              
64             }
65 0           return $hashref;
66             }
67              
68              
69             sub get_method {
70              
71 0     0 1   my $self = shift;
72 0           my $method = shift;
73 0           my $rsp = $self->execute_method('flickr.reflection.getMethodInfo',
74             {'method_name' => $method});
75 0           my $hash = $rsp->as_hash();
76 0           my $desc = {};
77              
78 0           $rsp->_propagate_status($self->{flickr}->{status});
79              
80 0           my $err;
81             my $arg;
82              
83 0 0         if ($rsp->success() == 1) {
84              
85 0           $self->_set_status(1,"flickr.reflection.getMethodInfo returned was successful");
86              
87 0           $desc->{$method} = $hash->{method};
88              
89 0           foreach $err (@{$hash->{errors}->{error}}) {
  0            
90              
91 0           $desc->{$method}->{error}->{$err->{code}}->{message} = $err->{message};
92 0           $desc->{$method}->{error}->{$err->{code}}->{content} = $err->{content};
93              
94             }
95              
96 0 0         if ( ref($hash->{arguments}->{argument}) eq 'ARRAY') {
97              
98 0           foreach $arg (@{$hash->{arguments}->{argument}}) {
  0            
99              
100 0           $desc->{$method}->{argument}->{$arg->{name}}->{optional} = $arg->{optional};
101 0           $desc->{$method}->{argument}->{$arg->{name}}->{content} = $arg->{content};
102              
103             }
104             }
105             else {
106              
107 0           $arg = $hash->{arguments}->{argument};
108 0           $desc->{$method}->{argument}->{$arg->{name}}->{optional} = $arg->{optional};
109 0           $desc->{$method}->{argument}->{$arg->{name}}->{content} = $arg->{content};
110              
111             }
112             }
113             else {
114              
115 0           $self->_set_status(0,"Flickr::API::Reflection get_method failed with response error");
116 0           carp "Flickr::API::Reflection get method failed with error code: ",$rsp->error_code()," \n ",
117             $rsp->error_message(),"\n";
118              
119             }
120              
121 0           return $desc;
122             } # get_method
123              
124              
125              
126             1;
127              
128             __END__