lib/XML/Schema/Base.pm

filter: Statementstmt 63.1% 149 / 236 Branchbran 46.6% 56 / 120 Conditioncond 50.9% 28 / 55 MC/DCmcdc 23.5% 8 / 34 Subroutinesub 71.4% 20 / 28 Podpod 40.0% 4 / 10 totaltotal 54.8% 265 / 483 CC 82 SCAR 36.5
CC
82
Cov
57%
_inspect
210.0
TRACE
29.7
_baseargs
27.1
CRAP 38.3
« lib/XML/Schema/Instance.pm ↑ Summary blib/lib/XML/Schema/Type/Provider.pm »
1 #============================================================= -*-perl-*-
2 #
3 # XML::Schema::Base
4 #
5 # DESCRIPTION
6 # Base class for various XML::Schema::* module implementing common
7 # functionality such as error reporting, etc.
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: Base.pm,v 1.2 2001/12/20 13:26:27 abw Exp $
21 #
22 #========================================================================
23  
24 package XML::Schema::Base;
25  
26 28 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 28 ▶use vars qw( $VERSION $DEBUG $ERROR $ECLASS $ETYPE $SNIPPET
Subroutine BEGIN: called CC=1 SCAR=0.0
28 28 $TRACE_LEVEL $INSPECT_LEVEL );
29 28 ▶use XML::Schema::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 28 $VERSION = sprintf("%d.%02d", q$Revision: 1.2 $ =~ /(\d+)\.(\d+)/);
32 28 ▶$DEBUG = 0 unless defined $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $XML::Schema::Base::DEBUG 28 0 28
33 28 $ERROR = '';
34 28 $ECLASS = 'XML::Schema::Exception';
35 28 $ETYPE = 'undef';
36 28 $SNIPPET = 16;
37 28 ▶$TRACE_LEVEL = 4 unless defined $TRACE_LEVEL;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $XML::Schema::Base::TRACE_LEVEL 28 0 28
38 28 ▶$INSPECT_LEVEL = 3 unless defined $INSPECT_LEVEL;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $XML::Schema::Base::INSPECT_LEVEL 28 0 28
39  
40  
41  
42 #------------------------------------------------------------------------
43 # new(@config)
44 # new(\%config)
45 #
46 # General purpose constructor method for instantiating derived class
47 # objects. Looks for the @BASEARGS package variable in the derived
48 # class package which may define mandatory positional parameters
49 # expected by the constructor. Values for these @BASEARGS are shifted
50 # off the argument list leaving any remaining configuration items as a
51 # hash reference or as a list of key => value pairs which are folded
52 # into a hash reference. Creates a new blessed hash seeded with these
53 # various values and then calls the init() method to perform any
54 # object initialisation. On success the new blessed object is
55 # returned. On error undef is returned and the $ERROR package
56 # variable is set in the _derived_ class' package.
57 #------------------------------------------------------------------------
58  
59 840 ▶sub new {
Subroutine new: called CC=4 SCAR=13.9
Pod documented
60 840 my $class = shift;
61 840 ▶ my $config = UNIVERSAL::isa($_[0], 'HASH') ? shift : { @_ };
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::isa($_[0], 'HASH') ? : 510 330 840
62  
63 840 $class->error('');
64  
65 my $self = bless {
66 _ERROR => '',
67 _FACTORY => $config->{ factory } || $config->{ FACTORY },
68 840 ▶ }, $class;
Condition100%3/3
$config->{'factory'} || $config->{'FACTORY'}
l!l&&r!l&&!r
11838
MC/DC100%2/2
$config->{'factory'} || $config->{'FACTORY'}
$config->{'factory'} $config->{'FACTORY'}
Truth table100%3/3
A || B
A= $config->{'factory'}B= $config->{'FACTORY'}
ABresult
1X1
011
000
69  
70 840 ▶ return $self->init($config)
Condition66%2/3
$self->init($config) || $class->error($self->error)
l!l&&r!l&&!r
790050
MC/DC50%1/2
$self->init($config) || $class->error($self->error)
$self->init($config) $class->error($self->error)
Truth table66%2/3
A || B
A= $self->init($config)B= $class->error($self->error)
ABresult
1X1
011
000
71 || $class->error($self->error());
72 }
73  
74  
75 #------------------------------------------------------------------------
76 # init(\%config)
77 #
78 # Initialisation method called by the new() constructor and passing a
79 # reference to a hash array containing any configuration items specified
80 # as constructor arguments. Should return $self on success or undef on
81 # error, via a call to the error() method to set the error message.
82 #------------------------------------------------------------------------
83  
84 6 ▶sub init {
Subroutine init: called CC=1 SCAR=0.0
Pod documented
85 6 my ($self, $config) = @_;
86 6 return $self;
87 }
88  
89  
90 #------------------------------------------------------------------------
91 # init_mandopt(\%config)
92 #
93 # Optional initialisation method which probes the caller's package
94 # for @MANDATORY and @OPTIONAL arguments and does the right thing
95 # to extract them from $config into $self.
96 #------------------------------------------------------------------------
97  
98 117 ▶sub init_mandopt {
Subroutine init_mandopt: called CC=4 SCAR=14.0
Pod undocumented
99 117 my ($self, $config) = @_;
100  
101 my ($mand, $option)
102 117 = @{ $self->_baseargs( qw( @MANDATORY %OPTIONAL ) ) };
103  
104 117 ▶ $self->_mandatory($mand, $config)
Branch: 1 branch
BranchTrueFalseTotal
if @$mand 55 62 117
Condition80%4/5
@$mand && ($self->_mandatory($mand, $config) || (return))
!ll
62550
$self->_mandatory($mand, $config) or return
l!l
532
MC/DC0%0/2
@$mand && ($self->_mandatory($mand, $config) || (return))
@$mand $self->_mandatory($mand, $config)
Truth table66%2/3
A && B
A= @$mandB= $self->_mandatory($mand, $config)
ABresult
0X0
100
111
105 || return if @$mand;
106  
107 115 ▶ $self->_optional($option, $config)
Branch: 1 branch
BranchTrueFalseTotal
$self->_optional($option, $config) or return 115 0 115
108 || return;
109  
110 115 return $self;
111 }
112  
113  
114 #------------------------------------------------------------------------
115 # error()
116 # error($msg, ...)
117 #
118 # General purpose method error for getting/setting object or class
119 # error value. When called as a class method it operates on the
120 # package variable $ERROR. When called as an object method it
121 # operates on the internal error item $self->{ _ERROR }. When called
122 # without any arguments it returns the current value for the variable.
123 # When called with one or more arguments (multiple arguments are
124 # concatenated) it updates the error variable and then returns undef.
125 #------------------------------------------------------------------------
126  
127 1826 ▶sub error {
Subroutine error: called CC=4 SCAR=13.9
Pod documented
128 1826 my $self = shift;
129 1826 my $errvar;
130  
131 {
132 28 ▶ no strict qw( refs );
Subroutine BEGIN: called CC=1 SCAR=0.0
133 1826 ▶ $errvar = ref $self ? \$self->{ _ERROR } : \${"$self\::ERROR"};
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 717 1109 1826
134 }
135 1826 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 1231 595 1826
136 # don't join if first arg is an object (may force stringification)
137 1231 ▶ $$errvar = ref($_[0]) ? shift : join('', @_);
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 1231 1231
138 1231 return undef;
139 }
140 else {
141 595 return $$errvar;
142 }
143 }
144  
145  
146 #------------------------------------------------------------------------
147 # error_value($item, $got, @values)
148 #
149 # Error reporting method which generates an error message of the form
150 # "item must be 'this', 'that' or 'the_other' (not: 'value_got')"
151 # and passes it to the error() method.
152 #------------------------------------------------------------------------
153  
154 4 ▶sub error_value {
Subroutine error_value: called CC=1 SCAR=0.0
Pod undocumented
155 4 my ($self, $item, $got, @values) = @_;
156 4 my $last = pop @values;
157 4 my $vals = join(', ', map { "'$_'" } @values);
158 4 $self->error("$item must be $vals or '$last' (not '$got')");
159 }
160  
161  
162 #------------------------------------------------------------------------
163 # throw($info)
164 # throw($type, $info)
165 #
166 # Throws an error as an XML::Schema::Exception object of type $type
167 # with an informational message as supplied by $info. If the type
168 # is unspecified (i.e. 1 argument, not 2) then the value defined in
169 # the object's $ETYPE package variable is used or if undefined, the
170 # value of the $ETYPE in this base class package.
171 #------------------------------------------------------------------------
172  
173 4 ▶sub throw {
Subroutine throw: called CC=5 SCAR=16.1
Pod documented
174 4 my ($self, $error, $info) = @_;
175 4 my $factory = $self->factory();
176 4 local $" = ', ';
177  
178 # die! die! die!
179 4 ▶ if ($factory->isa( exception => $error )) {
Branch: 2 branches
BranchTrueFalseTotal
if ($factory->isa('exception', $error)) { } 1 3 4
elsif (defined $info) { } 1 2 3
180 # $self->DEBUG("throwing existing exception $error\n");
181 1 die $error;
182 }
183 elsif (defined $info) {
184 1 $error = $factory->create( exception => $error, $info );
185 # $self->DEBUG("throwing created exception $error\n");
186 1 die $error;
187 }
188 else {
189 28 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
190 2 ▶ $error ||= '';
Condition50%1/2
$error ||= ""
l!l
20
MC/DC0%0/1
$error ||= ""
$error
Truth table50%1/2
A
A= $error
Aresult
11
00
191 # look for $ETYPE in derived class
192 2 my $class = ref $self;
193 2 ▶ my $ename = ${"$class\::ETYPE"} || $ETYPE;
Condition66%2/3
${"${class}::ETYPE";} || $XML::Schema::Base::ETYPE
l!l&&r!l&&!r
110
MC/DC0%0/2
${"${class}::ETYPE";} || $XML::Schema::Base::ETYPE
${"${class}::ETYPE";} $XML::Schema::Base::ETYPE
Truth table66%2/3
A || B
A= ${"${class}::ETYPE";}B= $XML::Schema::Base::ETYPE
ABresult
1X1
011
000
194 2 $error = $factory->create( exception => $ename, $error );
195 # $self->DEBUG("throwing created '$ename' exception $error\n");
196 2 die $error;
197 }
198  
199 # not reached
200 }
201  
202  
203 #------------------------------------------------------------------------
204 # factory()
205 # factory($new_factory)
206 #
207 # When called without arguments, returns the factory referenced by the
208 # internal _FACTORY item or the value specified in the
209 # $XML::Schema::FACTORY package variable ('XML::Schema::Factory' by
210 # default). When called as an object method with an argument, the
211 # internal _FACTORY item is updated to store the reference to the new
212 # factory passed as the argument.
213 #------------------------------------------------------------------------
214  
215 99 ▶sub factory {
Subroutine factory: called CC=6 SCAR=18.7
Pod undocumented
216 99 my $self = shift;
217 99 my $factory;
218  
219 return ($self->{ _FACTORY } = shift)
220 99 ▶ if @_ && ref $self;
Branch: 1 branch
BranchTrueFalseTotal
if @_ and ref $self 1 98 99
Condition66%2/3
@_ and ref $self
!ll&&!rl&&r
9801
MC/DC50%1/2
@_ and ref $self
@_ ref $self
Truth table66%2/3
A and B
A= @_B= ref $self
ABresult
0X0
100
111
221  
222 98 ▶ $factory = $self->{ _FACTORY } if ref $self;
Branch: 1 branch
BranchTrueFalseTotal
if ref $self 98 0 98
223 98 ▶ $factory ||= do {
Condition66%2/3
$factory ||= do { require XML::Schema; $XML::Schema::FACTORY }
l!l&&r!l&&!r
9170
MC/DC0%0/2
$factory ||= do { require XML::Schema; $XML::Schema::FACTORY }
$factory do { require XML::Schema; $XML::Schema::FACTORY }
Truth table66%2/3
A ||= B
A= $factoryB= do { require XML::Schema; $XML::Schema::FACTORY }
ABresult
1X1
011
000
224 7 require XML::Schema;
225 7 $XML::Schema::FACTORY;
226 };
227 98 ▶ return $factory || $self->error('no factory defined');
Condition33%1/3
$factory || $self->error('no factory defined')
l!l&&r!l&&!r
9800
MC/DC0%0/2
$factory || $self->error('no factory defined')
$factory $self->error('no factory defined')
Truth table33%1/3
A || B
A= $factoryB= $self->error('no factory defined')
ABresult
1X1
011
000
228 }
229  
230  
231  
232 #========================================================================
233 # private/protected methods
234 #========================================================================
235  
236 #------------------------------------------------------------------------
237 # _baseargs(@names)
238 # _baseargs(\%options, @names)
239 #
240 # This method walks up the inheritance tree collecting various package
241 # variables along the way and collating them for the derived object
242 # class. Variable names are passed as arguments, e.g. qw( @MANDATORY,
243 # %OPTIONAL ). A list reference is returned containing references to
244 # lists of all the items found.
245 #------------------------------------------------------------------------
246  
247 1587 ▶sub _baseargs {
Subroutine _baseargs: called CC=23 SCAR=33.0
248 1587 my ($class, @names) = @_;
249 1587 my ($cache, @pending, %examined, $isa, $base);
250 1587 my ($name, $type, $arg);
251 1587 my $args = { };
252 1587 ▶ my $options = ref $names[0] eq 'HASH' ? shift(@names) : { };
Branch: 1 branch
BranchTrueFalseTotal
ref $names[0] eq 'HASH' ? : 329 1258 1587
253  
254 1587 ▶ if ($DEBUG) {
Branch: 1 branch
BranchTrueFalseTotal
if ($XML::Schema::Base::DEBUG) 0 1587 1587
255 0 $class->DEBUG("_baseargs options: ",
256 $class->_inspect($options), "\n");
257 }
258  
259 1587 ▶ $class = ref $class || $class;
Condition66%2/3
ref $class || $class
l!l&&r!l&&!r
157890
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table66%2/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
260 1587 push(@pending, $class);
261  
262 28 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
263 1587 local $" = ', ';
264  
265 # looked for cached version
266 # $cache = \@{"$class\::BASEARGS"};
267 # return $cache if @$cache;
268  
269 1587 ▶ while (@pending) {
Branch: 1 branch
BranchTrueFalseTotal
if (@pending) 8642 1587 10229
270 8642 $base = shift @pending;
271 8642 ▶ next if $examined{ $base };
Branch: 1 branch
BranchTrueFalseTotal
if $examined{$base} 1334 7308 8642
272 7308 $examined{ $base } = 1;
273  
274 7308 foreach (@names) {
275 11570 $name = $_; # copy to avoid aliasing problems
276 11570 ($type, $name) = ($name =~ /([@%])(\w+)/);
277 11570 ▶ next if $options->{ skip }->{ $name };
Branch: 1 branch
BranchTrueFalseTotal
if $options->{"skip"}{$name} 1007 10563 11570
278 10563 $arg = \@{"$base\::$name"};
279  
280 10563 ▶ if ($type eq '@') {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq '@') { } 7427 3136 10563
elsif ($type eq '%') { } 3136 0 3136
281 7427 unshift(@{ $args->{ $name } }, @$arg);
282 7427 ▶ $class->DEBUG("$type$base\::$name : [ @$arg ]\n")
Branch: 1 branch
BranchTrueFalseTotal
if $XML::Schema::Base::DEBUG 0 7427 7427
283 if $DEBUG;
284 # stop if we only wanted (and got) first match
285 7427 ▶ if ($options->{ first } && @$arg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options->{"first"} and @$arg) 329 7098 7427
Condition100%3/3
$options->{"first"} and @$arg
!ll&&!rl&&r
6784314329
MC/DC100%2/2
$options->{"first"} and @$arg
$options->{"first"} @$arg
Truth table100%3/3
A and B
A= $options->{"first"}B= @$arg
ABresult
0X0
100
111
286 329 ▶ $class->DEBUG("found first item for $name: [ @$arg ]\n")
Branch: 1 branch
BranchTrueFalseTotal
if $XML::Schema::Base::DEBUG 0 329 329
287 if $DEBUG;
288 329 $options->{ skip }->{ $name } = 1;
289 }
290 }
291 elsif ($type eq '%') {
292 3136 ▶ if (@$arg) { $arg = { map { ($_ => '') } @$arg } }
Branch: 1 branch
BranchTrueFalseTotal
if (@$arg) { } 1421 1715 3136
293 1715 else { $arg = \%{"$base\::$name"}; }
294 3136 ▶ $args->{ $name } = { %$arg, %{ $args->{ $name } || { } } };
Condition100%2/2
$args->{$name} || {}
l!l
2401735
MC/DC100%1/1
$args->{$name} || {}
$args->{$name}
Truth table100%2/2
A
A= $args->{$name}
Aresult
11
00
295 3136 ▶ $class->DEBUG("$type$class\::$name : { %$arg }\n")
Branch: 1 branch
BranchTrueFalseTotal
if $XML::Schema::Base::DEBUG 0 3136 3136
296 if $DEBUG;
297 0 ▶ if ($options->{ first } && %{ $args->{ $name } }) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options->{"first"} and %{$args->{$name};}) 0 3136 3136
Condition33%1/3
$options->{"first"} and %{$args->{$name};}
!ll&&!rl&&r
313600
MC/DC0%0/2
$options->{"first"} and %{$args->{$name};}
$options->{"first"} %{$args->{$name};}
Truth table33%1/3
A and B
A= $options->{"first"}B= %{$args->{$name};}
ABresult
0X0
100
111
298 0 ▶ $class->DEBUG("found first item for $name: [ @$arg ]\n")
Branch: 1 branch
BranchTrueFalseTotal
if $XML::Schema::Base::DEBUG 0 0 0
299 if $DEBUG;
300 0 $options->{ skip }->{ $name } = 1;
301 }
302 }
303 }
304  
305 # note need to reverse @isa to ensure multiple inheritance (gasp!)
306 # of the form @ISA = qw( foo bar ) checks packages in the right
307 # order (bar, then foo) for unshifting onto the front of the
308 # @baseargs list
309 7308 $isa = \@{"$base\::ISA"};
310 7308 ▶ push(@pending, map { $examined{ $_ } ? () : $_ } reverse @$isa);
Branch: 1 branch
BranchTrueFalseTotal
$examined{$_} ? : 0 7055 7055
311  
312 7308 ▶ $class->DEBUG("$base isa @$isa\n") if $DEBUG && @$isa;
Branch: 1 branch
BranchTrueFalseTotal
if $XML::Schema::Base::DEBUG and @$isa 0 7308 7308
Condition33%1/3
$XML::Schema::Base::DEBUG and @$isa
!ll&&!rl&&r
730800
MC/DC0%0/2
$XML::Schema::Base::DEBUG and @$isa
$XML::Schema::Base::DEBUG @$isa
Truth table33%1/3
A and B
A= $XML::Schema::Base::DEBUGB= @$isa
ABresult
0X0
100
111
313 }
314  
315 # cache arguments for future invocations
316 # @$cache = ( @$args{ map { (/(\w+)/) } @names } );
317 1587 $cache = [ @$args{ map { (/(\w+)/) } @names } ];
318 1587 return $cache;
319 }
320  
321  
322 #------------------------------------------------------------------------
323 # _arguments(\@names, \@args)
324 #
325 # Copies mandatory positional arguments, specified in $names list, from
326 # $args list and sets them as internal data items. Returns reference to
327 # $self on success or undef on error.
328 #------------------------------------------------------------------------
329  
330 9 ▶sub _arguments {
Subroutine _arguments: called CC=4 SCAR=13.9
331 9 my ($self, $names, $args) = @_;
332
333 # shift off all mandatory positional arguments
334 9 foreach my $name (@$names) {
335 29 ▶ return $self->error(ref($self) . ": $name not specified")
Branch: 1 branch
BranchTrueFalseTotal
unless @$args and defined $args->[0] 7 22 29
Condition66%2/3
@$args and defined $args->[0]
!ll&&!rl&&r
7022
MC/DC50%1/2
@$args and defined $args->[0]
@$args defined $args->[0]
Truth table66%2/3
A and B
A= @$argsB= defined $args->[0]
ABresult
0X0
100
111
336 unless @$args && defined $args->[0];
337 22 $self->{ $name } = shift @$args;
338 }
339 2 return $self;
340 }
341  
342  
343 #------------------------------------------------------------------------
344 # _mandatory(\@names, \%config)
345 #
346 # Copies mandatory fields, specified in $names list, from $config
347 # hash ref to $self. Returns reference to $self on success or raises
348 # error and returns undef if any field is undefined.
349 #------------------------------------------------------------------------
350  
351 493 ▶sub _mandatory {
Subroutine _mandatory: called CC=3 SCAR=11.0
352 493 my ($self, $names, $config) = @_;
353  
354 493 foreach my $name (@$names) {
355 return $self->error(ref($self) . ": $name not specified")
356 625 ▶ unless defined $config->{ $name };
Branch: 1 branch
BranchTrueFalseTotal
unless defined $config->{$name} 21 604 625
357 604 $self->{ $name } = $config->{ $name };
358 }
359 472 return $self;
360 }
361  
362  
363 #------------------------------------------------------------------------
364 # _optional(\@names, \%config)
365 # _optional(\%names, \%config)
366 #
367 # Copies optional fields, specified in $names, from $config hash ref
368 # to $self. If $names is a hash reference then the corresponding value
369 # for any field will be used as a default if otherwise undefined in
370 # $config. Returns reference to $self.
371 #------------------------------------------------------------------------
372  
373 723 ▶sub _optional {
Subroutine _optional: called CC=5 SCAR=16.1
374 723 my ($self, $names, $config) = @_;
375 723 my ($key, $val);
376  
377 723 ▶ $names = { map { ($_ => '') } @$names }
Branch: 1 branch
BranchTrueFalseTotal
if ref $names eq "ARRAY" 4 719 723
378 if ref $names eq 'ARRAY';
379  
380 723 ▶ while (($key, $val) = each %$names) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$names) 2661 723 3384
381 $self->{ $key } = defined $config->{ $key }
382 2661 ▶ ? $config->{ $key }
Branch: 2 branches
BranchTrueFalseTotal
defined $config->{$key} ? : 342 2319 2661
ref $val eq 'CODE' ? : 4 2315 2319
383 : (ref $val eq 'CODE' ? &$val() : $val);
384 }
385  
386 723 return $self;
387 }
388  
389  
390  
391  
392 #========================================================================
393 # debugging methods
394 #========================================================================
395  
396 #------------------------------------------------------------------------
397 # DEBUG(@args)
398 #
399 # Prints all arguments to STDERR.
400 #------------------------------------------------------------------------
401  
402 0 ▶sub DEBUG {
Subroutine DEBUG: not called CC=1 SCAR=6.9
Pod undocumented
403 0 my $self = shift;
404 0 print STDERR @_;
405 }
406  
407  
408 #------------------------------------------------------------------------
409 # ID
410 #
411 # Returns a string to identify an object. May be redefined in subclasses
412 # to return more meaningful identifier.
413 #------------------------------------------------------------------------
414  
415 0 ▶sub ID {
Subroutine ID: not called CC=3 SCAR=20.0
Pod undocumented
416 0 my $self = shift;
417 0 ▶ my $class = ref $self || $self;
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
418 28 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
419 0 ▶ my $etype = ${"$class\::ETYPE"} || $self;
Condition0%0/3
${"${class}::ETYPE";} || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
${"${class}::ETYPE";} || $self
${"${class}::ETYPE";} $self
Truth table0%0/3
A || B
A= ${"${class}::ETYPE";}B= $self
ABresult
1X1
011
000
420 0 return $etype;
421 }
422  
423  
424 #------------------------------------------------------------------------
425 # TRACE(@args)
426 #
427 # Generates a trace message showing the object and method from where the
428 # TRACE method was called, along with any additional arguments passed.
429 # Non-reference arguments are added to the trace message intact, references
430 # are first stringified via the _dump_ref() method. The generated message
431 # is then sent to the DEBUG method.
432 #
433 # The internal _DEBUG item (or package variable $DEBUG if not
434 # defined) is used to determine the verbosity of the generated message.
435 #
436 # 1 print argument only
437 # 2 prefix arguments with object ID
438 # 3 as 2 but also with calling method name
439 # 4 as 3 but also with package, file and line info
440 #------------------------------------------------------------------------
441  
442 2 ▶sub TRACE {
Subroutine TRACE: called CC=8 SCAR=33.9
Pod undocumented
443 2 my $self = shift;
444 2 my ($pkg, $file, $line, $sub, $args,
445 $wantarray, $evaltext, $isreq, $hints, $bitmask) = caller(1);
446  
447 2 my $level;
448 2 ▶ if (exists $self->{ _DEBUG }) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'_DEBUG'}) { } 0 2 2
449 0 $level = $self->{ _DEBUG };
450 }
451 else
452 {
453 28 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
454 2 my $class = ref $self;
455 2 $level = ${"$class\::DEBUG"};
456 }
457 2 ▶ return unless $level;
Branch: 1 branch
BranchTrueFalseTotal
unless $level 2 0 2
458  
459 0 my $output = '';
460  
461 0 ▶ if ($level > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level > 1) 0 0 0
462 0 $output .= $self->ID;
463  
464 0 ▶ if ($level > 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level > 2) { } 0 0 0
465 0 $sub =~ s/.*::(\w+)$/$1/;
466 0 $output .= "->$sub()";
467  
468 0 ▶ if ($level > 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level > 3) { } 0 0 0
469 0 my ($ownpkg, $ownfile, $ownline) = caller();
470 0 $output .= "\n# at $ownfile line $ownline";
471 0 $output .= "\n# called from $file line $line\n";
472 }
473 else {
474 0 $output .= ' : ';
475 }
476 }
477 else {
478 0 $output .= ' : ';
479 }
480 }
481  
482 0 foreach my $arg (@_) {
483 0 ▶ $arg = '<undef>' unless defined $arg;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $arg 0 0 0
484 0 $output .= $self->_inspect($arg);
485 }
486 0 chomp($output);
487 0 $output .= "\n";
488  
489 0 $output =~ s/\n(.)/\n | $1/gs;
490  
491 0 $self->DEBUG('T| ' . $output);
492 }
493  
494  
495 #------------------------------------------------------------------------
496 # _inspect($something, $level)
497 #
498 # Attempts to Do The Right Thing to print a meaningful representation of
499 # the $something passes as an argument. Will recurse into $something's
500 # structure while $level is less that $INSPECT_LEVEL.
501 #------------------------------------------------------------------------
502  
503 0 ▶sub _inspect {
Subroutine _inspect: not called CC=14 SCAR=53.5
504 0 my ($self, $item, $level) = @_;
505 0 ▶ $level ||= 0;
Condition0%0/2
$level ||= 0
l!l
00
MC/DC0%0/1
$level ||= 0
$level
Truth table0%0/2
A
A= $level
Aresult
11
00
506 0 my $output = '';
507 0 my $pad = ' ';
508 0 ▶ my $pad1 = $level ? ($pad x $level) : '';
Branch: 1 branch
BranchTrueFalseTotal
$level ? : 0 0 0
509 0 my $pad2 = $pad x ++$level;
510  
511 0 ▶ $item = '<undef>' unless defined $item;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $item 0 0 0
512 0 ▶ return $item if $level > $INSPECT_LEVEL;
Branch: 1 branch
BranchTrueFalseTotal
if $level > $XML::Schema::Base::INSPECT_LEVEL 0 0 0
513 0 ▶ return "''" unless length $item;
Branch: 1 branch
BranchTrueFalseTotal
unless length $item 0 0 0
514 0 ▶ return $item unless ref $item;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $item 0 0 0
515  
516 0 ▶ if (UNIVERSAL::isa($item, 'HASH')) {
Branch: 3 branches
BranchTrueFalseTotal
if (UNIVERSAL::isa($item, 'HASH')) { } 0 0 0
elsif (UNIVERSAL::isa($item, 'ARRAY')) { } 0 0 0
elsif (UNIVERSAL::isa($item, 'SCALAR')) { } 0 0 0
517 0 ▶ if (%$item) {
Branch: 1 branch
BranchTrueFalseTotal
if (%$item) { } 0 0 0
518 0 $output .= "$item : {\n";
519 0 ▶ while (my ($key, $value) = each %$item) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$item) 0 0 0
520 0 $output .= sprintf("$pad2%-8s => %s,\n", $key, $self->_inspect($value, $level));
521 }
522 0 $output .= "$pad1}";
523 }
524 else {
525 0 $output .= "$item : { }";
526 }
527 }
528 elsif (UNIVERSAL::isa($item, 'ARRAY')) {
529 0 ▶ if (@$item) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$item) { } 0 0 0
530 0 $output .= "$item : [\n";
531 0 foreach my $i (@$item) {
532 0 $output .= $pad2 . $self->_inspect($i, $level) . ",\n";
533 }
534 0 $output .= "$pad1]";
535 }
536 else {
537 0 $output .= "$item : [ ]";
538 }
539 }
540 elsif (UNIVERSAL::isa($item, 'SCALAR')) {
541 0 $output .= $item . ' : \\"' . $self->_inspect($$item) . '"';
542 }
543 else {
544 0 $output .= $item;
545 }
546  
547 # $output =~ s/^/$pad/mg;
548 0 return $output;
549 }
550  
551  
552 #------------------------------------------------------------------------
553 # _text_snippet($text, $length)
554 #
555 # Return $text truncated to at most $length characters or $SNIPPET if
556 # $length is undefined.
557 #------------------------------------------------------------------------
558  
559 0 ▶sub _text_snippet {
Subroutine _text_snippet: not called CC=3 SCAR=24.8
560 0 my ($self, $text, $length) = @_;
561 0 ▶ $length ||= $SNIPPET;
Condition0%0/3
$length ||= $XML::Schema::Base::SNIPPET
l!l&&r!l&&!r
000
MC/DC0%0/2
$length ||= $XML::Schema::Base::SNIPPET
$length $XML::Schema::Base::SNIPPET
Truth table0%0/3
A ||= B
A= $lengthB= $XML::Schema::Base::SNIPPET
ABresult
1X1
011
000
562 0 my $snippet = substr($text, 0, $length);
563 0 ▶ $snippet .= '...' if length $text > $length;
Branch: 1 branch
BranchTrueFalseTotal
if length $text > $length 0 0 0
564 0 $snippet =~ s/\n/\\n/g;
565 0 return $snippet;
566 }
567  
568  
569 #------------------------------------------------------------------------
570 # old stuff, no longer used (I think)
571 #------------------------------------------------------------------------
572  
573 0 ▶sub _old_dump {
Subroutine _old_dump: not called CC=3 SCAR=24.8
574 0 my $self = shift;
575 0 my $output = "$self:\n";
576 0 ▶ while (my ($key, $value) = each %$self) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$self) 0 0 0
577 0 ▶ $value = '<undef>' unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
578 0 $output .= sprintf(" %-12s => %s\n", $key, $value);
579 }
580 0 return $output;
581 }
582  
583 0 ▶sub _old_dump_ref {
Subroutine _old_dump_ref: not called CC=3 SCAR=24.8
584 0 my ($self, $ref) = @_;
585 0 ▶ if (UNIVERSAL::isa($ref, 'HASH')) {
Branch: 2 branches
BranchTrueFalseTotal
if (UNIVERSAL::isa($ref, 'HASH')) { } 0 0 0
elsif (UNIVERSAL::isa($ref, 'LIST')) { } 0 0 0
586 0 return $self->_old_dump_hash($ref);
587 }
588 elsif (UNIVERSAL::isa($ref, 'LIST')) {
589 0 return $self->_old_dump_list($ref);
590 }
591 else {
592 0 return $ref;
593 }
594 }
595  
596 0 ▶sub _old_dump_hash {
Subroutine _old_dump_hash: not called CC=3 SCAR=24.8
597 0 my $self = shift;
598 0 my $hash = shift;
599 0 ▶ my $shallow = shift || 0;
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
600 return '{ ' . join(', ', map {
601 0 my $val = $hash->{ $_};
602 0 ▶ $val = '<undef>' unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 0 0
603 # $val = $self->_old_dump_ref($val) if ref $val && ! $shallow;
604 0 "$_ => $val"
605 } keys %$hash) . ' }';
606 }
607  
608 0 ▶sub _old_dump_list {
Subroutine _old_dump_list: not called CC=3 SCAR=24.8
609 0 my ($self, $list) = @_;
610 return '[ ' . join(', ', map {
611 0 my $val = $_;
612 0 ▶ $val = '<undef>' unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 0 0
613 0 ▶ $val = $self->_old_dump_ref($val) if ref $val;
Branch: 1 branch
BranchTrueFalseTotal
if ref $val 0 0 0
614 0 $val;
615 } @$list) . ' ]';
616 }
617  
618  
619 28 1;
620  
621 __END__
« lib/XML/Schema/Instance.pm ↑ Summary blib/lib/XML/Schema/Type/Provider.pm »