line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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 |
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
|
|
|
28
|
|
6424
|
use strict; |
|
28
|
|
|
|
|
49
|
|
|
28
|
|
|
|
|
902
|
|
27
|
28
|
|
|
28
|
|
11986
|
use XML::Schema::Element; |
|
28
|
|
|
|
|
70
|
|
|
28
|
|
|
|
|
947
|
|
28
|
28
|
|
|
28
|
|
13091
|
use XML::Schema::Factory; |
|
28
|
|
|
|
|
73
|
|
|
28
|
|
|
|
|
752
|
|
29
|
28
|
|
|
28
|
|
12996
|
use XML::Schema::Scope; |
|
28
|
|
|
|
|
72
|
|
|
28
|
|
|
|
|
828
|
|
30
|
28
|
|
|
28
|
|
12559
|
use XML::Schema::Type; |
|
28
|
|
|
|
|
92
|
|
|
28
|
|
|
|
|
844
|
|
31
|
28
|
|
|
28
|
|
154
|
use base qw( XML::Schema::Scope ); |
|
28
|
|
|
|
|
52
|
|
|
28
|
|
|
|
|
2013
|
|
32
|
28
|
|
|
28
|
|
140
|
use vars qw( $VERSION $DEBUG $ERROR $ETYPE $FACTORY @OPTIONAL ); |
|
28
|
|
|
|
|
49
|
|
|
28
|
|
|
|
|
25014
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
$VERSION = 0.07; |
35
|
|
|
|
|
|
|
$DEBUG = 0 unless defined $DEBUG; |
36
|
|
|
|
|
|
|
$ERROR = ''; |
37
|
|
|
|
|
|
|
$ETYPE = 'Schema'; |
38
|
|
|
|
|
|
|
$FACTORY = 'XML::Schema::Factory'; |
39
|
|
|
|
|
|
|
@OPTIONAL = qw( element ); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub init { |
43
|
5
|
|
|
5
|
1
|
12
|
my ($self, $config) = @_; |
44
|
|
|
|
|
|
|
|
45
|
5
|
50
|
|
|
|
56
|
$self->SUPER::init($config) |
46
|
|
|
|
|
|
|
|| return; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
my $factory = $self->{ _FACTORY } |
49
|
5
|
|
50
|
|
|
23
|
|| return $self->error("no factory defined"); |
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
|
|
|
|
|
36
|
return $self; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub element { |
63
|
3
|
|
|
3
|
0
|
12
|
my $self = shift; |
64
|
3
|
50
|
|
|
|
8
|
if (@_) { |
65
|
3
|
|
|
|
|
15
|
return ($self->{ element } = $self->SUPER::element(@_)); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
else { |
68
|
|
|
|
|
|
|
return $self->{ element } |
69
|
0
|
|
0
|
|
|
0
|
|| $self->error("no element defined"); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub old_element { |
74
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
75
|
|
|
|
|
|
|
my $factory = $self->{ _FACTORY } |
76
|
0
|
|
0
|
|
|
0
|
|| return $self->error("no factory defined"); |
77
|
|
|
|
|
|
|
|
78
|
0
|
0
|
|
|
|
0
|
$self->TRACE() if $DEBUG; |
79
|
|
|
|
|
|
|
|
80
|
0
|
0
|
|
|
|
0
|
if (@_) { |
81
|
0
|
0
|
|
|
|
0
|
if ($factory->isa( element => $_[0] )) { |
82
|
0
|
0
|
|
|
|
0
|
$self->TRACE("adding element") if $DEBUG; |
83
|
0
|
|
|
|
|
0
|
$self->{ element } = shift; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
else { |
86
|
0
|
0
|
|
|
|
0
|
my $args = UNIVERSAL::isa($_[0], 'HASH') ? shift : { @_ }; |
87
|
0
|
0
|
|
|
|
0
|
$args->{ scope } = $self unless exists $args->{ scope }; |
88
|
0
|
0
|
|
|
|
0
|
$self->TRACE("creating element") if $DEBUG; |
89
|
0
|
|
0
|
|
|
0
|
$self->{ element } = $factory->create( element => $args ) |
90
|
|
|
|
|
|
|
|| return $self->error($factory->error()); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
else { |
94
|
|
|
|
|
|
|
return $self->{ element } |
95
|
0
|
|
0
|
|
|
0
|
|| $self->error("no element defined"); |
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
|
|
|
|
|
|
|
sub content { |
110
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
return ($self->{ content } |
113
|
0
|
0
|
0
|
|
|
0
|
|| $self->error('schema has no content model')) |
114
|
|
|
|
|
|
|
unless @_; |
115
|
|
|
|
|
|
|
|
116
|
0
|
0
|
|
|
|
0
|
$self->TRACE("content: ", @_) if $DEBUG; |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
my $factory = $self->{ _FACTORY } |
119
|
0
|
|
0
|
|
|
0
|
|| return $self->error("no factory defined"); |
120
|
|
|
|
|
|
|
|
121
|
0
|
|
0
|
|
|
0
|
return ($self->{ content } = $factory->create( content => @_ )) |
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
|
|
|
|
|
|
|
sub parser { |
136
|
1
|
|
|
1
|
0
|
8
|
my $self = shift; |
137
|
1
|
50
|
33
|
|
|
18
|
my $args = $_[0] && ref($_[0]) eq 'HASH' ? shift : { @_ }; |
138
|
|
|
|
|
|
|
|
139
|
1
|
|
|
|
|
3
|
$args->{ schema } = $self; |
140
|
|
|
|
|
|
|
|
141
|
1
|
50
|
|
|
|
4
|
$self->TRACE("args => ", $args) if $DEBUG; |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
my $factory = $self->{ _FACTORY } |
144
|
1
|
|
50
|
|
|
3
|
|| return $self->error("no factory defined"); |
145
|
|
|
|
|
|
|
|
146
|
1
|
|
33
|
|
|
5
|
return $factory->create( parser => $args ) |
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
|
|
|
|
|
|
|
sub instance { |
162
|
1
|
|
|
1
|
0
|
6
|
my $self = shift; |
163
|
1
|
50
|
33
|
|
|
6
|
my $args = $_[0] && ref($_[0]) eq 'HASH' ? shift : { @_ }; |
164
|
|
|
|
|
|
|
|
165
|
1
|
|
|
|
|
3
|
$args->{ schema } = $self; |
166
|
|
|
|
|
|
|
|
167
|
1
|
50
|
|
|
|
4
|
$self->TRACE("args => ", $args) if $DEBUG; |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
my $factory = $self->{ _FACTORY } |
170
|
1
|
|
50
|
|
|
4
|
|| return $self->error("no factory defined"); |
171
|
|
|
|
|
|
|
|
172
|
1
|
|
33
|
|
|
10
|
return $factory->create( instance => $args ) |
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
|
|
|
|
|
|
|
sub handler { |
188
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
189
|
0
|
0
|
0
|
|
|
|
my $args = $_[0] && ref($_[0]) eq 'HASH' ? shift : { @_ }; |
190
|
|
|
|
|
|
|
|
191
|
0
|
|
|
|
|
|
$args->{ schema } = $self; |
192
|
|
|
|
|
|
|
|
193
|
0
|
0
|
|
|
|
|
$self->TRACE("args => ", $args) if $DEBUG; |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
my $factory = $self->{ _FACTORY } |
196
|
0
|
|
0
|
|
|
|
|| return $self->error("no factory defined"); |
197
|
|
|
|
|
|
|
|
198
|
0
|
|
0
|
|
|
|
return $factory->create( schema_handler => $args ) |
199
|
|
|
|
|
|
|
|| $self->error($factory->error()); |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
sub present { |
204
|
0
|
|
|
0
|
0
|
|
my ($self, $view) = @_; |
205
|
0
|
|
|
|
|
|
$view->view( schema => $self ); |
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
1; |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
__END__ |