File Coverage

blib/lib/Pikeo/API/Base.pm
Criterion Covered Total %
statement 9 38 23.6
branch 0 14 0.0
condition 0 3 0.0
subroutine 3 10 30.0
pod 2 2 100.0
total 14 67 20.9


line stmt bran cond sub pod time code
1             package Pikeo::API::Base;
2              
3 4     4   29 use strict;
  4         10  
  4         143  
4 4     4   24 use Carp;
  4         9  
  4         942  
5 4     4   651 use Pikeo::API::Photos;
  3         5  
  3         2559  
6              
7             =head1 NAME
8              
9             Pikeo::API::Base - Base class for Pikeo::API modules
10              
11             =head1 DESCRIPTION
12              
13             This is a base class, you shouldn't need to use this class
14             directly. See Pikeo::API
15              
16             =cut
17              
18             our $AUTOLOAD;
19              
20             sub AUTOLOAD {
21 0     0     my $self = shift;
22 0 0         my $type = ref($self)
23             or croak "$self is not an object";
24              
25 0           my $name = $AUTOLOAD;
26 0           $name =~ s/.*://;
27              
28 0 0 0       if ( $self->_info_fields &&
  0            
29             (grep {/^${name}$/} $self->_info_fields) ){
30 0 0         $self->_init() unless $self->_init_done();
31 0           return $self->{$name};
32             }
33              
34 0           croak "Can't locate `$name' in class $type";
35             }
36              
37              
38 0     0     sub _info_fields {}
39              
40             =head2 new(\%args)
41              
42             Returns a Pikeo::API object
43              
44             =cut
45              
46             sub new {
47 0     0 1   my $class = shift;
48 0           my $params = shift;
49              
50 0 0         unless ( $params->{'api'} ) {
51 0           croak "need an api";
52             }
53              
54 0           return bless { _api => $params->{'api'} }, $class;
55             }
56              
57             =head2 api()
58              
59             Returns the current api instance
60              
61             =cut
62              
63 0     0 1   sub api { return shift->{_api} }
64              
65             sub _init {
66 0     0     my $self = shift;
67 0           $self->{_init} = 1;
68             }
69              
70             sub _init_done {
71 0     0     my $self = shift;
72 0 0         return 0 unless $self->{_init};
73 0 0         return 0 if $self->{_dirty};
74             }
75              
76             sub _photos_from_xml {
77 0     0     my $self = shift;
78 0           my $params = shift;
79              
80 0           my @photos = ();
81 0           for my $ph ( @{$params->{xml}} ) {
  0            
82 0 0         next unless my $id = $ph->find("id")->to_literal->value;
83 0           push @photos , Pikeo::API::Photo->new( {
84             id => $id,
85             api => $self->api,
86             } );
87             }
88              
89 0           return \@photos;
90             }
91              
92             1;