blib/lib/XML/Schema/Handler/Schema.pm untested

filter: Statementstmt 0.0% 0 / 46 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 95 CC 9 SCAR 22.0
CC
9
Cov
0%
end_child
20.0
start_child
12.0
start_element
6.0
CRAP 9.0
1 #============================================================= -*-perl-*-
2 #
3 # XML::Schema::Handler::Schema.pm
4 #
5 # DESCRIPTION
6 # Module implementing a parser handler for the outermost schema 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: Schema.pm,v 1.1.1.1 2001/08/29 14:30:17 abw Exp $
20 #
21 #========================================================================
22  
23 package XML::Schema::Handler::Schema;
24  
25 use strict;
26 use XML::Schema::Handler;
27 use base qw( XML::Schema::Handler );
28 use vars qw( $VERSION $DEBUG $ERROR @MANDATORY @SCHEDULES );
29  
30 $VERSION = sprintf("%d.%02d", q$Revision: 1.1.1.1 $ =~ /(\d+)\.(\d+)/);
31 $DEBUG = 0 unless defined $DEBUG;
32 $ERROR = '';
33  
34 @MANDATORY = qw( schema );
35 @SCHEDULES = qw( start_element start_child end_child end_element text );
36  
37  
38  
39  
40 #------------------------------------------------------------------------
41 # start_element($instance)
42 #
43 # Called at start of schema.
44 #------------------------------------------------------------------------
45  
46 sub start_element {
47 my ($self, $instance) = @_;
48  
49 $self->DEBUG($self->ID, "->start_element($instance)\n")
50 if $DEBUG;
51  
52 $self->{ content } = '';
53  
54 my $schema = $self->{ schema }
55 || return $self->error("no schema defined");
56  
57 my $element = $schema->element()
58 || return $self->error("schema has no element defined");
59  
60 $self->{ element } = $element;
61  
62 return 1;
63 }
64  
65  
66 #------------------------------------------------------------------------
67 # end_element($instance)
68 #
69 # Called at end of schema.
70 #------------------------------------------------------------------------
71  
72 sub end_element {
73 my ($self, $instance) = @_;
74  
75 $self->DEBUG($self->ID, "->end($instance)\n")
76 if $DEBUG;
77  
78 # TODO: validate content
79  
80 return $self->{ content };
81 }
82  
83  
84 #------------------------------------------------------------------------
85 # start_child($instance, $name, $attr)
86 #------------------------------------------------------------------------
87  
88 sub start_child {
89 my ($self, $instance, $name, $attr) = @_;
90 my ($element, $handler);
91  
92 $self->TRACE("instance => $instance, name => $name") if $DEBUG;
93  
94 ($element = $self->{ element })
95 || return $self->error('no schema element defined');
96  
97 ($handler = $element->handler($instance))
98 || return $self->error($element->error());
99  
100 my $child = {
101 name => $name,
102 attributes => $attr,
103 element => $element,
104 handler => $handler,
105 skip => 0, # TODO
106 error => undef,
107 };
108  
109 return $self->{ _SCHEDULE_start_child }
110 ? $self->activate_start_child($child)
111 : $child;
112 }
113  
114  
115 #------------------------------------------------------------------------
116 # end_child()
117 #------------------------------------------------------------------------
118  
119 sub end_child {
120 my ($self, $instance, $name, $child) = @_;
121  
122 $self->TRACE("instance => $instance, name => $name, child => ", $child) if $DEBUG;
123  
124 $self->activate_end_child($child)
125 || return
126 if $self->{ _SCHEDULE_end_child };
127  
128 # use 'result' entry in child or child as it is
129 my $result = exists $child->{ result } ? $child->{ result } : $child;
130  
131 $self->{ content } = $result;
132  
133 return $child;
134 }
135  
136  
137 #------------------------------------------------------------------------
138 # text($instance, $text)
139 #
140 # Called to store (or in this case, reject unless insignificant whitespace)
141 # character content.
142 #------------------------------------------------------------------------
143  
144 sub text {
145 my ($self, $instance, $text) = @_;
146 return $self->error("schema cannot accept text")
147 unless $text =~ /^\s*$/s;
148 return 1
149 }
150  
151  
152 sub ID {
153 my $self = shift;
154 return "Schema_Handler[$self->{ _NAME }]";
155 }
156  
157 1;
158  
159 __END__