blib/lib/XML/NewsML_G2/Scheme_Manager.pm

filter: Statementstmt 82.8% 29 / 35 Branchbran 33.3% 4 / 12 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 87.5% 7 / 8 Podpod 100% 4 / 4 totaltotal 67.6% 46 / 68 CC 9 SCAR 16.1
CC
9
Cov
66%
add_role
12.0
_add_qcode
6.3
add_qcode_or_literal
2.0
CRAP 5.0
« blib/lib/XML/NewsML_G2/Writer.pm ↑ Summary Build »
1 package XML::NewsML_G2::Scheme_Manager;
2  
3 # $Id: Scheme_Manager.pm 47068 2013-07-03 12:17:55Z apatecgortan $
4  
5 13 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 13 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 13 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9  
10 13 foreach (qw(desk hltype role ind geo org topic crel svc isbn ean isrol
11 nprov ninat stat sig iso3166_1a2 genre isin medtop)) {
12 260 has $_, isa => 'XML::NewsML_G2::Scheme', is => 'rw';
13 }
14  
15 # public methods
16  
17 sub get_all_schemes {
18 5 ▶ my $self = shift;
Subroutine get_all_schemes: called CC=1 SCAR=0.0
Pod documented
19  
20 5 return grep {defined} map {$self->can($_)->($self)} sort $self->meta->get_attribute_list();
21 }
22  
23 sub add_qcode_or_literal {
24 10 ▶ my ($self, $elem, $name, $value) = @_;
Subroutine add_qcode_or_literal: called CC=2 SCAR=7.1
Pod documented
25 10 ▶ $self->_add_qcode($elem, $name, $value) or $elem->setAttribute('literal', $name . '#' . $value);
Branch: 1 branch
BranchTrueFalseTotal
$self->_add_qcode($elem, $name, $value) or $elem->setAttribute("literal", $name . '#' . $value) 0 10 10
26 10 return 1;
27 }
28  
29 sub add_qcode {
30 5 ▶ my ($self, $elem, $name, $value) = @_;
Subroutine add_qcode: called CC=2 SCAR=7.1
Pod documented
31 5 ▶ $self->_add_qcode($elem, $name, $value) or die "Specifying a '$name' schema with uri or catalog required\n";
Branch: 1 branch
BranchTrueFalseTotal
$self->_add_qcode($elem, $name, $value) or die "Specifying a '${name}' schema with uri or catalog required\n" 0 5 5
32 5 return 1;
33 }
34  
35 sub add_role {
36 0 ▶ my ($self, $elem, $name, $value) = @_;
Subroutine add_role: not called CC=3 SCAR=24.8
Pod documented
37 0 ▶ my $getter = $self->can($name) or croak "No schema named '$name'!";
Branch: 1 branch
BranchTrueFalseTotal
my $getter = $self->can($name) or croak("No schema named '${name}'!") 0 0 0
38 0 my $scheme = $getter->($self);
39 0 ▶ return unless $scheme;
Branch: 1 branch
BranchTrueFalseTotal
unless $scheme 0 0 0
40  
41 0 $elem->setAttribute('role', $scheme->alias . ':' . $value);
42 0 return 1;
43 }
44  
45 # private methods
46  
47 sub _add_qcode {
48 15 ▶ my ($self, $elem, $name, $value) = @_;
Subroutine _add_qcode: called CC=5 SCAR=18.4
49  
50 15 ▶ my $getter = $self->can($name) or croak "No schema named '$name'!";
Branch: 1 branch
BranchTrueFalseTotal
my $getter = $self->can($name) or croak("No schema named '${name}'!") 0 15 15
51 15 my $scheme = $getter->($self);
52 15 ▶ return unless ($scheme and ($scheme->uri or $scheme->catalog));
Branch: 1 branch
BranchTrueFalseTotal
unless $scheme and $scheme->uri || $scheme->catalog 0 15 15
Condition33%2/6
$scheme and $scheme->uri || $scheme->catalog
!ll&&!rl&&r
0015
$scheme->uri or $scheme->catalog
l!l&&r!l&&!r
0150
MC/DC0%0/3
$scheme and $scheme->uri || $scheme->catalog
$scheme $scheme->uri $scheme->catalog
Truth table25%1/4
A and B or C
A= $schemeB= $scheme->uriC= $scheme->catalog
ABCresult
0XX0
1000
11X1
1011
53  
54 15 $elem->setAttribute('qcode', $scheme->alias . ':' . $value);
55 15 return 1;
56 }
57  
58  
59 13 __PACKAGE__->meta->make_immutable;
60  
61 13 1;
62  
63 __END__
64  
65 =head1 NAME
66  
67 XML::NewsML_G2::Scheme_Manager - hold all L<XML::NewsML_G2::Scheme> instances
68  
69  
70 =for test_synopsis
71 my ($s1, $s2, $s3);
72  
73 =head1 SYNOPSIS
74  
75 my $sm = XML::NewsML_G2::Scheme_Manager->new(desk => $s1, hltype => $s2, svc => $s3);
76  
77 =head1 ATTRIBUTES
78  
79 =over 4
80  
81 =item crel
82  
83 Scheme for company relations
84  
85 =item desk
86  
87 Scheme for editorial desk
88  
89 =item ean
90  
91 Scheme for european/international article number
92  
93 =item geo
94  
95 Scheme for location information
96  
97 =item hltype
98  
99 Scheme for type of headline
100  
101 =item ind
102  
103 Scheme for content indicators
104  
105 =item isbn
106  
107 Scheme for international standard book number
108  
109 =item org
110  
111 Scheme for organisations
112  
113 =item role
114  
115 Scheme for editorial note roles
116  
117 =item svc
118  
119 Scheme for editorial service
120  
121 =item topic
122  
123 Scheme for topics
124  
125  
126 =item isrol
127  
128 =item nprov
129  
130 =item ninat
131  
132 =item stat
133  
134 =item sig
135  
136 =item iso3166_1a2
137  
138 =item genre
139  
140 =item isin
141  
142 =item medtop
143  
144 =back
145  
146 =head1 METHODS
147  
148 =over 4
149  
150 =item get_all_schemes
151  
152 Returns a list of all registered L<XML::NewsML_G2::Scheme> instances
153  
154 =item add_qcode
155  
156 Add a qcode attribute of the given scheme to the XML element:
157  
158 $scheme_manager->add_qcode($element, 'ninat', 'text');
159  
160 If the schema does not provide a catalog or URI, creating a qcode is
161 not possible, and this method will die.
162  
163 =item add_qcode_or_literal
164  
165 Same as C<add_qcode>, but will create a C<literal> attribute if
166 creating a qcode is not possible.
167  
168 =item add_role
169  
170 If the scheme is defined, add a role attribute to the given XML
171 element. Else, do nothing.
172  
173 $scheme_manager->add_role($element, 'isrol', 'originfo');
174  
175 =back
176  
177 =head1 AUTHOR
178  
179 Philipp Gortan C<< <philipp.gortan@apa.at> >>
180  
181 =head1 LICENCE AND COPYRIGHT
182  
183 Copyright (c) 2013, APA-IT. All rights reserved.
184  
185 See L<XML::NewsML_G2> for the license.
« blib/lib/XML/NewsML_G2/Writer.pm ↑ Summary Build »