blib/lib/XML/NewsML_G2/Scheme_Manager.pm

filter: Statementstmt 87.5% 35 / 40 Branchbran 64.2% 9 / 14 Conditioncond 66.6% 4 / 6 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 88.8% 8 / 9 Podpod 100% 5 / 5 totaltotal 80.5% 62 / 77 CC 10 SCAR 13.1
CC
10
Cov
80%
build_qcode
6.4
add_role
6.0
add_qcode
2.0
CRAP 3.7
« Build ↑ Summary blib/lib/XML/NewsML_G2/Scheme.pm »
1 package XML::NewsML_G2::Scheme_Manager;
2  
3 23 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 23 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 23 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 23 my @attrs = (
8 qw(desk hltype role ind geo org topic crel crol drol svc
9 isbn ean isrol nprov ninat stat sig iso3166_1a2 genre isin medtop
10 rnd vidrnd colsp adc group pgrmod copyright_holder electiondistrict
11 electionprovince facet sportfacet sportfacetvalue storytype gyibt)
12 );
13  
14 23 foreach (@attrs) {
15 828 has $_, isa => 'XML::NewsML_G2::Scheme', is => 'rw';
16 }
17  
18 # public methods
19  
20 sub get_all_schemes {
21 13 ▶ my $self = shift;
Subroutine get_all_schemes: called CC=1 SCAR=0.0
Pod documented
22  
23 468 return grep {defined}
24 13 map { $self->$_() } sort $self->meta->get_attribute_list();
25 }
26  
27 sub build_qcode {
28 36 ▶ my ( $self, $name, $value ) = @_;
Subroutine build_qcode: called CC=6 SCAR=18.6
Pod documented
29 36 ▶ return unless $value;
Branch: 1 branch
BranchTrueFalseTotal
unless $value 0 36 36
30  
31 36 ▶ my $getter = $self->can($name)
Branch: 1 branch
BranchTrueFalseTotal
my $getter = $self->can($name) or croak("No schema named '${name}' for value $value!") 0 36 36
32 or croak "No schema named '$name' for value $value!";
33 36 my $scheme = $getter->($self);
34 36 ▶ return unless ( $scheme and ( $scheme->uri or $scheme->catalog ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $scheme and $scheme->uri || $scheme->catalog 8 28 36
Condition66%4/6
$scheme and $scheme->uri || $scheme->catalog
!ll&&!rl&&r
8028
$scheme->uri or $scheme->catalog
l!l&&r!l&&!r
2260
MC/DC33%1/3
$scheme and $scheme->uri || $scheme->catalog
$scheme $scheme->uri $scheme->catalog
Truth table50%2/4
A and B or C
A= $schemeB= $scheme->uriC= $scheme->catalog
ABCresult
0XX0
1000
11X1
1011
35  
36 28 return $scheme->alias . ':' . $value;
37 }
38  
39 sub add_qcode_or_literal {
40 22 ▶ my ( $self, $elem, $name, $value ) = @_;
Subroutine add_qcode_or_literal: called CC=2 SCAR=6.9
Pod documented
41 22 ▶ $self->_add_qcode( $elem, $name, $value )
Branch: 1 branch
BranchTrueFalseTotal
$self->_add_qcode($elem, $name, $value) or $elem->setAttribute("literal", $name . '#' . $value) 8 14 22
42 or $elem->setAttribute( 'literal', $name . '#' . $value );
43 22 return 1;
44 }
45  
46 sub add_qcode {
47 13 ▶ my ( $self, $elem, $name, $value ) = @_;
Subroutine add_qcode: called CC=2 SCAR=7.1
Pod documented
48 13 ▶ $self->_add_qcode( $elem, $name, $value )
Branch: 1 branch
BranchTrueFalseTotal
$self->_add_qcode($elem, $name, $value) or die "Specifying a '${name}' schema with uri or catalog required\n" 0 13 13
49 or die "Specifying a '$name' schema with uri or catalog required\n";
50 13 return 1;
51 }
52  
53 sub add_role {
54 0 ▶ my ( $self, $elem, $name, $value ) = @_;
Subroutine add_role: not called CC=2 SCAR=17.9
Pod documented
55  
56 0 my $role = $self->build_qcode( $name, $value );
57 0 ▶ return unless $role;
Branch: 1 branch
BranchTrueFalseTotal
unless $role 0 0 0
58  
59 0 $elem->setAttribute( 'role', $role );
60 0 return 1;
61 }
62  
63 # private methods
64  
65 sub _add_qcode {
66 35 ▶ my ( $self, $elem, $name, $value ) = @_;
Subroutine _add_qcode: called CC=2 SCAR=6.9
67  
68 35 my $qcode = $self->build_qcode( $name, $value );
69 35 ▶ return unless $qcode;
Branch: 1 branch
BranchTrueFalseTotal
unless $qcode 8 27 35
70  
71 27 $elem->setAttribute( 'qcode', $qcode );
72 27 return 1;
73 }
74  
75 23 __PACKAGE__->meta->make_immutable;
76  
77 23 1;
78  
79 __END__
80  
81 =head1 NAME
82  
83 XML::NewsML_G2::Scheme_Manager - hold all L<XML::NewsML_G2::Scheme> instances
84  
85  
86 =for test_synopsis
87 my ($s1, $s2, $s3);
88  
89 =head1 SYNOPSIS
90  
91 my $sm = XML::NewsML_G2::Scheme_Manager->new(desk => $s1, hltype => $s2, svc => $s3);
92  
93 =head1 ATTRIBUTES
94  
95 =over 4
96  
97 =item crel
98  
99 Scheme for company relations
100  
101 =item desk
102  
103 Scheme for editorial desk
104  
105 =item ean
106  
107 Scheme for european/international article number
108  
109 =item geo
110  
111 Scheme for location information
112  
113 =item hltype
114  
115 Scheme for type of headline
116  
117 =item ind
118  
119 Scheme for content indicators
120  
121 =item isbn
122  
123 Scheme for international standard book number
124  
125 =item org
126  
127 Scheme for organisations
128  
129 =item role
130  
131 Scheme for editorial note roles
132  
133 =item svc
134  
135 Scheme for editorial service
136  
137 =item topic
138  
139 Scheme for topics
140  
141 =item isrol
142  
143 Scheme for info source role
144  
145 =item nprov
146  
147 Scheme for news provder
148  
149 =item ninat
150  
151 Scheme for news item nature
152  
153 =item stat
154  
155 Scheme for document state
156  
157 =item sig
158  
159 Scheme for signals
160  
161 =item iso3166_1a2
162  
163 Scheme for country codes
164  
165 =item genre
166  
167 Scheme for genres
168  
169 =item isin
170  
171 Scheme for ISIN codes
172  
173 =item medtop
174  
175 Scheme for media topics
176  
177 =item rnd
178  
179 Scheme for renditions
180  
181 =item colsp
182  
183 Scheme for colorspaces
184  
185 =item adc
186  
187 Scheme for audio channels
188  
189 =item group
190  
191 Scheme for groups within a package
192  
193 =item pgrmod
194  
195 Scheme for package group mode
196  
197 =item copyright_holder
198  
199 Scheme for copyright holder
200  
201 =item electiondistrict
202  
203 Scheme for election districts
204  
205 =item electionprovince
206  
207 Scheme for election provinces
208  
209 =item facet
210  
211 Scheme for facets
212  
213 =item sportfacet
214  
215 Scheme for sport facets
216  
217 =item sportfacetvalue
218  
219 Scheme for sport facet values
220  
221 =item storytype
222  
223 Scheme for storytypes
224  
225 =item gyibt
226  
227 Scheme for creator kinds
228  
229 =back
230  
231 =head1 METHODS
232  
233 =over 4
234  
235 =item get_all_schemes
236  
237 Returns a list of all registered L<XML::NewsML_G2::Scheme> instances
238  
239 =item build_qcode
240  
241 Build a qcode of the given scheme
242  
243 $scheme_manager->build_qcode('ninat', 'text');
244  
245 If the schema does not provide a catalog or URI, creating a qcode is
246 not possible, and this method will return undef.
247  
248 =item add_qcode
249  
250 Add a qcode attribute of the given scheme to the XML element:
251  
252 $scheme_manager->add_qcode($element, 'ninat', 'text');
253  
254 If the schema does not provide a catalog or URI, creating a qcode is
255 not possible, and this method will die.
256  
257 =item add_qcode_or_literal
258  
259 Same as C<add_qcode>, but will create a C<literal> attribute if
260 creating a qcode is not possible.
261  
262 =item add_role
263  
264 If the scheme is defined, add a role attribute to the given XML
265 element. Else, do nothing.
266  
267 $scheme_manager->add_role($element, 'isrol', 'originfo');
268  
269 =back
270  
271 =head1 AUTHOR
272  
273 Philipp Gortan C<< <philipp.gortan@apa.at> >>
274  
275 =head1 LICENCE AND COPYRIGHT
276  
277 Copyright (c) 2013-2014, APA-IT. All rights reserved.
278  
279 See L<XML::NewsML_G2> for the license.
« Build ↑ Summary blib/lib/XML/NewsML_G2/Scheme.pm »