File Coverage

blib/lib/Flickr/API/Reflection.pm
Criterion Covered Total %
statement 12 12 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 16 16 100.0


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