lib/XML/Schema/Handler/Simple.pm

filter: Statementstmt 89.1% 41 / 46 Branchbran 55.0% 11 / 20 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 80.0% 8 / 10 Podpod 0.0% 0 / 6 totaltotal 72.4% 63 / 87 CC 11 SCAR 12.2
CC
11
Cov
78%
end_child
6.0
end_element
5.1
start_element
4.0
CRAP 3.4
« lib/XML/Schema/Type/Builtin.pm ↑ Summary lib/XML/Schema/Test.pm »
1 #============================================================= -*-perl-*-
2 #
3 # XML::Schema::Handler::Simple.pm
4 #
5 # DESCRIPTION
6 # Module implementing a parser handler for simple content.
7 #
8 # AUTHOR
9 # Andy Wardley <abw@kfs.org>
10 #
11 # COPYRIGHT
12 # Copyright (C) 2001 Canon Research Centre Europe Ltd.
13 # All Rights Reserved.
14 #
15 # This module is free software; you can redistribute it and/or
16 # modify it under the same terms as Perl itself.
17 #
18 # REVISION
19 # $Id: Simple.pm,v 1.1.1.1 2001/08/29 14:30:17 abw Exp $
20 #
21 #========================================================================
22  
23 package XML::Schema::Handler::Simple;
24  
25 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 ▶use XML::Schema::Handler;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 ▶use base qw( XML::Schema::Handler );
Subroutine BEGIN: called CC=1 SCAR=0.0
28 1 ▶use vars qw( $VERSION $DEBUG $ERROR @SCHEDULES @MANDATORY );
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 1 $VERSION = sprintf("%d.%02d", q$Revision: 1.1.1.1 $ =~ /(\d+)\.(\d+)/);
31 1 ▶$DEBUG = 0 unless defined $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $XML::Schema::Handler::Simple::DEBUG 1 0 1
32 1 $ERROR = '';
33  
34 1 @MANDATORY = qw( type );
35 1 @SCHEDULES = qw( instance );
36  
37  
38 #------------------------------------------------------------------------
39 # start_element($instance, $name, \%attr)
40 #
41 # Called at start tag.
42 #------------------------------------------------------------------------
43  
44 4 ▶sub start_element {
Subroutine start_element: called CC=4 SCAR=14.0
Pod undocumented
45 4 my ($self, $instance, $name, $attr) = @_;
46  
47 4 ▶ $self->TRACE("<$name>") if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $XML::Schema::Handler::Simple::DEBUG 0 4 4
48  
49 4 $self->{ instance } = $instance;
50 4 $self->{ name } = $name;
51 4 $self->{ text } = '';
52  
53 4 ▶ return $self->error("simple element type cannot contain attributes")
Branch: 1 branch
BranchTrueFalseTotal
if $attr and %$attr 1 3 4
Condition66%2/3
$attr and %$attr
!ll&&!rl&&r
301
MC/DC50%1/2
$attr and %$attr
$attr %$attr
Truth table66%2/3
A and B
A= $attrB= %$attr
ABresult
0X0
100
111
54 if $attr && %$attr;
55  
56 3 return 1;
57 }
58  
59  
60 #------------------------------------------------------------------------
61 # start_child($instance, $name, $attr)
62 #
63 # Should not be called: simple content can have no elements.
64 #------------------------------------------------------------------------
65  
66 1 ▶sub start_child {
Subroutine start_child: called CC=2 SCAR=7.1
Pod undocumented
67 1 my ($self, $instance, $name, $attr) = @_;
68 1 ▶ $self->TRACE("<$self->{ name }> <$name>") if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $XML::Schema::Handler::Simple::DEBUG 0 1 1
69 1 $self->error("simple element type cannot contain child elements");
70 }
71  
72  
73 #------------------------------------------------------------------------
74 # end_child($instance, $name, $child)
75 #
76 # Should not be called: as above.
77 #------------------------------------------------------------------------
78  
79 0 ▶sub end_child {
Subroutine end_child: not called CC=2 SCAR=17.9
Pod undocumented
80 0 my ($self, $instance, $name) = @_;
81 0 ▶ $self->TRACE("<$self->{ name }> </$name>") if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $XML::Schema::Handler::Simple::DEBUG 0 0 0
82 0 $self->error("simple element type cannot contain child elements");
83 }
84  
85  
86 #------------------------------------------------------------------------
87 # text($instance, $text)
88 #
89 # Called to store character content.
90 #------------------------------------------------------------------------
91  
92 3 ▶sub text {
Subroutine text: called CC=2 SCAR=7.0
Pod undocumented
93 3 my ($self, $instance, $text) = @_;
94 3 ▶ $self->TRACE("text => ", $self->_text_snippet($text)) if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $XML::Schema::Handler::Simple::DEBUG 0 3 3
95 3 $self->{ text } .= $text;
96 3 return 1;
97 }
98  
99  
100 #------------------------------------------------------------------------
101 # end_element($instance, $name)
102 #
103 # Called at end tag. Instantiates and returns a simple type instance.
104 #------------------------------------------------------------------------
105  
106 3 ▶sub end_element {
Subroutine end_element: called CC=5 SCAR=16.4
Pod undocumented
107 3 my ($self, $instance, $name) = @_;
108  
109 3 ▶ $self->TRACE("instance => $instance, name => $name") if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $XML::Schema::Handler::Simple::DEBUG 0 3 3
110  
111 $self->throw($self->ID . " caught end of '$name' (expected $self->{ name })")
112 3 ▶ unless $name eq $self->{ name };
Branch: 1 branch
BranchTrueFalseTotal
unless $name eq $self->{"name"} 0 3 3
113  
114 3 my $type = $self->{ type };
115  
116 # copy 'text' to 'value' for validation to assert
117 3 $self->{ value } = $self->{ text };
118  
119 3 ▶ $type->validate_instance($self)
Branch: 1 branch
BranchTrueFalseTotal
$type->validate_instance($self) or return $self->error($type->error) 2 1 3
120 || return $self->error($type->error());
121  
122 # copy 'value' to 'result' for scheduled actions to modify
123 2 $self->{ result } = $self->{ value };
124  
125 # activate any type specific actions
126 2 ▶ $type->activate_instance($self)
Branch: 1 branch
BranchTrueFalseTotal
$type->activate_instance($self) or return $self->error($type->error) 2 0 2
127 || return $self->error($type->error());
128  
129 # activate handler specific actions
130 2 $self->activate_instance($self);
131 }
132  
133  
134 0 ▶sub ID {
Subroutine ID: not called CC=1 SCAR=6.9
Pod undocumented
135 0 my $self = shift;
136 0 return "Simple_Handler[$self->{ name }]";
137 }
138  
139 1 1;
140  
141 __END__
« lib/XML/Schema/Type/Builtin.pm ↑ Summary lib/XML/Schema/Test.pm »