File Coverage

blib/lib/WebService/IMDB/Base.pm
Criterion Covered Total %
statement 47 56 83.9
branch 9 14 64.2
condition n/a
subroutine 11 14 78.5
pod 0 1 0.0
total 67 85 78.8


line stmt bran cond sub pod time code
1             # $Id: Base.pm 7370 2012-04-09 01:17:33Z chris $
2              
3             package WebService::IMDB::Base;
4              
5 2     2   12 use strict;
  2         4  
  2         149  
6 2     2   10 use warnings;
  2         4  
  2         85  
7              
8             our $VERSION = '0.05';
9              
10 2     2   10 use base qw(Class::Accessor);
  2         4  
  2         191  
11              
12 2     2   18 use Cache::FileCache;
  2         3  
  2         92  
13              
14 2     2   10 use Carp;
  2         3  
  2         166  
15             our @CARP_NOT = qw(WebService::IMDB WebService::IMDB::Title WebService::IMDB::Name);
16              
17 2     2   18 use HTTP::Request::Common;
  2         10  
  2         6823  
18              
19             __PACKAGE__->mk_accessors(qw(
20             _ws
21             _q
22              
23             __id
24              
25             __content
26             ));
27              
28              
29             sub _new {
30 891     891   1536 my $class = shift;
31 891         1019 my $ws = shift;
32 891 50       3198 my $q = shift or die;
33 891         1975 my %opts = @_;
34              
35 891         1433 my $self = {};
36              
37 891         2513 bless $self, $class;
38              
39 891         2494 $self->_ws($ws);
40              
41 891         9985 $self->_q($q);
42              
43 891 100       8597 if (!$opts{'_defer_fetch'}) {
44 13         59 $self->_id();
45             }
46              
47 891         2769 return $self;
48              
49             }
50              
51             ################################
52             #
53             # Primary properties
54             #
55             ################################
56              
57             sub type {
58 0     0 0 0 my $self = shift;
59 0 0       0 if ($self->isa("WebService::IMDB::Title")) {
    0          
60 0         0 return "Title";
61             } elsif ($self->isa("WebService::IMDB::Name")) {
62 0         0 return "Name";
63             } else {
64 0         0 die "Unknown type";
65             }
66             }
67              
68              
69             sub _domain {
70 44     44   95 my $self = shift;
71 44         157 return $self->_ws()->_domain();
72             }
73              
74             sub _url {
75 0     0   0 die "Not implemented";
76             }
77              
78             sub _request {
79 30     30   338 my $self = shift;
80 30         60 my $page = shift;
81 30         156 return GET $self->_url($page);
82             }
83              
84              
85             ################################
86             #
87             # Caching accessors
88             #
89             ################################
90              
91             sub _flush {
92 0     0   0 my $self = shift;
93              
94 0         0 $self->__id(undef);
95 0         0 $self->__content(undef);
96             }
97              
98             sub _id {
99 43     43   89 my $self = shift;
100              
101 43 100       176 if (!defined $self->__id) {
102 14         226 $self->__id($self->_get_id());
103             }
104 43         575 return $self->__id();
105             }
106              
107             sub _content {
108 105     105   293 my $self = shift;
109 105         180 my $page = shift;
110              
111 105 100       359 if (!defined $self->__content()) { $self->__content({}); }
  14         183  
112              
113 105         1346 my $content = $self->__content()->{$page};
114              
115 105 100       1004 if (! defined $content) {
116              
117 30         104 $content = $self->_ws()->_response_decoded_json($self->_request($page));
118              
119 30         262 $self->__content()->{$page} = $content;
120             }
121              
122 105         1224 return $content;
123              
124             }
125              
126              
127             ################################
128             #
129             # Parsing methods
130             #
131             ################################
132              
133              
134              
135             1;