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