lib/XML/Schema/Attribute/Group.pm

filter: Statementstmt 91.2% 198 / 217 Branchbran 68.8% 128 / 186 Conditioncond 47.0% 32 / 68 MC/DCmcdc 26.3% 10 / 38 Subroutinesub 85.7% 18 / 21 Podpod 6.6% 1 / 15 totaltotal 71.0% 387 / 545 CC 131 SCAR 33.2
CC
131
Cov
76%
init
51.5
validate
36.9
attribute
21.0
CRAP 27.6
« blib/lib/XML/Schema/Type/Provider.pm ↑ Summary lib/XML/Schema/Particle/Choice.pm »
1 #============================================================= -*-perl-*-
2 #
3 # XML::Schema::Attribute::Group.pm
4 #
5 # DESCRIPTION
6 # Module implementing an attribute group which is used by the
7 # XML::Schema::Type::Complex module to store attributes for a
8 # complex type, and also to define Attribute Groups within a
9 # schema to represent relocatable collections of attributes.
10 #
11 # AUTHOR
12 # Andy Wardley <abw@kfs.org>
13 #
14 # COPYRIGHT
15 # Copyright (C) 2001 Canon Research Centre Europe Ltd.
16 # All Rights Reserved.
17 #
18 # This module is free software; you can redistribute it and/or
19 # modify it under the same terms as Perl itself.
20 #
21 # REVISION
22 # $Id: Group.pm,v 1.2 2001/12/20 13:26:27 abw Exp $
23 #
24 #========================================================================
25  
26 package XML::Schema::Attribute::Group;
27  
28 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 11 ▶use XML::Schema::Scope;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 11 ▶use XML::Schema::Attribute;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 11 ▶use XML::Schema::Constants qw( :attribs );
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 11 ▶use base qw( XML::Schema::Scope );
Subroutine BEGIN: called CC=1 SCAR=0.0
35 11 ▶use vars qw( $VERSION $DEBUG $ERROR @MANDATORY @OPTIONAL );
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 11 $VERSION = sprintf("%d.%02d", q$Revision: 1.2 $ =~ /(\d+)\.(\d+)/);
38 11 ▶$DEBUG = 0 unless defined $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $XML::Schema::Attribute::Group::DEBUG 11 0 11
39 11 $ERROR = '';
40  
41 11 @MANDATORY = qw( name );
42 11 @OPTIONAL = qw( namespace annotation );
43  
44  
45 #------------------------------------------------------------------------
46 # build regexen to match valid attribute usage and constraints values
47 #------------------------------------------------------------------------
48  
49 11 my @USE_OPTS = ( OPTIONAL, REQUIRED, PROHIBITED );
50 11 my $USE_REGEX = join('|', @USE_OPTS);
51 11 $USE_REGEX = qr/^$USE_REGEX$/;
52  
53  
54  
55 #------------------------------------------------------------------------
56 # init(\%config)
57 #
58 # Initiliasation method called by base class new() constructor.
59 # A reference to a hash array of configuration options can be specified
60 # as shown in this example:
61 #
62 # my $group = XML::Schema::Attribute::Group->new({
63 # attributes => {
64 # foo => XML::Schema::Attribute->new(...),
65 # bar => { name => 'bar', type => 'string' }
66 # baz => { type => 'string' }, # name implied by key 'baz'
67 # baz => { type => 'string', use => REQUIRED },
68 # boz => { type => 'string', required => 1 },
69 # wiz => 'string',
70 # },
71 # default_use => OPTIONAL,
72 # use => { # either specify use for each
73 # foo => REQUIRED,
74 # },
75 # required => [ qw( bar baz ) ], # or list each type
76 # }
77 #
78 #------------------------------------------------------------------------
79  
80 55 ▶sub init {
Subroutine init: called CC=38 SCAR=39.4
Pod documented
81 55 my ($self, $config) = @_;
82 55 my ($name, $value);
83  
84 55 ▶ $self->SUPER::init($config)
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init($config) or return 53 2 55
85 || return;
86  
87 53 ▶ my $factory = $self->factory() || return;
Condition50%1/2
$self->factory || (return)
l!l
530
MC/DC0%0/1
$self->factory || (return)
$self->factory
Truth table50%1/2
A
A= $self->factory
Aresult
11
00
88  
89 53 ▶ my $attribs = $config->{ attributes } || { };
Condition100%2/2
$config->{'attributes'} || {}
l!l
2627
MC/DC100%1/1
$config->{'attributes'} || {}
$config->{'attributes'}
Truth table100%2/2
A
A= $config->{'attributes'}
Aresult
11
00
90  
91 # first look for a default_use option, otherwise go with OPTIONAL
92 53 ▶ my $default_use = $self->{ default_use } = $config->{ default_use } || OPTIONAL;
Condition100%2/2
$config->{'default_use'} || 'optional'
l!l
251
MC/DC100%1/1
$config->{'default_use'} || 'optional'
$config->{'default_use'}
Truth table100%2/2
A
A= $config->{'default_use'}
Aresult
11
00
93  
94 53 ▶ return $self->error_value('default_use', $default_use, @USE_OPTS)
Branch: 1 branch
BranchTrueFalseTotal
unless $default_use =~ /$USE_REGEX/ 0 53 53
95 unless $default_use =~ $USE_REGEX;
96  
97 53 ▶ $self->DEBUG("set default_use to $default_use\n") if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $XML::Schema::Attribute::Group::DEBUG 0 53 53
98  
99 # then look for a 'use' hash array...
100 53 my $use = $config->{ use };
101 53 ▶ $use = { } unless ref $use eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $use eq "HASH" 53 0 53
102
103 # ...and check each entry is valid
104 53 foreach $name (keys %$use) {
105 return $self->error("unknown attribute in use hash: '$name'")
106 0 ▶ unless $attribs->{ $name };
Branch: 1 branch
BranchTrueFalseTotal
unless $attribs->{$name} 0 0 0
107  
108 0 $value = $use->{ $name };
109  
110 # allow 0 and 1 as shorthand for OPTIONAL and REQUIRED
111 0 ▶ $value = ($value eq '1') ? REQUIRED
Branch: 2 branches
BranchTrueFalseTotal
$value eq '1' ? : 0 0 0
$value eq '0' ? : 0 0 0
112 : ($value eq '0') ? OPTIONAL : $value;
113  
114 0 ▶ return $self->error_value("use for attribute '$name'", $value, @USE_OPTS)
Branch: 1 branch
BranchTrueFalseTotal
unless $value =~ /$USE_REGEX/ 0 0 0
115 unless $value =~ $USE_REGEX;
116  
117 0 $use->{ name } = $value;
118 }
119  
120 # check for required => { }, optional => { } and prohibited => { } options
121 53 foreach my $value (@USE_OPTS) {
122 159 ▶ my $list = $config->{ $value } || next;
Condition100%2/2
$config->{$value} || (next)
l!l
18141
MC/DC100%1/1
$config->{$value} || (next)
$config->{$value}
Truth table100%2/2
A
A= $config->{$value}
Aresult
11
00
123 18 ▶ $list = [ $list ] unless ref $list eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $list eq "ARRAY" 1 17 18
124  
125 18 foreach $name (@$list) {
126 return $self->error("unknown attribute in $value list: '$name'")
127 22 ▶ unless $attribs->{ $name };
Branch: 1 branch
BranchTrueFalseTotal
unless $attribs->{$name} 0 22 22
128 22 $use->{ $name } = $value;
129 }
130 }
131  
132 53 $self->{ use } = $use;
133  
134 # coerce attributes into objects if not already so
135 $self->{ attributes } = {
136 map {
137 53 my $a = $attribs->{ $_ };
138  
139 63 ▶ if ($factory->isa( attribute => $a )) {
Branch: 1 branch
BranchTrueFalseTotal
if ($factory->isa('attribute', $a)) { } 3 60 63
140 3 $name = $a->name();
141 }
142 else {
143 # if it's not already an attribute object then make it so
144 60 ▶ $a = { type => $a } unless ref $a eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $a eq "HASH" 39 21 60
145 60 ▶ $a->{ name } = $_ unless defined $a->{ name };
Branch: 1 branch
BranchTrueFalseTotal
unless defined $a->{"name"} 55 5 60
146 60 ▶ $a->{ scope } = $self unless defined $a->{ scope };
Branch: 1 branch
BranchTrueFalseTotal
unless defined $a->{"scope"} 60 0 60
147  
148 60 $name = $a->{ name };
149  
150 # allow 'required => 1' to alias for 'use => REQUIRED'
151 60 foreach $value (@USE_OPTS) {
152 180 ▶ $a->{ use } = $value if $a->{ $value };
Branch: 1 branch
BranchTrueFalseTotal
if $a->{$value} 7 173 180
153 }
154  
155 # look for 'use' option
156 60 ▶ if (defined ($value = $a->{ use })) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($value = $a->{"use"})) 11 49 60
157 11 ▶ return $self->error_value("attribute '$name' use", $value, @USE_OPTS)
Branch: 1 branch
BranchTrueFalseTotal
unless $value =~ /$USE_REGEX/ 0 11 11
158 unless $value =~ $USE_REGEX;
159 11 $use->{ $name } = $value;
160 }
161  
162 60 $a = $factory->create( attribute => $a );
163 }
164 $use->{ $name } = $default_use
165 63 ▶ unless defined $use->{ $name };
Branch: 1 branch
BranchTrueFalseTotal
unless defined $use->{$name} 32 31 63
166 63 ▶ $self->DEBUG("set use($name) to $use->{ $name }\n") if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $XML::Schema::Attribute::Group::DEBUG 0 63 63
167 63 ($_, $a);
168 } keys %$attribs
169 };
170  
171 # look for attribute group(s)
172 53 $self->{ groups } = [ ];
173 53 ▶ my $groups = $config->{ groups } || [ ];
Condition100%2/2
$config->{'groups'} || []
l!l
251
MC/DC100%1/1
$config->{'groups'} || []
$config->{'groups'}
Truth table100%2/2
A
A= $config->{'groups'}
Aresult
11
00
174 53 ▶ push(@$groups, $config->{ group }) if $config->{ group };
Branch: 1 branch
BranchTrueFalseTotal
if $config->{"group"} 1 52 53
175  
176 53 foreach my $group (@$groups) {
177 5 ▶ $self->group($group)
Branch: 1 branch
BranchTrueFalseTotal
$self->group($group) or return 5 0 5
178 || return;
179 }
180  
181 # see if a wildcard is defined or something that can be coerced into one
182 53 foreach my $item (qw( any not )) {
183 $config->{ wildcard } ||= { $item => $config->{ $item } }
184 106 ▶ if $config->{ $item };
Branch: 1 branch
BranchTrueFalseTotal
if $config->{$item} 1 105 106
Condition50%1/2
$config->{"wildcard"} ||= {$item, $config->{$item}}
l!l
01
MC/DC0%0/1
$config->{"wildcard"} ||= {$item, $config->{$item}}
$config->{"wildcard"}
Truth table50%1/2
A
A= $config->{"wildcard"}
Aresult
11
00
185 }
186  
187 53 my $wildcard = $config->{ wildcard };
188 53 ▶ if ($wildcard) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wildcard) 14 39 53
189 14 ▶ $wildcard = $factory->create( wildcard => $wildcard )
Branch: 1 branch
BranchTrueFalseTotal
unless $factory->isa("wildcard", $wildcard) 13 1 14
Condition50%1/2
$factory->create('wildcard', $wildcard) || (return $self->error($factory->error))
l!l
130
MC/DC0%0/1
$factory->create('wildcard', $wildcard) || (return $self->error($factory->error))
$factory->create('wildcard', $wildcard)
Truth table50%1/2
A
A= $factory->create('wildcard', $wildcard)
Aresult
11
00
190 || return $self->error( $factory->error() )
191 unless $factory->isa( wildcard => $wildcard );
192 14 $self->{ wildcard } = $wildcard;
193 }
194  
195 53 return $self;
196 }
197  
198  
199 #------------------------------------------------------------------------
200 # attribute( $name ) # return named attributed
201 # attribute( $attr ) # add attribute
202 # attribute( name => $name, type => $type, ... ) # create and add
203 #
204 # Used to retrieve an existing attribute when called with a single
205 # non-reference argument. Used to define a new attribute when passed
206 # with a single reference to an attribute object or a hash reference
207 # or list of arguments which are used to create a new argument via the
208 # factory module.
209 #
210 # <complexType name="personType">
211 # <attribute name="id" type="string"/>
212 # ...
213 # </complextype>
214 #------------------------------------------------------------------------
215  
216 23 ▶sub attribute {
Subroutine attribute: called CC=18 SCAR=30.5
Pod undocumented
217 23 my $self = shift;
218 23 my ($name, $args, $attr, $required);
219  
220 23 ▶ my $factory = $self->factory()
Condition50%1/2
$self->factory || (return)
l!l
230
MC/DC0%0/1
$self->factory || (return)
$self->factory
Truth table50%1/2
A
A= $self->factory
Aresult
11
00
221 || return;
222  
223 23 ▶ if (ref $_[0]) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $_[0]) { } 1 22 23
elsif (scalar @_ == 1) { } 11 11 22
224 # hash array or attribute object
225 1 $args = shift;
226 }
227 elsif (scalar @_ == 1) {
228 # name requesting specific attribute
229 11 $name = shift;
230 11 ▶ return $self->{ attributes }->{ $name }
Condition66%2/3
$self->{'attributes'}{$name} || $self->error("no such attribute: $name")
l!l&&r!l&&!r
1001
MC/DC50%1/2
$self->{'attributes'}{$name} || $self->error("no such attribute: $name")
$self->{'attributes'}{$name} $self->error("no such attribute: $name")
Truth table66%2/3
A || B
A= $self->{'attributes'}{$name}B= $self->error("no such attribute: $name")
ABresult
1X1
011
000
231 || $self->error("no such attribute: $name");
232 }
233 else {
234 11 $args = { @_ };
235 }
236  
237 12 ▶ if ($factory->isa( attribute => $args )) {
Branch: 1 branch
BranchTrueFalseTotal
if ($factory->isa('attribute', $args)) { } 1 11 12
238 1 $attr = $args;
239 1 ▶ $args = ref $_[0] eq 'HASH' ? shift : { @_ };
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 1 1
240 # define scope of attribute unless already set
241 1 ▶ $attr->scope($self)
Branch: 1 branch
BranchTrueFalseTotal
unless defined $attr->scope 0 1 1
242 unless defined $attr->scope();
243 }
244 else {
245 # define scope of attribute unless already set
246 $args->{ scope } = $self
247 if UNIVERSAL::isa($args, 'HASH')
248 11 ▶ && ! exists $args->{ scope };
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($args, "HASH") and not exists $args->{"scope"} 11 0 11
Condition33%1/3
UNIVERSAL::isa($args, "HASH") and not exists $args->{"scope"}
!ll&&!rl&&r
0011
MC/DC0%0/2
UNIVERSAL::isa($args, "HASH") and not exists $args->{"scope"}
UNIVERSAL::isa($args, "HASH") not exists $args->{"scope"}
Truth table33%1/3
A and not(B)
A= UNIVERSAL::isa($args, "HASH")B= not exists $args->{"scope"}
ABresult
0X0
100
111
249  
250 11 ▶ $attr = $factory->create( attribute => $args )
Condition100%2/2
$factory->create('attribute', $args) || (return $self->error($factory->error))
l!l
92
MC/DC100%1/1
$factory->create('attribute', $args) || (return $self->error($factory->error))
$factory->create('attribute', $args)
Truth table100%2/2
A
A= $factory->create('attribute', $args)
Aresult
11
00
251 || return $self->error( $factory->error() );
252 }
253 10 ▶ defined ($name = $attr->name())
Branch: 1 branch
BranchTrueFalseTotal
defined($name = $attr->name) or return $self->error("no name specified for attribute") 10 0 10
254 || return $self->error('no name specified for attribute');
255  
256 10 ▶ $self->DEBUG($self->ID, "->attribute( $name => ", $attr->ID, " )\n")
Branch: 1 branch
BranchTrueFalseTotal
if $XML::Schema::Attribute::Group::DEBUG 0 10 10
257 if $DEBUG;
258  
259 10 $self->{ attributes }->{ $name } = $attr;
260
261 10 ▶ $self->DEBUG("setting use for $name\n") if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $XML::Schema::Attribute::Group::DEBUG 0 10 10
262  
263 # allow 'required => 1' to alias for 'use => REQUIRED'
264 10 foreach my $usage (@USE_OPTS) {
265 30 ▶ $args->{ use } = $usage if $args->{ $usage };
Branch: 1 branch
BranchTrueFalseTotal
if $args->{$usage} 1 29 30
266 }
267  
268 # now set usage
269 $self->use( $name => $args->{ use } || $self->{ default_use } )
270 10 ▶ || return;
Branch: 1 branch
BranchTrueFalseTotal
$self->use($name, $args->{"use"} || $self->{"default_use"}) or return 10 0 10
Condition66%2/3
$args->{'use'} || $self->{'default_use'}
l!l&&r!l&&!r
280
MC/DC0%0/2
$args->{'use'} || $self->{'default_use'}
$args->{'use'} $self->{'default_use'}
Truth table66%2/3
A || B
A= $args->{'use'}B= $self->{'default_use'}
ABresult
1X1
011
000
271  
272 10 return $attr;
273 }
274  
275  
276 #------------------------------------------------------------------------
277 # attributes()
278 #
279 # Returns reference to a hash containing all current attributes defined,
280 # indexed by name.
281 #------------------------------------------------------------------------
282  
283 1 ▶sub attributes {
Subroutine attributes: called CC=1 SCAR=0.0
Pod undocumented
284 1 my $self = shift;
285 1 return $self->{ attributes };
286 }
287  
288  
289 #------------------------------------------------------------------------
290 # group($group)
291 #
292 # Add a new attribute group as a sub-group of this group.
293 #------------------------------------------------------------------------
294  
295 8 ▶sub group {
Subroutine group: called CC=3 SCAR=11.3
Pod undocumented
296 8 my ($self, $group) = @_;
297 8 my $name;
298  
299 8 ▶ if (ref $group) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $group) { } 8 0 8
300 # looks like a new attribute group definition so create and
301 # register it in the current scope
302 8 ▶ $group = $self->attribute_group($group)
Condition50%1/2
$self->attribute_group($group) || (return)
l!l
80
MC/DC0%0/1
$self->attribute_group($group) || (return)
$self->attribute_group($group)
Truth table50%1/2
A
A= $self->attribute_group($group)
Aresult
11
00
303 || return;
304  
305 8 $name = $group->name();
306 }
307 else {
308 # it's the name of an attribute group
309 0 $name = $group;
310 }
311  
312 # add group name to list of sub-groups defined
313 8 push(@{ $self->{ groups } }, $name);
314  
315 # return reference to new group or group name
316 8 return $group;
317 }
318
319  
320  
321 #------------------------------------------------------------------------
322 # groups()
323 #
324 # Returns a reference to a list containing the names of all attribute
325 # groups defined as sub-groups of this group. To fetch a reference to
326 # a hash of all attribute groups defined within the current scope,
327 # call attribute_group() (inherited from XML::Schema::Scope) with no
328 # arguments. Call same method to define new attribute groups within
329 # this scope, but not directly attach them to this group.
330 #------------------------------------------------------------------------
331  
332 0 ▶sub groups {
Subroutine groups: not called CC=1 SCAR=6.9
Pod undocumented
333 0 my $self = shift;
334 0 return $self->{ groups };
335 }
336  
337  
338  
339 #------------------------------------------------------------------------
340 # validate(\%attributes)
341 #
342 #------------------------------------------------------------------------
343  
344 47 ▶sub validate {
Subroutine validate: called CC=32 SCAR=36.1
Pod undocumented
345 47 my ($self, $inbound, $outbound, $scope) = @_;
346 47 my ($name, $attr, $value, $magic, $usage, $wildcard);
347  
348 # if $outbound is undefined then we're the parent group
349 47 ▶ my $parent = $outbound ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$outbound ? : 17 30 47
350 47 ▶ $outbound ||= { };
Condition100%2/2
$outbound ||= {}
l!l
1730
MC/DC100%1/1
$outbound ||= {}
$outbound
Truth table100%2/2
A
A= $outbound
Aresult
11
00
351  
352 # if we've been called as the sub-group of some higher attribute
353 # group validation then we need to bind our scope to that which
354 # it passed us
355 47 ▶ $self->{ scope } = $scope if $scope;
Branch: 1 branch
BranchTrueFalseTotal
if $scope 17 30 47
356  
357 47 my $use = $self->{ use };
358 my $attributes = $self->{ attributes }
359 47 ▶ || return $self->error("no attributes defined");
Condition50%1/2
$self->{'attributes'} || (return $self->error('no attributes defined'))
l!l
470
MC/DC0%0/1
$self->{'attributes'} || (return $self->error('no attributes defined'))
$self->{'attributes'}
Truth table50%1/2
A
A= $self->{'attributes'}
Aresult
11
00
360  
361  
362 # walk through each of our defined attributes seeing if it
363 # appears in $inbound, validate and instantiate it and copy
364 # into $outbound
365  
366 47 keys %$attributes; # reset iterator
367  
368 47 ▶ while (($name, $attr) = each %$attributes) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$attributes) 100 42 142
369  
370 # check usage contraints
371 100 ▶ $usage = $use->{ $name } || $self->{ default_use };
Condition33%1/3
$use->{$name} || $self->{'default_use'}
l!l&&r!l&&!r
10000
MC/DC0%0/2
$use->{$name} || $self->{'default_use'}
$use->{$name} $self->{'default_use'}
Truth table33%1/3
A || B
A= $use->{$name}B= $self->{'default_use'}
ABresult
1X1
011
000
372  
373 100 ▶ $self->TRACE("testing attribute $name usage $usage\n") if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $XML::Schema::Attribute::Group::DEBUG 0 100 100
374  
375 100 ▶ if (defined ($value = $inbound->{ $name })) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($value = $inbound->{$name})) { } 79 21 100
376 79 ▶ return $self->error("attribute '$name' is prohibited")
Branch: 1 branch
BranchTrueFalseTotal
if $usage eq "prohibited" 1 78 79
377 if $usage eq PROHIBITED;
378 }
379 else {
380 21 ▶ return $self->error("required attribute '$name' not defined")
Branch: 1 branch
BranchTrueFalseTotal
if $usage eq "required" 1 20 21
381 if $usage eq REQUIRED;
382  
383 # don't give PROHIBITED attributes a chance to provide defaults
384 20 ▶ next if $usage eq PROHIBITED;
Branch: 1 branch
BranchTrueFalseTotal
if $usage eq "prohibited" 1 19 20
385  
386 # must be OPTIONAL, so it's OK that the attribute is missing
387 # next;
388 }
389  
390 # instantiate attribute
391 97 ($value, $magic) = $attr->instance($value);
392  
393 97 ▶ if (defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) { } 80 17 97
394 80 $outbound->{ $name } = $value;
395 }
396 else {
397 17 my $error = $attr->error();
398 17 ▶ return $self->error("$name attribute: $error")
Branch: 1 branch
BranchTrueFalseTotal
unless $usage eq "optional" and $error eq "no value provided" 3 14 17
Condition66%2/3
$usage eq "optional" and $error eq "no value provided"
!ll&&!rl&&r
3014
MC/DC50%1/2
$usage eq "optional" and $error eq "no value provided"
$usage eq "optional" $error eq "no value provided"
Truth table66%2/3
A and B
A= $usage eq "optional"B= $error eq "no value provided"
ABresult
0X0
100
111
399 unless $usage eq OPTIONAL && $error eq 'no value provided';
400 }
401  
402 94 ▶ if ($magic) {
Branch: 1 branch
BranchTrueFalseTotal
if ($magic) 0 94 94
403 0 ▶ my $list = $outbound->{ _MAGIC }->{ $magic->[0] } ||= [ ];
Condition0%0/2
$outbound->{"_MAGIC"}{$magic->[0]} ||= []
l!l
00
MC/DC0%0/1
$outbound->{"_MAGIC"}{$magic->[0]} ||= []
$outbound->{"_MAGIC"}{$magic->[0]}
Truth table0%0/2
A
A= $outbound->{"_MAGIC"}{$magic->[0]}
Aresult
11
00
404 0 push(@$list, [ attribute => $name, $magic->[1] ]);
405 0 ▶ $self->DEBUG("detected '$magic->[0]' magic valued '$magic->[1]' in $name attribute\n")
Branch: 1 branch
BranchTrueFalseTotal
if $XML::Schema::Attribute::Group::DEBUG 0 0 0
406 if $DEBUG;
407 }
408  
409 94 ▶ $self->TRACE("attribute $name => ", $outbound->{ $name }) if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $XML::Schema::Attribute::Group::DEBUG 0 94 94
410  
411 # all is well so delete entry from inbound hash
412 94 delete $inbound->{ $name };
413 }
414  
415 # any attributes left in the $inbound hash are those that don't
416 # correspond to an attribute defined within this group.
417  
418 42 ▶ if (%$inbound) {
Branch: 1 branch
BranchTrueFalseTotal
if (%$inbound) 34 8 42
419 # try delegating to any defined sub-groups
420 34 foreach $name (@{ $self->{ groups } }) {
421 17 ▶ $self->TRACE("testing sub-group: $name\n") if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $XML::Schema::Attribute::Group::DEBUG 0 17 17
422  
423 # fetch attribute object from group name
424 17 ▶ my $group = $self->attribute_group($name)
Condition50%1/2
$self->attribute_group($name) || (return)
l!l
170
MC/DC0%0/1
$self->attribute_group($name) || (return)
$self->attribute_group($name)
Truth table50%1/2
A
A= $self->attribute_group($name)
Aresult
11
00
425 || return;
426 17 ▶ $group->validate($inbound, $outbound, $self)
Branch: 1 branch
BranchTrueFalseTotal
$group->validate($inbound, $outbound, $self) or return $self->error($group->error) 16 1 17
427 || return $self->error($group->error());
428 }
429
430  
431 # look for a wildcard
432 33 ▶ if ($wildcard = $self->{ wildcard }) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wildcard = $self->{"wildcard"}) 28 5 33
433 28 ▶ $self->TRACE("testing wildcard: $wildcard\n") if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $XML::Schema::Attribute::Group::DEBUG 0 28 28
434 28 keys %$inbound; # reset iterator
435  
436 28 ▶ while (($name, $value) = each %$inbound) {
Branch: 1 branch
BranchTrueFalseTotal
if (($name, $value) = each %$inbound) 86 28 114
437 86 ▶ if ($wildcard->accept($name)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wildcard->accept($name)) 36 50 86
438 36 ▶ $self->TRACE("wildcard accepted $name => $value\n") if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $XML::Schema::Attribute::Group::DEBUG 0 36 36
439 36 $outbound->{ $name } = $value;
440 36 delete $inbound->{ $name };
441 }
442 }
443 }
444 }
445
446 # raise error for any attributes we don't know about
447 41 my @badguys = sort keys %$inbound;
448 41 ▶ if ($parent && @badguys) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parent and @badguys) 6 35 41
Condition100%3/3
$parent and @badguys
!ll&&!rl&&r
16196
MC/DC100%2/2
$parent and @badguys
$parent @badguys
Truth table100%3/3
A and B
A= $parentB= @badguys
ABresult
0X0
100
111
449 6 ▶ return $self->error("unexpected attribute",
Branch: 1 branch
BranchTrueFalseTotal
@badguys > 1 ? : 1 5 6
450 @badguys > 1 ? 's: ' : ': ',
451 join(', ', @badguys));
452 }
453  
454 35 return $outbound;
455 }
456  
457  
458  
459 #------------------------------------------------------------------------
460 # wildcard()
461 # wildcard($new_wildcard)
462 #------------------------------------------------------------------------
463  
464 1 ▶sub wildcard {
Subroutine wildcard: called CC=5 SCAR=18.7
Pod undocumented
465 1 my $self = shift;
466 1 my $wildcard;
467  
468 return $self->{ wildcard }
469 1 ▶ || $self->error("no wildcard defined")
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 1 1
Condition0%0/3
$self->{'wildcard'} || $self->error('no wildcard defined')
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'wildcard'} || $self->error('no wildcard defined')
$self->{'wildcard'} $self->error('no wildcard defined')
Truth table0%0/3
A || B
A= $self->{'wildcard'}B= $self->error('no wildcard defined')
ABresult
1X1
011
000
470 unless @_;
471  
472 1 my $factory = $self->factory();
473  
474 1 ▶ if ($factory->isa( wildcard => $_[0] )) {
Branch: 1 branch
BranchTrueFalseTotal
if ($factory->isa('wildcard', $_[0])) { } 0 1 1
475 0 $wildcard = shift;
476 }
477 else {
478 1 ▶ $wildcard = $factory->create( wildcard => @_ )
Condition50%1/2
$factory->create('wildcard', @_) || (return $self->error($factory->error))
l!l
10
MC/DC0%0/1
$factory->create('wildcard', @_) || (return $self->error($factory->error))
$factory->create('wildcard', @_)
Truth table50%1/2
A
A= $factory->create('wildcard', @_)
Aresult
11
00
479 || return $self->error( $factory->error() );
480 }
481  
482 1 $self->{ wildcard } = $wildcard;
483  
484 1 return $wildcard;
485 }
486  
487  
488  
489 #------------------------------------------------------------------------
490 # name()
491 #
492 # Simple accessor method to return name value.
493 #------------------------------------------------------------------------
494  
495 18 ▶sub name {
Subroutine name: called CC=1 SCAR=0.0
Pod undocumented
496 18 my $self = shift;
497 18 return $self->{ name };
498 }
499  
500  
501 #------------------------------------------------------------------------
502 # namespace( $namespace )
503 #
504 # Simple accessor method to return existing namespace value or set new
505 # namespace when called with an argument.
506 #------------------------------------------------------------------------
507  
508 0 ▶sub namespace {
Subroutine namespace: not called CC=2 SCAR=17.9
Pod undocumented
509 0 my $self = shift;
510 0 ▶ return @_ ? ($self->{ namespace } = shift) : $self->{ namespace };
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
511 }
512  
513  
514 #------------------------------------------------------------------------
515 # default_use($new_default)
516 #
517 # Accessor method to get (when called without arguments) or set (when
518 # called with a single true/false value) the default usage value as
519 # one of the strings 'optional', 'required' or 'prohibited'.
520 #------------------------------------------------------------------------
521  
522 3 ▶sub default_use {
Subroutine default_use: called CC=3 SCAR=11.0
Pod undocumented
523 3 my $self = shift;
524  
525 3 ▶ return $self->{ default_use } unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 2 1 3
526  
527 1 my $use = shift;
528 1 ▶ return $self->error_value('default_use() argument', $use, @USE_OPTS)
Branch: 1 branch
BranchTrueFalseTotal
unless $use =~ /$USE_REGEX/ 0 1 1
529 unless $use =~ $USE_REGEX;
530  
531 1 $self->{ default_use } = $use;
532 }
533  
534  
535 #------------------------------------------------------------------------
536 # use($name, $new_use)
537 #
538 # Accessor method to get (when called without arguments) or set (when
539 # called with a single true/false value) the default usage value as
540 # one of the strings 'optional', 'required' or 'prohibited'.
541 #------------------------------------------------------------------------
542  
543 15 ▶sub use {
Subroutine use: called CC=10 SCAR=27.8
Pod undocumented
544 15 my ($self, $name, $use) = @_;
545  
546 15 ▶ $self->DEBUG("use($name, ", $use || '<undef>', ")\n") if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $XML::Schema::Attribute::Group::DEBUG 0 15 15
Condition0%0/2
$use || '<undef>'
l!l
00
MC/DC0%0/1
$use || '<undef>'
$use
Truth table0%0/2
A
A= $use
Aresult
11
00
547  
548 15 ▶ if (defined $name) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name) { } 15 0 15
549 return $self->error("no such attribute: '$name'")
550 15 ▶ unless defined $self->{ attributes }->{ $name };
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"attributes"}{$name} 1 14 15
551  
552 14 ▶ if (defined $use) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $use) { } 13 1 14
553 13 ▶ return $self->error_value("use for attribute '$name'", $use, @USE_OPTS)
Branch: 1 branch
BranchTrueFalseTotal
unless $use =~ /$USE_REGEX/ 0 13 13
554 unless $use =~ $USE_REGEX;
555 13 ▶ return ($self->{ use }->{ $name } = $use) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
($self->{'use'}{$name} = $use) ? : 13 0 13
556 }
557 else {
558 1 ▶ return $self->{ use }->{ $name } || $self->error("no use");
Condition33%1/3
$self->{'use'}{$name} || $self->error('no use')
l!l&&r!l&&!r
100
MC/DC0%0/2
$self->{'use'}{$name} || $self->error('no use')
$self->{'use'}{$name} $self->error('no use')
Truth table33%1/3
A || B
A= $self->{'use'}{$name}B= $self->error('no use')
ABresult
1X1
011
000
559 }
560 }
561 else {
562 0 ▶ return $self->{ use } unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 0 0
563 }
564 }
565  
566  
567 #------------------------------------------------------------------------
568 # required($name, $value)
569 #
570 # When called without any arguments, this method returns a reference
571 # to the internal hash table indicating which attributes are required.
572 # When called with a single argument, $name, it returns a boolean
573 # value to indicate if the named argument is required or not. When
574 # called with an additional argument, $value, the flag for the
575 # attribute is updated to the new value. Returns undef with an error
576 # set if the attribute name is not recognised.
577 #------------------------------------------------------------------------
578  
579 30 ▶sub required {
Subroutine required: called CC=10 SCAR=24.5
Pod undocumented
580 30 my ($self, $name, $value) = @_;
581  
582 30 ▶ $self->DEBUG("required(", $name || '<undef>', ", ", $value || '<undef>', ")\n") if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $XML::Schema::Attribute::Group::DEBUG 0 30 30
Condition0%0/4
$name || '<undef>'
l!l
00
$value || '<undef>'
l!l
00
MC/DC0%0/1
$name || '<undef>'
$name
MC/DC0%0/1
$value || '<undef>'
$value
Truth table0%0/2
A
A= $name
Aresult
11
00
Truth table0%0/2
A
A= $value
Aresult
11
00
583  
584 30 ▶ if (defined $name) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name) { } 28 2 30
585 return $self->error("no such attribute: '$name'")
586 28 ▶ unless defined $self->{ attributes }->{ $name };
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"attributes"}{$name} 0 28 28
587  
588 28 ▶ if (defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) { } 1 27 28
589 1 ▶ return $self->use( $name => $value ? REQUIRED : OPTIONAL );
Branch: 1 branch
BranchTrueFalseTotal
$value ? : 1 0 1
590 }
591 else {
592 27 ▶ return $self->{ use }->{ $name } eq REQUIRED ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'use'}{$name} eq 'required' ? : 15 12 27
593 }
594 }
595 else {
596 2 my $use = $self->{ use };
597 return [
598 2 ▶ map { $use->{ $_ } eq REQUIRED ? $_ : () }
Branch: 1 branch
BranchTrueFalseTotal
$use->{$_} eq 'required' ? : 5 5 10
599 keys %$use
600 ];
601 }
602  
603 # not reached
604 }
605  
606  
607 #------------------------------------------------------------------------
608 # optional($name, $value)
609 #
610 # As per required() above, for OPTIONAL attributes.
611 #------------------------------------------------------------------------
612  
613 6 ▶sub optional {
Subroutine optional: called CC=10 SCAR=26.8
Pod undocumented
614 6 my ($self, $name, $value) = @_;
615  
616 6 ▶ $self->DEBUG("optional(", $name || '<undef>', ", ", $value || '<undef>', ")\n") if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $XML::Schema::Attribute::Group::DEBUG 0 6 6
Condition0%0/4
$name || '<undef>'
l!l
00
$value || '<undef>'
l!l
00
MC/DC0%0/1
$name || '<undef>'
$name
MC/DC0%0/1
$value || '<undef>'
$value
Truth table0%0/2
A
A= $name
Aresult
11
00
Truth table0%0/2
A
A= $value
Aresult
11
00
617  
618 6 ▶ if (defined $name) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name) { } 5 1 6
619 return $self->error("no such attribute: '$name'")
620 5 ▶ unless defined $self->{ attributes }->{ $name };
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"attributes"}{$name} 0 5 5
621  
622 5 ▶ if (defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) { } 0 5 5
623 0 ▶ return $self->use( $name => $value ? OPTIONAL : REQUIRED );
Branch: 1 branch
BranchTrueFalseTotal
$value ? : 0 0 0
624 }
625 else {
626 5 ▶ return $self->{ use }->{ $name } eq OPTIONAL ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'use'}{$name} eq 'optional' ? : 4 1 5
627 }
628 }
629 else {
630 1 my $use = $self->{ use };
631 return [
632 1 ▶ map { $use->{ $_ } eq OPTIONAL ? $_ : () }
Branch: 1 branch
BranchTrueFalseTotal
$use->{$_} eq 'optional' ? : 2 3 5
633 keys %$use
634 ];
635 }
636  
637 # not reached
638 }
639  
640  
641 #------------------------------------------------------------------------
642 # prohibited($name, $value)
643 #
644 # As per required() above, for PROHIBITED attributes.
645 #------------------------------------------------------------------------
646  
647 3 ▶sub prohibited {
Subroutine prohibited: called CC=10 SCAR=27.8
Pod undocumented
648 3 my ($self, $name, $value) = @_;
649  
650 3 ▶ $self->DEBUG("prohibited(", $name || '<undef>', ", ", $value || '<undef>', ")\n") if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $XML::Schema::Attribute::Group::DEBUG 0 3 3
Condition0%0/4
$name || '<undef>'
l!l
00
$value || '<undef>'
l!l
00
MC/DC0%0/1
$name || '<undef>'
$name
MC/DC0%0/1
$value || '<undef>'
$value
Truth table0%0/2
A
A= $name
Aresult
11
00
Truth table0%0/2
A
A= $value
Aresult
11
00
651  
652 3 ▶ if (defined $name) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name) { } 1 2 3
653 return $self->error("no such attribute: '$name'")
654 1 ▶ unless defined $self->{ attributes }->{ $name };
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"attributes"}{$name} 0 1 1
655  
656 1 ▶ if (defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) { } 1 0 1
657 1 ▶ return $self->use( $name => $value ? PROHIBITED : OPTIONAL );
Branch: 1 branch
BranchTrueFalseTotal
$value ? : 1 0 1
658 }
659 else {
660 0 ▶ return $self->{ use }->{ $name } eq PROHIBITED ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'use'}{$name} eq 'prohibited' ? : 0 0 0
661 }
662 }
663 else {
664 2 my $use = $self->{ use };
665 return [
666 2 ▶ map { $use->{ $_ } eq PROHIBITED ? $_ : () }
Branch: 1 branch
BranchTrueFalseTotal
$use->{$_} eq 'prohibited' ? : 1 9 10
667 keys %$use
668 ];
669 }
670  
671 # not reached
672 }
673  
674  
675  
676 0 ▶sub ID {
Subroutine ID: not called CC=1 SCAR=6.9
Pod undocumented
677 0 my $self = shift;
678 0 return $self->{ name };
679 }
680  
681  
682 11 1;
683  
684 __END__
« blib/lib/XML/Schema/Type/Provider.pm ↑ Summary lib/XML/Schema/Particle/Choice.pm »