ReutersConnect/Channel.pm

filter: Statementstmt 41.0% 16 / 39 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 3 / 6 Podpod 100% 2 / 2 totaltotal 41.1% 21 / 51 CC 5 SCAR 20.3
CC
5
Cov
37%
is_online_report
12.0
from_node
12.0
__ANON__
1.1
CRAP 7.6
« ReutersConnect/XMLDocument.pm ↑ Summary ReutersConnect/DB.pm »
1 package WebService::ReutersConnect::Channel;
2 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use DateTime::Format::ISO8601;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 has 'reuters' => ( is => 'ro', weak_ref => 1 , isa => 'WebService::ReutersConnect', required => 1 );
7  
8 1 has 'description' => ( is => 'ro' , isa => 'Str' , default => '' );
9 1 has 'alias' => ( is => 'ro' , isa => 'Str' );
10 1 has 'last_update' => ( is => 'ro', isa => 'DateTime' );
11 0 ▶has 'categories' => ( is => 'ro', isa => 'ArrayRef[WebService::ReutersConnect::Category]', required => 1, default => sub{ []; } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
12  
13 =head1 NAME
14  
15 WebService::ReutersConnect::Channel - A ReutersConnect Channel
16  
17 =head2 alias
18  
19 The 'Primary ID' of the channel.
20  
21 =head2 description
22  
23 A short descriptive string.
24  
25 =head2 last_update
26  
27 A L<DateTime> of .. the last channel update.
28  
29 =head2 categories
30  
31 Retuns an ArrayRef of L<WebService::ReutersConnect::Category>'s
32  
33 Usage:
34  
35 foreach my $cat ( @{$channel->categories()} ){
36 print(' Category: '.$cat->id().' - '.$cat->description());
37 }
38  
39 =head2 is_online_report
40  
41 Returns true if this Channel contains the OLR category.
42 Online report channel can be used to fetch edited NEPs (News Event Packages)
43 with the WebService::ReutersConnect::packages method.
44  
45 Usage:
46  
47 if( $this->is_online_report() ){
48 ...
49 }
50  
51 =cut
52  
53 0 ▶sub is_online_report{
Subroutine is_online_report: not called CC=3 SCAR=24.8
Pod documented
54 0 my ($self) = @_;
55 0 foreach my $cat ( @{$self->categories()} ){
56 0 ▶ if( $cat->id() eq 'OLR' ){
Branch: 1 branch
BranchTrueFalseTotal
if ($cat->id eq "OLR") 0 0 0
57 0 return $cat; ## HIT!
58 }
59 }
60 0 return; ## Fail.
61 }
62  
63 =head2 from_node
64  
65 Builds a new instance from the given WebService::ReutersConnect and XML node object.
66  
67 =cut
68  
69 0 ▶sub from_node{
Subroutine from_node: not called CC=3 SCAR=24.8
Pod documented
70 0 my ($class, $reuters , $node) = @_;
71  
72 0 my $build_params = { reuters => $reuters };
73  
74 ## Find description
75 0 my $description = $node->findvalue('./description');
76 0 $build_params->{description} = $description;
77  
78 0 my $alias = $node->findvalue('./alias');
79 0 $build_params->{alias} = $alias;
80  
81 0 my $lastupdate_string = $node->findvalue('./lastUpdate');
82 0 ▶ if( $lastupdate_string ){
Branch: 1 branch
BranchTrueFalseTotal
if ($lastupdate_string) 0 0 0
83 0 $build_params->{'last_update'} = DateTime::Format::ISO8601->parse_datetime($lastupdate_string);
84 }
85  
86 0 my @categories = ();
87 0 my @cat_nodes = $node->findnodes('./category');
88 0 foreach my $cat_node ( @cat_nodes ){
89 0 my ( $cat_id , $cat_desc ) = ( $cat_node->getAttribute('id') , $cat_node->getAttribute('description') );
90 0 push @categories , $reuters->_vivify_category({ id => $cat_id , description => $cat_desc });
91 }
92  
93 0 $build_params->{'categories'} = \@categories;
94 0 return $class->new($build_params);
95 }
96  
97 1 __PACKAGE__->meta->make_immutable();
98 1 1;
« ReutersConnect/XMLDocument.pm ↑ Summary ReutersConnect/DB.pm »