line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Flickr::Tools::Cameras; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
146743
|
use Flickr::API::Cameras; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
use Types::Standard qw ( InstanceOf ); |
5
|
|
|
|
|
|
|
use Carp; |
6
|
|
|
|
|
|
|
use Moo; |
7
|
|
|
|
|
|
|
use strictures; |
8
|
|
|
|
|
|
|
use namespace::clean; |
9
|
|
|
|
|
|
|
use 5.010; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
with qw(Flickr::Roles::Caching); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '1.22'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
extends 'Flickr::Tools'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has '+_api_name' => ( |
18
|
|
|
|
|
|
|
is => 'ro', |
19
|
|
|
|
|
|
|
isa => sub { $_[0] eq 'Flickr::API::Cameras' }, |
20
|
|
|
|
|
|
|
required => 1, |
21
|
|
|
|
|
|
|
default => 'Flickr::API::Cameras', |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub getBrands { |
25
|
|
|
|
|
|
|
my ( $self, $args ) = @_; |
26
|
|
|
|
|
|
|
my $brands; |
27
|
|
|
|
|
|
|
my $pre_expire = 0; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
$self->_set_cache_hit(1); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
if ( defined( $args->{clear_cache} ) and $args->{clear_cache} ) { |
32
|
|
|
|
|
|
|
$pre_expire = 1; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
if ( defined( $args->{list_type} ) and $args->{list_type} =~ m/list/i ) { |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
$self->_set_cache_key('brands_list'); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
$brands = $self->_cache->get( $self->cache_key, |
40
|
|
|
|
|
|
|
expire_if => sub { $pre_expire } ); |
41
|
|
|
|
|
|
|
if ( !defined $brands ) { |
42
|
|
|
|
|
|
|
$brands = $self->{_api}->brands_list; |
43
|
|
|
|
|
|
|
$self->_set_cache_hit(0); |
44
|
|
|
|
|
|
|
$self->_cache->set( $self->cache_key, $brands, |
45
|
|
|
|
|
|
|
$self->cache_duration ); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
else { |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
$self->_set_cache_key('brands_hash'); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
$brands = $self->_cache->get( $self->cache_key, |
53
|
|
|
|
|
|
|
expire_if => sub { $pre_expire } ); |
54
|
|
|
|
|
|
|
if ( !defined $brands ) { |
55
|
|
|
|
|
|
|
$brands = $self->{_api}->brands_hash; |
56
|
|
|
|
|
|
|
$self->_set_cache_hit(0); |
57
|
|
|
|
|
|
|
$self->_cache->set( $self->cache_key, $brands, |
58
|
|
|
|
|
|
|
$self->cache_duration ); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
return $brands; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub getBrandModels { |
65
|
|
|
|
|
|
|
my ( $self, $args ) = @_; |
66
|
|
|
|
|
|
|
my $models = {}; |
67
|
|
|
|
|
|
|
my $pre_expire = 0; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
$self->_set_cache_hit(1); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
if ( defined( $args->{clear_cache} ) and $args->{clear_cache} ) { |
72
|
|
|
|
|
|
|
$pre_expire = 1; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
if ( exists( $args->{Brand} ) ) { |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
$self->_set_cache_key( 'Models ' . $args->{Brand} ); |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
$models = $self->_cache->get( $self->cache_key, |
80
|
|
|
|
|
|
|
expire_if => sub { $pre_expire } ); |
81
|
|
|
|
|
|
|
if ( !defined $models ) { |
82
|
|
|
|
|
|
|
$models = $self->{_api}->get_cameras( $args->{Brand} ); |
83
|
|
|
|
|
|
|
$self->_set_cache_hit(0); |
84
|
|
|
|
|
|
|
$self->_cache->set( $self->cache_key, $models, |
85
|
|
|
|
|
|
|
$self->cache_duration ); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
else { |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
carp |
91
|
|
|
|
|
|
|
"\nCannot return models unless a required argument: Brand is passed in\n"; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
return $models; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
1; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
__END__ |