File Coverage

blib/lib/Flickr/API/Cameras.pm
Criterion Covered Total %
statement 12 59 20.3
branch 0 6 0.0
condition n/a
subroutine 4 8 50.0
pod 3 3 100.0
total 19 76 25.0


line stmt bran cond sub pod time code
1             package Flickr::API::Cameras;
2              
3 1     1   132280 use strict;
  1         1  
  1         40  
4 1     1   10 use warnings;
  1         2  
  1         56  
5 1     1   5 use Carp;
  1         3  
  1         90  
6              
7 1     1   493 use parent qw( Flickr::API );
  1         337  
  1         7  
8             our $VERSION = '1.28';
9              
10             sub _initialize {
11              
12 0     0     my $self = shift;
13 0           $self->_set_status(1,'API::Cameras initialized');
14 0           return;
15              
16             }
17              
18             sub brands_list {
19              
20 0     0 1   my $self = shift;
21 0           my $rsp = $self->execute_method('flickr.cameras.getBrands');
22 0           my $listref = ();
23              
24 0           $rsp->_propagate_status($self->{flickr}->{status});
25              
26 0 0         if ($rsp->success() == 1) {
27              
28 0           foreach my $cam (@{$rsp->as_hash()->{brands}->{brand}}) {
  0            
29              
30 0           push (@{$listref},$cam->{name});
  0            
31              
32             }
33              
34 0           $self->_set_status(1,"flickr.camera.getBrands returned " . $#{$listref} . " brands.");
  0            
35              
36             }
37             else {
38              
39              
40 0           $self->_set_status(0,"Flickr::API::Cameras Methods list/hash failed with response error");
41              
42 0           carp "Flickr::API::Cameras Methods list/hash failed with response error: ",$rsp->error_code()," \n ",
43             $rsp->error_message(),"\n";
44              
45             }
46 0           return $listref;
47             }
48              
49              
50              
51              
52             sub brands_hash {
53              
54 0     0 1   my $self = shift;
55 0           my $arrayref = $self->brands_list();
56 0           my $hashref;
57              
58              
59 0 0         if ($arrayref) {
60              
61 0           %{$hashref} = map {$_ => 1} @{$arrayref};
  0            
  0            
  0            
62              
63             }
64             else {
65              
66 0           $hashref = {};
67              
68             }
69 0           return $hashref;
70             }
71              
72             sub get_cameras {
73              
74 0     0 1   my $self = shift;
75 0           my $brand = shift;
76 0           my $rsp = $self->execute_method('flickr.cameras.getBrandModels',
77             {'brand' => $brand});
78 0           my $hash = $rsp->as_hash();
79 0           my $AoH = {};
80 0           my $desc = {};
81              
82 0           my $cam;
83              
84 0           $rsp->_propagate_status($self->{flickr}->{status});
85              
86 0 0         if ($rsp->success() == 1) {
87              
88 0           $AoH = $hash->{cameras}->{camera};
89              
90 0           foreach $cam (@{$AoH}) {
  0            
91              
92 0           $desc->{$brand}->{$cam->{id}}->{name} = $cam->{name};
93 0           $desc->{$brand}->{$cam->{id}}->{details} = $cam->{details};
94 0           $desc->{$brand}->{$cam->{id}}->{images} = $cam->{images};
95              
96             }
97              
98 0           $self->_set_status(1,"flickr.camera.getBrandModels returned " . $#{$AoH} . " models.");
  0            
99              
100             }
101             else {
102              
103              
104 0           $self->_set_status(0,"Flickr::API::Cameras get_cameras failed with response error");
105              
106 0           carp "Flickr::API::Cameras get_cameras method failed with error code: ",$rsp->error_code()," \n ",
107             $rsp->error_message(),"\n";
108              
109              
110             }
111              
112 0           return $desc;
113             }
114              
115              
116             1;
117              
118             __END__