lib/XML/Schema/Particle/Element.pm

filter: Statementstmt 81.5% 31 / 38 Branchbran 59.0% 13 / 22 Conditioncond 50.0% 2 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 71.4% 5 / 7 Podpod 25.0% 1 / 4 totaltotal 67.5% 52 / 77 CC 14 SCAR 19.1
CC
14
Cov
72%
match
12.0
element
8.5
init
5.2
CRAP 6.8
« lib/XML/Schema/Type/Simple.pm ↑ Summary lib/XML/Schema/Content.pm »
1 #============================================================= -*-perl-*-
2 #
3 # XML::Schema::Particle::Element.pm
4 #
5 # DESCRIPTION
6 # Subclassed particle to contain a reference to a element instead
7 # of a simple particle.
8 #
9 # AUTHOR
10 # Andy Wardley <abw@kfs.org>
11 #
12 # COPYRIGHT
13 # Copyright (C) 2001 Canon Research Centre Europe Ltd.
14 # All Rights Reserved.
15 #
16 # This module is free software; you can redistribute it and/or
17 # modify it under the same terms as Perl itself.
18 #
19 # REVISION
20 # $Id: Element.pm,v 1.1.1.1 2001/08/29 14:30:17 abw Exp $
21 #
22 #========================================================================
23  
24 package XML::Schema::Particle::Element;
25  
26 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 5 ▶use base qw( XML::Schema::Particle );
Subroutine BEGIN: called CC=1 SCAR=0.0
28 5 ▶use vars qw( $VERSION $DEBUG $ERROR $ETYPE );
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 5 $VERSION = sprintf("%d.%02d", q$Revision: 1.1.1.1 $ =~ /(\d+)\.(\d+)/);
31 #$DEBUG = 0 unless defined $DEBUG;
32 #$ERROR = '';
33 5 $ETYPE = 'ElementParticle';
34  
35 5 *DEBUG = \$XML::Schema::Particle::DEBUG;
36 5 *ERROR = \$XML::Schema::Particle::ERROR;
37 #*DECLINED = \&XML::Schema::Particle::DECLINED;
38  
39  
40 #------------------------------------------------------------------------
41 # init()
42 #
43 # Called automatically by base class new() method.
44 #------------------------------------------------------------------------
45  
46 20 ▶sub init {
Subroutine init: called CC=5 SCAR=16.5
Pod documented
47 20 my ($self, $config) = @_;
48  
49 20 ▶ $self->TRACE("config => ", $config) if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $XML::Schema::Particle::Element::DEBUG 0 20 20
50  
51 20 $self->{ type } = 'element';
52 $self->{ element } = $config->{ element }
53 20 ▶ || return $self->error(ref $self, ': element not specified');
Condition50%1/2
$config->{'element'} || (return $self->error(ref $self, ': element not specified'))
l!l
200
MC/DC0%0/1
$config->{'element'} || (return $self->error(ref $self, ': element not specified'))
$config->{'element'}
Truth table50%1/2
A
A= $config->{'element'}
Aresult
11
00
54 $self->{ name } = $self->{ element }->name()
55 20 ▶ || return $self->error("unable to determine name for element '$self->{ element }'");
Condition50%1/2
$self->{'element'}->name || (return $self->error("unable to determine name for element '$self->{'element'}'"))
l!l
200
MC/DC0%0/1
$self->{'element'}->name || (return $self->error("unable to determine name for element '$self->{'element'}'"))
$self->{'element'}->name
Truth table50%1/2
A
A= $self->{'element'}->name
Aresult
11
00
56  
57 20 ▶ $self->constrain($config)
Branch: 1 branch
BranchTrueFalseTotal
$self->constrain($config) or return 19 1 20
58 || return;
59  
60 19 return $self;
61 }
62  
63  
64 16 ▶sub element {
Subroutine element: called CC=8 SCAR=21.4
Pod undocumented
65 16 my ($self, $name) = @_;
66 my ($min, $max, $occurs, $ename)
67 16 = @$self{ qw( min max occurs name ) };
68 16 $self->{ _ERROR } = '';
69  
70 # return element reference for reflective purposes when called
71 # without a name argument
72 return $self->{ element }
73 16 ▶ unless $name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 6 10 16
74  
75 10 ▶ $self->TRACE("name => $name") if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $XML::Schema::Particle::Element::DEBUG 0 10 10
76  
77 # if the element names don't match then the candidate element must
78 # belong to the next particle in the content model; we must therefore
79 # validate the current particle to ensure it has been satisfied
80 10 ▶ unless ($name eq $ename) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($name eq $ename) 2 8 10
81
82 2 ▶ return $self->error("unexpected <$name> found (min. $min <$ename> element",
Branch: 2 branches
BranchTrueFalseTotal
if $occurs < $min 2 0 2
$min > 1 ? : 0 2 2
83 $min > 1 ? 's' : '', " required)")
84 if $occurs < $min;
85  
86 0 return $self->decline("unexpected <$name> element found");
87 }
88  
89 # at this point, we know the element names match, but we may have
90 # exceeded our maxOccurs limit, in which case we decline hoping
91 # that a subsequent particle can collect it
92 8 ▶ return $self->decline("maximum of $max <$ename> element",
Branch: 2 branches
BranchTrueFalseTotal
unless $occurs < $max 3 5 8
$max > 1 ? : 3 0 3
93 $max > 1 ? 's' : '', " exceeded")
94 unless $occurs < $max;
95  
96 # OK, it looks like the particle can accept the element
97 5 $self->{ occurs }++;
98  
99 5 return $self->{ element };
100 }
101  
102  
103 0 ▶sub match {
Subroutine match: not called CC=3 SCAR=24.8
Pod undocumented
104 0 my ($self, $name) = @_;
105  
106 # true if names match
107 0 ▶ return 1 if $self->{ name } eq $name;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"name"} eq $name 0 0 0
108  
109 # false if names don't match but particle has minOccurs == 0
110 0 ▶ return 0 if $self->{ min } == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"min"} == 0 0 0 0
111  
112 # undef otherwise
113 0 return undef;
114 }
115  
116  
117 0 ▶sub ID {
Subroutine ID: not called CC=1 SCAR=6.9
Pod undocumented
118 0 my $self = shift;
119 0 return "$ETYPE\[$self->{ name }]";
120 }
121
122 5 1;
123  
124  
« lib/XML/Schema/Type/Simple.pm ↑ Summary lib/XML/Schema/Content.pm »