File Coverage

blib/lib/WebService/IMDB/NewsItem.pm
Criterion Covered Total %
statement 42 43 97.6
branch 4 8 50.0
condition n/a
subroutine 8 8 100.0
pod n/a
total 54 59 91.5


line stmt bran cond sub pod time code
1             # $Id: NewsItem.pm 7370 2012-04-09 01:17:33Z chris $
2              
3             =head1 NAME
4              
5             WebService::IMDB::NewsItem
6              
7             =cut
8              
9             package WebService::IMDB::NewsItem;
10              
11 2     2   10 use strict;
  2         50  
  2         68  
12 2     2   11 use warnings;
  2         4  
  2         138  
13              
14             our $VERSION = '0.05';
15              
16 2     2   11 use base qw(Class::Accessor);
  2         4  
  2         147  
17              
18 2     2   12 use Carp;
  2         4  
  2         180  
19             our @CARP_NOT = qw(WebService::IMDB WebService::IMDB::Name WebService::IMDB::News);
20              
21 2     2   12 use DateTime::Format::Strptime;
  2         50  
  2         82  
22              
23 2     2   13 use WebService::IMDB::Name::Stub;
  2         3  
  2         50  
24 2     2   1296 use WebService::IMDB::Title::Stub;
  2         6  
  2         18  
25              
26             __PACKAGE__->mk_accessors(qw(
27             id
28             body
29             datetime
30             head
31             icon
32             link
33             names
34             source
35             titles
36             ));
37              
38              
39             =head1 METHODS
40              
41             =head2 id
42              
43             =head2 body
44              
45             =head2 datetime
46              
47             =head2 head
48              
49             =head2 icon
50              
51             =head2 link
52              
53             =head2 names
54              
55             =head2 sources
56              
57             =head2 titles
58              
59             =cut
60              
61             sub _new {
62 40     40   469 my $class = shift;
63 40         68 my $ws = shift;
64 40 50       111 my $data = shift or die;
65 40 50       111 my $sources = shift or die;
66              
67 40         63 my $self = {};
68              
69 40         134 bless $self, $class;
70              
71 40         175 $self->id($data->{'id'});
72 40         512 $self->body($data->{'body'});
73 40         612 $self->datetime(DateTime::Format::Strptime->new('pattern' => "%Y-%m-%dT%H:%M:%SZ", 'on_error' => "croak")->parse_datetime($data->{'datetime'})); # TODO: Handle timezone other than Z (i.e. UTC)
74 40         50902 $self->head($data->{'head'});
75 40 50       462 if (exists $data->{'icon'}) { $self->icon($data->{'icon'}); }
  0         0  
76 40 50       129 if (exists $data->{'link'}) { $self->link($data->{'link'}); }
  40         190  
77 40         596 $self->names( [ map { WebService::IMDB::Name::Stub->_new($ws, $_) } @{$data->{'names'}} ] );
  419         1295  
  40         114  
78 40         512 $self->source($sources->{$data->{'source'}});
79 40         413 $self->titles( [ map { WebService::IMDB::Title::Stub->_new($ws, $_) } @{$data->{'titles'}} ] );
  285         937  
  40         126  
80              
81 40         592 return $self;
82             }
83              
84             1;