NewsML_G2/News_Item.pm

filter: Statementstmt 98.7% 77 / 78 Branchbran 80.0% 8 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 22 / 22 Podpod 100% 3 / 3 totaltotal 97.3% 110 / 113 CC 6 SCAR 4.2
CC
6
Cov
97%
add_paragraph
3.0
add_location
3.0
add_remote
2.0
CRAP 1.5
« NewsML_G2/Substancial_Item.pm ↑ Summary NewsML_G2/Concept.pm »
1 package XML::NewsML_G2::News_Item;
2  
3 27 ▶use XML::LibXML qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 27 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 27 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 27 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 # document properties
10 27 extends 'XML::NewsML_G2::Substancial_Item';
11  
12 27 has 'caption', isa => 'Str', is => 'rw';
13 27 has 'teaser', isa => 'Str', is => 'rw';
14 27 has 'byline', isa => 'Str', is => 'rw';
15 27 has 'dateline', isa => 'Str', is => 'rw';
16 27 has 'paragraphs', isa => 'XML::LibXML::Node', is => 'rw';
17 27 has 'content_created',
18 isa => 'DateTime',
19 is => 'ro',
20 lazy => 1,
21 builder => '_build_content_created';
22 27 has 'content_modified', isa => 'DateTime', is => 'ro';
23  
24 27 has 'credit', isa => 'Str', is => 'rw';
25 27 has 'priority', isa => 'Int', is => 'ro', default => 5;
26 27 has 'message_id', isa => 'Str', is => 'ro';
27 27 has 'slugline', isa => 'Str', is => 'rw';
28 27 has 'slugline_sep', isa => 'Str', is => 'rw', default => '/';
29 27 has 'electiondistrict', isa => 'XML::NewsML_G2::ElectionDistrict', is => 'rw';
30  
31 has 'event_references',
32 isa => 'ArrayRef[XML::NewsML_G2::Event_Ref]',
33 is => 'rw',
34 33 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
35 27 traits => ['Array'],
36 handles =>
37 { add_event_reference => 'push', has_event_references => 'count' };
38 has 'sources',
39 isa => 'ArrayRef[Str]',
40 is => 'rw',
41 33 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
42 27 traits => ['Array'],
43 handles => { add_source => 'push' };
44 has 'authors',
45 isa => 'XML::NewsML_G2::ArrayRefOfCreators',
46 is => 'rw',
47 coerce => 1,
48 33 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
49 27 traits => ['Array'],
50 handles => { add_author => 'push' };
51 has 'cities',
52 isa => 'ArrayRef[Str]',
53 is => 'rw',
54 33 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
55 27 traits => ['Array'],
56 handles => { add_city => 'push' };
57  
58 has 'genres',
59 isa => 'ArrayRef[XML::NewsML_G2::Genre]',
60 is => 'rw',
61 33 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
62 27 traits => ['Array'],
63 handles => { add_genre => 'push' };
64 has 'storytypes',
65 isa => 'ArrayRef[XML::NewsML_G2::StoryType]',
66 is => 'rw',
67 33 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
68 27 traits => ['Array'],
69 handles => { add_storytype => 'push' };
70 has 'organisations',
71 isa => 'ArrayRef[XML::NewsML_G2::Organisation]',
72 is => 'rw',
73 33 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
74 27 traits => ['Array'],
75 handles => { add_organisation => 'push', has_organisations => 'count' };
76 has 'topics',
77 isa => 'ArrayRef[XML::NewsML_G2::Topic]',
78 is => 'rw',
79 33 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
80 27 traits => ['Array'],
81 handles => { add_topic => 'push', has_topics => 'count' };
82 has 'products',
83 isa => 'ArrayRef[XML::NewsML_G2::Product]',
84 is => 'rw',
85 33 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
86 27 traits => ['Array'],
87 handles => { add_product => 'push', has_products => 'count' };
88 has 'desks',
89 isa => 'ArrayRef[XML::NewsML_G2::Desk]',
90 is => 'rw',
91 33 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
92 27 traits => ['Array'],
93 handles => { add_desk => 'push', has_desks => 'count' };
94 has 'locations',
95 isa => 'HashRef[XML::NewsML_G2::Location]',
96 is => 'rw',
97 33 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
98 27 traits => ['Hash'],
99 handles => { has_locations => 'count' };
100 has 'keywords',
101 isa => 'ArrayRef[Str]',
102 is => 'rw',
103 33 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
104 27 traits => ['Array'],
105 handles => { add_keyword => 'push', has_keywords => 'count' };
106 has 'remotes',
107 isa => 'HashRef',
108 is => 'rw',
109 33 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
110 27 traits => ['Hash'],
111 handles => { has_remotes => 'count' };
112 has 'inlinedata',
113 isa => 'ArrayRef[XML::NewsML_G2::Inline_Data]',
114 is => 'rw',
115 33 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
116 27 traits => ['Array'],
117 handles => { add_inlinedata => 'push', has_inlinedata => 'count' };
118  
119 5 ▶sub _build_content_created {
Subroutine _build_content_created: called CC=1 SCAR=0.0
120 5 my ($self) = @_;
121 5 return DateTime->now( time_zone => $self->timezone );
122 }
123  
124 # public methods
125  
126 100 ▶sub add_location {
Subroutine add_location: called CC=3 SCAR=11.0
Pod documented
127 100 my ( $self, $l ) = @_;
128 100 ▶ return if exists $self->locations->{ $l->qcode };
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->locations->{$l->qcode} 25 75 100
129 75 $self->locations->{ $l->qcode } = $l;
130 75 ▶ $self->add_location( $l->parent ) if $l->parent;
Branch: 1 branch
BranchTrueFalseTotal
if $l->parent 50 25 75
131 75 return 1;
132 }
133  
134 7 ▶sub add_paragraph {
Subroutine add_paragraph: called CC=3 SCAR=11.1
Pod documented
135 7 my ( $self, $text_or_xml ) = @_;
136 7 my $paras = $self->paragraphs;
137 7 ▶ unless ($paras) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($paras) 6 1 7
138 6 $self->paragraphs( $paras =
139 XML::LibXML->createDocument()->createElement('paragraphs') );
140 }
141 7 ▶ if ( ref $text_or_xml ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $text_or_xml) { } 0 7 7
142 0 $paras->appendChild($text_or_xml);
143 }
144 else {
145 7 my $doc = $paras->getOwnerDocument;
146 7 my $p = $doc->createElementNS( 'http://www.w3.org/1999/xhtml', 'p' );
147 7 $p->appendChild( $doc->createTextNode($text_or_xml) );
148 7 $paras->appendChild($p);
149 }
150 7 return 1;
151 }
152  
153 9 ▶sub add_remote {
Subroutine add_remote: called CC=2 SCAR=7.0
Pod documented
154 9 my ( $self, $uri, $remote ) = @_;
155 9 ▶ return if exists $self->remotes->{$uri};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->remotes->{$uri} 0 9 9
156 9 $self->remotes->{$uri} = $remote;
157  
158 9 return 1;
159 }
160  
161 27 __PACKAGE__->meta->make_immutable;
162  
163 27 1;
164 __END__
« NewsML_G2/Substancial_Item.pm ↑ Summary NewsML_G2/Concept.pm »