lib/XML/Schema.pm

filter: Statementstmt 64.3% 47 / 73 Branchbran 19.4% 7 / 36 Conditioncond 15.9% 7 / 44 MC/DCmcdc 0.0% 0 / 27 Subroutinesub 73.3% 11 / 15 Podpod 12.5% 1 / 8 totaltotal 35.9% 73 / 203 CC 35 SCAR 37.5
CC
35
Cov
40%
old_element
132.0
content
42.0
handler
42.0
CRAP 42.6
« lib/XML/Schema/Handler/Complex.pm ↑ Summary lib/XML/Schema/Instance.pm »
1 #============================================================= -*-perl-*-
2 #
3 # XML::Schema
4 #
5 # DESCRIPTION
6 # Modules for representing, constucting and utilising XML Schemata
7 # in Perl.
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: Schema.pm,v 1.2 2001/12/20 13:26:27 abw Exp $
21 #
22 #========================================================================
23  
24 package XML::Schema;
25  
26 28 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 28 ▶use XML::Schema::Element;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 28 ▶use XML::Schema::Factory;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 28 ▶use XML::Schema::Scope;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 28 ▶use XML::Schema::Type;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 28 ▶use base qw( XML::Schema::Scope );
Subroutine BEGIN: called CC=1 SCAR=0.0
32 28 ▶use vars qw( $VERSION $DEBUG $ERROR $ETYPE $FACTORY @OPTIONAL );
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 28 $VERSION = 0.07;
35 28 ▶$DEBUG = 0 unless defined $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $XML::Schema::DEBUG 28 0 28
36 28 $ERROR = '';
37 28 $ETYPE = 'Schema';
38 28 $FACTORY = 'XML::Schema::Factory';
39 28 @OPTIONAL = qw( element );
40  
41  
42 5 ▶sub init {
Subroutine init: called CC=3 SCAR=11.4
Pod documented
43 5 my ($self, $config) = @_;
44  
45 5 ▶ $self->SUPER::init($config)
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init($config) or return 5 0 5
46 || return;
47  
48 my $factory = $self->{ _FACTORY }
49 5 ▶ || return $self->error("no factory defined");
Condition50%1/2
$self->{'_FACTORY'} || (return $self->error('no factory defined'))
l!l
50
MC/DC0%0/1
$self->{'_FACTORY'} || (return $self->error('no factory defined'))
$self->{'_FACTORY'}
Truth table50%1/2
A
A= $self->{'_FACTORY'}
Aresult
11
00
50  
51 # allow (but don't enfore) content model to be created by specifying
52 # 'type', 'particle' or 'content' in config
53 # $self->{ content } = $FACTORY->content($config);
54 # || return $self->error($FACTORY->error());
55 #
56 # $self->TRACE("content => ", $self->{ content }) if $DEBUG;
57  
58 5 return $self;
59 }
60  
61  
62 3 ▶sub element {
Subroutine element: called CC=3 SCAR=15.1
Pod undocumented
63 3 my $self = shift;
64 3 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 3 0 3
65 3 return ($self->{ element } = $self->SUPER::element(@_));
66 }
67 else {
68 return $self->{ element }
69 0 ▶ || $self->error("no element defined");
Condition0%0/3
$self->{'element'} || $self->error('no element defined')
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'element'} || $self->error('no element defined')
$self->{'element'} $self->error('no element defined')
Truth table0%0/3
A || B
A= $self->{'element'}B= $self->error('no element defined')
ABresult
1X1
011
000
70 }
71 }
72  
73 0 ▶sub old_element {
Subroutine old_element: not called CC=11 SCAR=48.8
Pod undocumented
74 0 my $self = shift;
75 my $factory = $self->{ _FACTORY }
76 0 ▶ || return $self->error("no factory defined");
Condition0%0/2
$self->{'_FACTORY'} || (return $self->error('no factory defined'))
l!l
00
MC/DC0%0/1
$self->{'_FACTORY'} || (return $self->error('no factory defined'))
$self->{'_FACTORY'}
Truth table0%0/2
A
A= $self->{'_FACTORY'}
Aresult
11
00
77  
78 0 ▶ $self->TRACE() if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $XML::Schema::DEBUG 0 0 0
79  
80 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
81 0 ▶ if ($factory->isa( element => $_[0] )) {
Branch: 1 branch
BranchTrueFalseTotal
if ($factory->isa('element', $_[0])) { } 0 0 0
82 0 ▶ $self->TRACE("adding element") if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $XML::Schema::DEBUG 0 0 0
83 0 $self->{ element } = shift;
84 }
85 else {
86 0 ▶ my $args = UNIVERSAL::isa($_[0], 'HASH') ? shift : { @_ };
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::isa($_[0], 'HASH') ? : 0 0 0
87 0 ▶ $args->{ scope } = $self unless exists $args->{ scope };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args->{"scope"} 0 0 0
88 0 ▶ $self->TRACE("creating element") if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $XML::Schema::DEBUG 0 0 0
89 0 ▶ $self->{ element } = $factory->create( element => $args )
Condition0%0/2
$factory->create('element', $args) || (return $self->error($factory->error))
l!l
00
MC/DC0%0/1
$factory->create('element', $args) || (return $self->error($factory->error))
$factory->create('element', $args)
Truth table0%0/2
A
A= $factory->create('element', $args)
Aresult
11
00
90 || return $self->error($factory->error());
91 }
92 }
93 else {
94 return $self->{ element }
95 0 ▶ || $self->error("no element defined");
Condition0%0/3
$self->{'element'} || $self->error('no element defined')
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'element'} || $self->error('no element defined')
$self->{'element'} $self->error('no element defined')
Truth table0%0/3
A || B
A= $self->{'element'}B= $self->error('no element defined')
ABresult
1X1
011
000
96 }
97 }
98  
99  
100 #------------------------------------------------------------------------
101 # content()
102 # content($item)
103 #
104 # Return the current content model for the schema (if any) when called
105 # without any args. Sets the content model (converting it to a Content
106 # object if necessary) when called with an argument.
107 #------------------------------------------------------------------------
108  
109 0 ▶sub content {
Subroutine content: not called CC=6 SCAR=37.4
Pod undocumented
110 0 my $self = shift;
111  
112 return ($self->{ content }
113 0 ▶ || $self->error('schema has no content model'))
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
Condition0%0/3
$self->{'content'} || $self->error('schema has no content model')
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'content'} || $self->error('schema has no content model')
$self->{'content'} $self->error('schema has no content model')
Truth table0%0/3
A || B
A= $self->{'content'}B= $self->error('schema has no content model')
ABresult
1X1
011
000
114 unless @_;
115  
116 0 ▶ $self->TRACE("content: ", @_) if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $XML::Schema::DEBUG 0 0 0
117  
118 my $factory = $self->{ _FACTORY }
119 0 ▶ || return $self->error("no factory defined");
Condition0%0/2
$self->{'_FACTORY'} || (return $self->error('no factory defined'))
l!l
00
MC/DC0%0/1
$self->{'_FACTORY'} || (return $self->error('no factory defined'))
$self->{'_FACTORY'}
Truth table0%0/2
A
A= $self->{'_FACTORY'}
Aresult
11
00
120  
121 0 ▶ return ($self->{ content } = $factory->create( content => @_ ))
Condition0%0/3
($self->{'content'} = $factory->create('content', @_)) || $self->error($factory->error)
l!l&&r!l&&!r
000
MC/DC0%0/2
($self->{'content'} = $factory->create('content', @_)) || $self->error($factory->error)
($self->{'content'} = $factory->create('content', @_)) $self->error($factory->error)
Truth table0%0/3
A || B
A= ($self->{'content'} = $factory->create('content', @_))B= $self->error($factory->error)
ABresult
1X1
011
000
122 || $self->error($factory->error());
123 }
124  
125  
126 #------------------------------------------------------------------------
127 # parser(@args)
128 #
129 # Create a parser object (XML::Schema::Parser by default) primed for
130 # validation against this schema. Arguments are folded into a hash
131 # reference, if not already provided as such, and the 'schema' item is
132 # added, containing a reference to the $self schema object.
133 #------------------------------------------------------------------------
134  
135 1 ▶sub parser {
Subroutine parser: called CC=6 SCAR=20.9
Pod undocumented
136 1 my $self = shift;
137 1 ▶ my $args = $_[0] && ref($_[0]) eq 'HASH' ? shift : { @_ };
Branch: 1 branch
BranchTrueFalseTotal
$_[0] && ref $_[0] eq 'HASH' ? : 0 1 1
Condition33%1/3
$_[0] and ref $_[0] eq "HASH"
!ll&&!rl&&r
100
MC/DC0%0/2
$_[0] and ref $_[0] eq "HASH"
$_[0] ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= $_[0]B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
138  
139 1 $args->{ schema } = $self;
140  
141 1 ▶ $self->TRACE("args => ", $args) if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $XML::Schema::DEBUG 0 1 1
142  
143 my $factory = $self->{ _FACTORY }
144 1 ▶ || return $self->error("no factory defined");
Condition50%1/2
$self->{'_FACTORY'} || (return $self->error('no factory defined'))
l!l
10
MC/DC0%0/1
$self->{'_FACTORY'} || (return $self->error('no factory defined'))
$self->{'_FACTORY'}
Truth table50%1/2
A
A= $self->{'_FACTORY'}
Aresult
11
00
145  
146 1 ▶ return $factory->create( parser => $args )
Condition33%1/3
$factory->create('parser', $args) || $self->error($factory->error)
l!l&&r!l&&!r
001
MC/DC0%0/2
$factory->create('parser', $args) || $self->error($factory->error)
$factory->create('parser', $args) $self->error($factory->error)
Truth table33%1/3
A || B
A= $factory->create('parser', $args)B= $self->error($factory->error)
ABresult
1X1
011
000
147 || $self->error($factory->error());
148 }
149  
150  
151 #------------------------------------------------------------------------
152 # instance(@args)
153 #
154 # Create an instance object (XML::Schema::Instance by default) for
155 # representing the generated content created by parsing an instance
156 # document of this schema. Arguments are folded into a hash
157 # reference, if not already provided as such, and the 'schema' item is
158 # added, containing a reference to the $self schema object.
159 #------------------------------------------------------------------------
160  
161 1 ▶sub instance {
Subroutine instance: called CC=6 SCAR=20.9
Pod undocumented
162 1 my $self = shift;
163 1 ▶ my $args = $_[0] && ref($_[0]) eq 'HASH' ? shift : { @_ };
Branch: 1 branch
BranchTrueFalseTotal
$_[0] && ref $_[0] eq 'HASH' ? : 0 1 1
Condition33%1/3
$_[0] and ref $_[0] eq "HASH"
!ll&&!rl&&r
100
MC/DC0%0/2
$_[0] and ref $_[0] eq "HASH"
$_[0] ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= $_[0]B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
164  
165 1 $args->{ schema } = $self;
166  
167 1 ▶ $self->TRACE("args => ", $args) if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $XML::Schema::DEBUG 0 1 1
168  
169 my $factory = $self->{ _FACTORY }
170 1 ▶ || return $self->error("no factory defined");
Condition50%1/2
$self->{'_FACTORY'} || (return $self->error('no factory defined'))
l!l
10
MC/DC0%0/1
$self->{'_FACTORY'} || (return $self->error('no factory defined'))
$self->{'_FACTORY'}
Truth table50%1/2
A
A= $self->{'_FACTORY'}
Aresult
11
00
171  
172 1 ▶ return $factory->create( instance => $args )
Condition33%1/3
$factory->create('instance', $args) || $self->error($factory->error)
l!l&&r!l&&!r
100
MC/DC0%0/2
$factory->create('instance', $args) || $self->error($factory->error)
$factory->create('instance', $args) $self->error($factory->error)
Truth table33%1/3
A || B
A= $factory->create('instance', $args)B= $self->error($factory->error)
ABresult
1X1
011
000
173 || $self->error($factory->error());
174 }
175  
176  
177 #------------------------------------------------------------------------
178 # handler(@args)
179 #
180 # Create a parser object (XML::Schema::Parser by default) for parsing
181 # instance documents according to the current schema. Arguments are
182 # folded into a hash reference, if not already provided as such, and
183 # the 'schema' item is added, containing a reference to the $self
184 # schema object.
185 #------------------------------------------------------------------------
186  
187 0 ▶sub handler {
Subroutine handler: not called CC=6 SCAR=37.4
Pod undocumented
188 0 my $self = shift;
189 0 ▶ my $args = $_[0] && ref($_[0]) eq 'HASH' ? shift : { @_ };
Branch: 1 branch
BranchTrueFalseTotal
$_[0] && ref $_[0] eq 'HASH' ? : 0 0 0
Condition0%0/3
$_[0] and ref $_[0] eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
$_[0] and ref $_[0] eq "HASH"
$_[0] ref $_[0] eq "HASH"
Truth table0%0/3
A and B
A= $_[0]B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
190  
191 0 $args->{ schema } = $self;
192  
193 0 ▶ $self->TRACE("args => ", $args) if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $XML::Schema::DEBUG 0 0 0
194  
195 my $factory = $self->{ _FACTORY }
196 0 ▶ || return $self->error("no factory defined");
Condition0%0/2
$self->{'_FACTORY'} || (return $self->error('no factory defined'))
l!l
00
MC/DC0%0/1
$self->{'_FACTORY'} || (return $self->error('no factory defined'))
$self->{'_FACTORY'}
Truth table0%0/2
A
A= $self->{'_FACTORY'}
Aresult
11
00
197  
198 0 ▶ return $factory->create( schema_handler => $args )
Condition0%0/3
$factory->create('schema_handler', $args) || $self->error($factory->error)
l!l&&r!l&&!r
000
MC/DC0%0/2
$factory->create('schema_handler', $args) || $self->error($factory->error)
$factory->create('schema_handler', $args) $self->error($factory->error)
Truth table0%0/3
A || B
A= $factory->create('schema_handler', $args)B= $self->error($factory->error)
ABresult
1X1
011
000
199 || $self->error($factory->error());
200 }
201  
202  
203 0 ▶sub present {
Subroutine present: not called CC=1 SCAR=6.9
Pod undocumented
204 0 my ($self, $view) = @_;
205 0 $view->view( schema => $self );
206 }
207  
208 28 1;
209  
210 __END__
« lib/XML/Schema/Handler/Complex.pm ↑ Summary lib/XML/Schema/Instance.pm »