| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# Copyrights 2006-2019 by [Mark Overmeer ]. |
|
2
|
|
|
|
|
|
|
# For other contributors see ChangeLog. |
|
3
|
|
|
|
|
|
|
# See the manual pages for details on the licensing terms. |
|
4
|
|
|
|
|
|
|
# Pod stripped from pm file by OODoc 2.02. |
|
5
|
|
|
|
|
|
|
# This code is part of distribution XML-Compile. Meta-POD processed with |
|
6
|
|
|
|
|
|
|
# OODoc into POD and HTML manual-pages. See README.md |
|
7
|
|
|
|
|
|
|
# Copyright Mark Overmeer. Licensed under the same terms as Perl itself. |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package XML::Compile::Translate::Writer; |
|
10
|
47
|
|
|
47
|
|
2028
|
use vars '$VERSION'; |
|
|
47
|
|
|
|
|
97
|
|
|
|
47
|
|
|
|
|
3107
|
|
|
11
|
|
|
|
|
|
|
$VERSION = '1.62'; |
|
12
|
|
|
|
|
|
|
|
|
13
|
47
|
|
|
47
|
|
282
|
use base 'XML::Compile::Translate'; |
|
|
47
|
|
|
|
|
84
|
|
|
|
47
|
|
|
|
|
5929
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
47
|
|
|
47
|
|
307
|
use strict; |
|
|
47
|
|
|
|
|
79
|
|
|
|
47
|
|
|
|
|
1154
|
|
|
16
|
47
|
|
|
47
|
|
268
|
use warnings; |
|
|
47
|
|
|
|
|
126
|
|
|
|
47
|
|
|
|
|
1782
|
|
|
17
|
47
|
|
|
47
|
|
253
|
no warnings 'once', 'recursion'; |
|
|
47
|
|
|
|
|
3819
|
|
|
|
47
|
|
|
|
|
2334
|
|
|
18
|
|
|
|
|
|
|
|
|
19
|
47
|
|
|
47
|
|
287
|
use Log::Report 'xml-compile'; |
|
|
47
|
|
|
|
|
97
|
|
|
|
47
|
|
|
|
|
365
|
|
|
20
|
|
|
|
|
|
|
|
|
21
|
47
|
|
|
47
|
|
16023
|
use List::Util qw/first/; |
|
|
47
|
|
|
|
|
108
|
|
|
|
47
|
|
|
|
|
3771
|
|
|
22
|
47
|
|
|
47
|
|
291
|
use Scalar::Util qw/blessed weaken/; |
|
|
47
|
|
|
|
|
95
|
|
|
|
47
|
|
|
|
|
2761
|
|
|
23
|
47
|
|
|
47
|
|
313
|
use Encode qw/encode/; |
|
|
47
|
|
|
|
|
129
|
|
|
|
47
|
|
|
|
|
2133
|
|
|
24
|
|
|
|
|
|
|
|
|
25
|
47
|
|
|
47
|
|
307
|
use XML::LibXML; |
|
|
47
|
|
|
|
|
91
|
|
|
|
47
|
|
|
|
|
356
|
|
|
26
|
47
|
|
|
|
|
12870
|
use XML::Compile::Util qw/pack_type unpack_type type_of_node SCHEMA2001i |
|
27
|
47
|
|
|
47
|
|
9467
|
SCHEMA2001 odd_elements even_elements/; |
|
|
47
|
|
|
|
|
122
|
|
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# Each action implementation returns a code reference, which will be |
|
31
|
|
|
|
|
|
|
# used to do the run-time work. The principle of closures is used to |
|
32
|
|
|
|
|
|
|
# keep the important information. Be sure that you understand closures |
|
33
|
|
|
|
|
|
|
# before you attempt to change anything. |
|
34
|
|
|
|
|
|
|
# |
|
35
|
|
|
|
|
|
|
# The returned writer subroutines will always be called |
|
36
|
|
|
|
|
|
|
# $writer->($doc, $value) |
|
37
|
|
|
|
|
|
|
|
|
38
|
1157
|
|
|
1157
|
0
|
4898
|
sub actsAs($) { $_[1] eq 'WRITER' } |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub makeTagQualified |
|
41
|
|
|
|
|
|
|
{ # my ($self, $path, $node, $local, $ns) = @_; |
|
42
|
|
|
|
|
|
|
# my $prefix = $self->_registerNSprefix('', $ns, 1); |
|
43
|
|
|
|
|
|
|
# length($prefix) ? "$prefix:$local" : $local; |
|
44
|
132
|
|
|
132
|
0
|
384
|
my $prefix = $_[0]->_registerNSprefix('', $_[4], 1); |
|
45
|
132
|
100
|
|
|
|
431
|
length($prefix) ? "$prefix:$_[3]" : $_[3]; |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub makeTagUnqualified |
|
49
|
|
|
|
|
|
|
{ # my ($self, $path, $node, $local, $ns) = @_; |
|
50
|
|
|
|
|
|
|
# $local; |
|
51
|
823
|
|
|
823
|
0
|
1867
|
$_[3]; |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub _typemapClass($$) |
|
55
|
1
|
|
|
1
|
|
4
|
{ my ($self, $type, $class) = @_; |
|
56
|
|
|
|
|
|
|
|
|
57
|
47
|
|
|
47
|
|
373
|
no strict 'refs'; |
|
|
47
|
|
|
|
|
100
|
|
|
|
47
|
|
|
|
|
418778
|
|
|
58
|
1
|
50
|
|
|
|
2
|
keys %{$class.'::'} |
|
|
1
|
|
|
|
|
10
|
|
|
59
|
|
|
|
|
|
|
or error __x"class {pkg} for typemap {type} is not loaded" |
|
60
|
|
|
|
|
|
|
, pkg => $class, type => $type; |
|
61
|
|
|
|
|
|
|
|
|
62
|
1
|
50
|
|
|
|
9
|
$class->can('toXML') |
|
63
|
|
|
|
|
|
|
or error __x"class {pkg} does not implement toXML(), required for typemap {type}" |
|
64
|
|
|
|
|
|
|
, pkg => $class, type => $type; |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub { |
|
67
|
1
|
|
|
1
|
|
4
|
my ($doc, $values, $path) = @_; |
|
68
|
1
|
50
|
|
|
|
10
|
UNIVERSAL::isa($values, $class) ? $values->toXML($type, $doc) : $values; |
|
69
|
1
|
|
|
|
|
7
|
}; |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub _typemapObject($$) |
|
73
|
1
|
|
|
1
|
|
4
|
{ my ($self, $type, $object) = @_; |
|
74
|
|
|
|
|
|
|
|
|
75
|
1
|
50
|
|
|
|
8
|
$object->can('toXML') |
|
76
|
|
|
|
|
|
|
or error __x"object of class {pkg} does not implement toXML(), required for typemap {type}" |
|
77
|
|
|
|
|
|
|
, pkg => ref($object), type => $type; |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub { |
|
80
|
1
|
|
|
1
|
|
4
|
my ($doc, $values, $path) = @_; |
|
81
|
1
|
50
|
|
|
|
10
|
blessed($values) ? $object->toXML($values, $type, $doc) : $values; |
|
82
|
1
|
|
|
|
|
7
|
}; |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub typemapToHooks($$) |
|
86
|
356
|
|
|
356
|
0
|
826
|
{ my ($self, $hooks, $typemap) = @_; |
|
87
|
356
|
|
|
|
|
1527
|
while(my($type, $action) = each %$typemap) |
|
88
|
3
|
50
|
|
|
|
12
|
{ defined $action or next; |
|
89
|
3
|
|
|
|
|
5
|
my $hook; |
|
90
|
3
|
100
|
|
|
|
13
|
if(!ref $action) |
|
|
|
100
|
|
|
|
|
|
|
91
|
1
|
|
|
|
|
5
|
{ $hook = $self->_typemapClass($type, $action); |
|
92
|
1
|
|
|
|
|
7
|
trace "created writer hook for type $type to class $action"; |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
elsif(ref $action eq 'CODE') |
|
95
|
|
|
|
|
|
|
{ $hook = sub { |
|
96
|
1
|
|
|
1
|
|
3
|
my ($doc, $values, $path) = @_; |
|
97
|
1
|
50
|
|
|
|
8
|
blessed($values) |
|
98
|
|
|
|
|
|
|
? $action->(WRITER => $values, $type, $doc) |
|
99
|
|
|
|
|
|
|
: $values; |
|
100
|
1
|
|
|
|
|
8
|
}; |
|
101
|
1
|
|
|
|
|
6
|
trace "created writer hook for type $type to CODE"; |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
else |
|
104
|
1
|
|
|
|
|
5
|
{ $hook = $self->_typemapObject($type, $action); |
|
105
|
1
|
|
|
|
|
7
|
trace "created reader hook for type $type to object"; |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
|
|
109
|
3
|
|
|
|
|
90
|
push @$hooks, +{action => 'WRITER', type => $type, before => $hook}; |
|
110
|
|
|
|
|
|
|
} |
|
111
|
356
|
|
|
|
|
726
|
$hooks; |
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub makeElementWrapper |
|
115
|
356
|
|
|
356
|
0
|
812
|
{ my ($self, $path, $processor) = @_; |
|
116
|
|
|
|
|
|
|
sub { |
|
117
|
358
|
|
|
358
|
|
310318
|
my ($doc, $data) = @_; |
|
118
|
358
|
50
|
|
|
|
1692
|
UNIVERSAL::isa($doc, 'XML::LibXML::Document') |
|
119
|
|
|
|
|
|
|
or error __x"first argument of call to writer must be an XML::LibXML::Document"; |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
|
122
|
358
|
|
|
|
|
908
|
my $top = $processor->(@_); |
|
123
|
315
|
|
|
|
|
3867
|
$doc->indexElements; |
|
124
|
315
|
|
|
|
|
797
|
$top; |
|
125
|
356
|
|
|
|
|
1518
|
}; |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
*makeAttributeWrapper = \&makeElementWrapper; |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub makeWrapperNs |
|
130
|
55
|
|
|
55
|
0
|
148
|
{ my ($self, $path, $processor, $index, $filter) = @_; |
|
131
|
55
|
|
|
|
|
88
|
my @entries; |
|
132
|
55
|
50
|
|
184
|
|
286
|
$filter = sub {$_[2]} if ref $filter ne 'CODE'; # only the used |
|
|
184
|
|
|
|
|
411
|
|
|
133
|
|
|
|
|
|
|
|
|
134
|
55
|
|
|
|
|
333
|
foreach my $entry (sort {$a->{prefix} cmp $b->{prefix}} values %$index) |
|
|
191
|
|
|
|
|
433
|
|
|
135
|
|
|
|
|
|
|
{ # ANY components are frustrating this |
|
136
|
184
|
100
|
|
|
|
349
|
$filter->($entry->{uri}, $entry->{prefix}, $entry->{used}) or next; |
|
137
|
73
|
|
|
|
|
195
|
push @entries, [ $entry->{uri}, $entry->{prefix} ]; |
|
138
|
73
|
|
|
|
|
139
|
$entry->{used} = 0; |
|
139
|
|
|
|
|
|
|
} |
|
140
|
|
|
|
|
|
|
|
|
141
|
55
|
100
|
|
|
|
141
|
@entries or return $processor; |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub { |
|
144
|
55
|
50
|
|
55
|
|
59556
|
my $node = $processor->(@_) or return (); |
|
145
|
52
|
50
|
|
|
|
370
|
UNIVERSAL::isa($node, 'XML::LibXML::Element') |
|
146
|
|
|
|
|
|
|
or return $node; |
|
147
|
52
|
|
|
|
|
246
|
$node->setNamespace(@$_, 0) for @entries; |
|
148
|
52
|
|
|
|
|
1111
|
$node; |
|
149
|
54
|
|
|
|
|
851
|
}; |
|
150
|
|
|
|
|
|
|
} |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub makeSequence($@) |
|
153
|
207
|
|
|
207
|
0
|
652
|
{ my ($self, $path, @pairs) = @_; |
|
154
|
|
|
|
|
|
|
|
|
155
|
207
|
100
|
|
|
|
582
|
if(@pairs==2) |
|
156
|
80
|
|
|
|
|
230
|
{ my ($take, $do) = @pairs; |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
return |
|
159
|
0
|
|
|
0
|
|
0
|
ref $do eq 'ANY' ? bless(sub { $do->(@_) }, 'BLOCK') |
|
160
|
|
|
|
|
|
|
: ref $do eq 'BLOCK' ? $do |
|
161
|
|
|
|
|
|
|
: bless sub { |
|
162
|
69
|
|
|
69
|
|
142
|
my ($doc, $values) = @_; |
|
163
|
69
|
50
|
|
|
|
180
|
defined $values or return; |
|
164
|
69
|
|
|
|
|
232
|
$do->($doc, delete $values->{$take}); |
|
165
|
80
|
100
|
|
|
|
826
|
}, 'BLOCK'; |
|
|
|
50
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
} |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
bless sub { |
|
169
|
133
|
|
|
133
|
|
268
|
my ($doc, $values) = @_; |
|
170
|
133
|
50
|
|
|
|
307
|
defined $values or return; |
|
171
|
|
|
|
|
|
|
|
|
172
|
133
|
|
|
|
|
178
|
my @res; |
|
173
|
133
|
|
|
|
|
352
|
my @do = @pairs; |
|
174
|
133
|
|
|
|
|
306
|
while(@do) |
|
175
|
303
|
|
|
|
|
695
|
{ my ($take, $do) = (shift @do, shift @do); |
|
176
|
|
|
|
|
|
|
push @res |
|
177
|
|
|
|
|
|
|
, ref $do eq 'BLOCK' ? $do->($doc, $values) |
|
178
|
|
|
|
|
|
|
: ref $do eq 'ANY' ? $do->($doc, $values) |
|
179
|
303
|
100
|
|
|
|
3349
|
: $do->($doc, delete $values->{$take}); |
|
|
|
100
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
} |
|
181
|
126
|
|
|
|
|
2247
|
@res; |
|
182
|
127
|
|
|
|
|
1058
|
}, 'BLOCK'; |
|
183
|
|
|
|
|
|
|
} |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
sub makeChoice($@) |
|
186
|
38
|
|
|
38
|
0
|
83
|
{ my ($self, $path) = (shift, shift); |
|
187
|
38
|
|
|
|
|
64
|
my (%do, @specials); |
|
188
|
38
|
|
|
|
|
100
|
while(@_) # protect order of specials |
|
189
|
89
|
|
|
|
|
145
|
{ my ($el, $do) = (shift, shift); |
|
190
|
89
|
100
|
66
|
|
|
332
|
if(ref $do eq 'BLOCK' || ref $do eq 'ANY') |
|
191
|
12
|
|
|
|
|
33
|
{ push @specials, $do } |
|
192
|
77
|
|
|
|
|
217
|
else { $do{$el} = $do } |
|
193
|
|
|
|
|
|
|
} |
|
194
|
|
|
|
|
|
|
|
|
195
|
38
|
100
|
100
|
|
|
174
|
if(!@specials && keys %do==1) |
|
196
|
2
|
|
|
|
|
8
|
{ my ($take, $do) = %do; |
|
197
|
|
|
|
|
|
|
return bless sub { |
|
198
|
2
|
|
|
2
|
|
5
|
my ($doc, $values) = @_; |
|
199
|
|
|
|
|
|
|
defined $values && defined $values->{$take} |
|
200
|
2
|
50
|
33
|
|
|
16
|
? $do->($doc, delete $values->{$take}) : (); |
|
201
|
2
|
|
|
|
|
17
|
}, 'BLOCK'; |
|
202
|
|
|
|
|
|
|
} |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
bless sub { |
|
205
|
43
|
|
|
43
|
|
79
|
my ($doc, $values) = @_; |
|
206
|
43
|
50
|
|
|
|
96
|
defined $values or return (); |
|
207
|
43
|
|
|
|
|
123
|
foreach my $take (keys %do) |
|
208
|
|
|
|
|
|
|
{ |
|
209
|
|
|
|
|
|
|
#warn "TAKE($take) = ", (defined $values->{$take} ? 'defined' : "undef"); |
|
210
|
|
|
|
|
|
|
return $do{$take}->($doc, delete $values->{$take}) |
|
211
|
67
|
100
|
|
|
|
219
|
if defined $values->{$take}; |
|
212
|
|
|
|
|
|
|
} |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
#warn "TRY SPECIALS"; |
|
215
|
9
|
|
|
|
|
26
|
my $starter = keys %$values; |
|
216
|
9
|
|
|
|
|
18
|
foreach (@specials) |
|
217
|
6
|
|
|
|
|
35
|
{ my @d = try { $_->($doc, $values) }; |
|
|
6
|
|
|
|
|
1533
|
|
|
218
|
6
|
50
|
|
|
|
120
|
if(my $f = $@->wasFatal(class => 'misfit')) |
|
|
|
50
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
{ # misfit error is ok, if nothing consumed |
|
220
|
0
|
|
|
|
|
0
|
my $err = $@; |
|
221
|
0
|
|
|
|
|
0
|
trace "misfit $path ".$@->wasFatal->message; |
|
222
|
0
|
0
|
|
|
|
0
|
$err->reportAll if $starter != keys %$values; |
|
223
|
0
|
|
|
|
|
0
|
next; |
|
224
|
|
|
|
|
|
|
} |
|
225
|
6
|
|
|
|
|
71
|
elsif(defined $@) {$@->reportAll} |
|
226
|
|
|
|
|
|
|
|
|
227
|
6
|
|
|
|
|
61
|
return @d; |
|
228
|
|
|
|
|
|
|
} |
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
#warn "BLURK!"; |
|
231
|
|
|
|
|
|
|
# blurk... any element with minOccurs=0 or default? |
|
232
|
3
|
|
|
|
|
9
|
foreach (values %do) |
|
233
|
5
|
|
|
|
|
40
|
{ my @d = try { $_->($doc, undef) }; |
|
|
5
|
|
|
|
|
1304
|
|
|
234
|
5
|
100
|
66
|
|
|
1094
|
return @d if !$@ && @d; |
|
235
|
|
|
|
|
|
|
} |
|
236
|
2
|
|
|
|
|
17
|
foreach (@specials) |
|
237
|
0
|
|
|
|
|
0
|
{ my @d = try { $_->($doc, undef) }; |
|
|
0
|
|
|
|
|
0
|
|
|
238
|
0
|
0
|
|
|
|
0
|
if($@->wasFatal(class => 'misfit')) |
|
|
|
0
|
|
|
|
|
|
|
239
|
0
|
0
|
|
|
|
0
|
{ $@->reportAll if $starter != keys %$values; |
|
240
|
0
|
|
|
|
|
0
|
next; |
|
241
|
|
|
|
|
|
|
} |
|
242
|
0
|
|
|
|
|
0
|
elsif(defined $@) {$@->reportAll} |
|
243
|
0
|
|
|
|
|
0
|
return @d; |
|
244
|
|
|
|
|
|
|
} |
|
245
|
|
|
|
|
|
|
|
|
246
|
2
|
|
|
|
|
5
|
(); |
|
247
|
36
|
|
|
|
|
325
|
}, 'BLOCK'; |
|
248
|
|
|
|
|
|
|
} |
|
249
|
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
sub makeAll($@) |
|
251
|
14
|
|
|
14
|
0
|
54
|
{ my ($self, $path, @pairs) = @_; |
|
252
|
|
|
|
|
|
|
|
|
253
|
14
|
50
|
66
|
|
|
54
|
if(@pairs==2 && !ref $pairs[1]) |
|
254
|
0
|
|
|
|
|
0
|
{ my ($take, $do) = @pairs; |
|
255
|
|
|
|
|
|
|
return bless sub { |
|
256
|
0
|
|
|
0
|
|
0
|
my ($doc, $values) = @_; |
|
257
|
0
|
|
|
|
|
0
|
$do->($doc, delete $values->{$take}); |
|
258
|
0
|
|
|
|
|
0
|
}, 'BLOCK'; |
|
259
|
|
|
|
|
|
|
} |
|
260
|
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
return bless sub { |
|
262
|
13
|
|
|
13
|
|
24
|
my ($doc, $values) = @_; |
|
263
|
|
|
|
|
|
|
|
|
264
|
13
|
|
|
|
|
19
|
my @res; |
|
265
|
13
|
|
|
|
|
41
|
my @do = @pairs; |
|
266
|
13
|
|
|
|
|
32
|
while(@do) |
|
267
|
35
|
|
|
|
|
73
|
{ my ($take, $do) = (shift @do, shift @do); |
|
268
|
|
|
|
|
|
|
push @res |
|
269
|
|
|
|
|
|
|
, ref $do eq 'BLOCK' || ref $do eq 'ANY' |
|
270
|
|
|
|
|
|
|
? $do->($doc, $values) |
|
271
|
35
|
100
|
66
|
|
|
196
|
: $do->($doc, delete $values->{$take}); |
|
272
|
|
|
|
|
|
|
} |
|
273
|
13
|
|
|
|
|
40
|
@res; |
|
274
|
14
|
|
|
|
|
102
|
}, 'BLOCK'; |
|
275
|
|
|
|
|
|
|
} |
|
276
|
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
# |
|
278
|
|
|
|
|
|
|
## Element |
|
279
|
|
|
|
|
|
|
# |
|
280
|
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
# see comment BlockHandler: undef means zero but success |
|
282
|
|
|
|
|
|
|
sub makeElementHandler |
|
283
|
452
|
|
|
452
|
0
|
1275
|
{ my ($self, $path, $label, $min,$max, $required, $optional) = @_; |
|
284
|
452
|
100
|
|
1
|
|
1104
|
$max eq "0" and return sub {}; |
|
285
|
|
|
|
|
|
|
|
|
286
|
451
|
100
|
100
|
|
|
1362
|
if($min==0 && $max eq 'unbounded') |
|
287
|
|
|
|
|
|
|
{ return |
|
288
|
12
|
|
|
12
|
|
27
|
sub { my ($doc, $values) = @_; |
|
289
|
12
|
50
|
|
|
|
47
|
my @values = ref $values eq 'ARRAY' ? @$values |
|
|
|
100
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
: defined $values ? $values : (); |
|
291
|
12
|
100
|
|
|
|
34
|
@values ? map {$optional->($doc,$_)} @values : (undef); |
|
|
15
|
|
|
|
|
33
|
|
|
292
|
11
|
|
|
|
|
107
|
}; |
|
293
|
|
|
|
|
|
|
} |
|
294
|
|
|
|
|
|
|
|
|
295
|
440
|
50
|
|
|
|
910
|
if($max eq 'unbounded') |
|
296
|
|
|
|
|
|
|
{ return |
|
297
|
0
|
|
|
0
|
|
0
|
sub { my ($doc, $values) = @_; |
|
298
|
0
|
0
|
|
|
|
0
|
my @values = ref $values eq 'ARRAY' ? @$values |
|
|
|
0
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
: defined $values ? $values : (); |
|
300
|
0
|
|
|
|
|
0
|
my @d = ( (map { $required->($doc, shift @values) } 1..$min) |
|
301
|
0
|
|
|
|
|
0
|
, (map { $optional->($doc, $_) } @values) ); |
|
|
0
|
|
|
|
|
0
|
|
|
302
|
0
|
0
|
|
|
|
0
|
@d ? @d : (undef); |
|
303
|
0
|
|
|
|
|
0
|
}; |
|
304
|
|
|
|
|
|
|
} |
|
305
|
|
|
|
|
|
|
|
|
306
|
94
|
100
|
|
94
|
|
210
|
return sub { my @d = $optional->(@_); @d ? @d : undef } |
|
|
92
|
|
|
|
|
428
|
|
|
307
|
440
|
100
|
100
|
|
|
1752
|
if $min==0 && $max==1; |
|
308
|
|
|
|
|
|
|
|
|
309
|
352
|
100
|
100
|
|
|
2937
|
return $required |
|
310
|
|
|
|
|
|
|
if $min==1 && $max==1; |
|
311
|
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
sub { |
|
313
|
12
|
|
|
12
|
|
25
|
my ($doc, $values) = @_; |
|
314
|
|
|
|
|
|
|
my @values |
|
315
|
12
|
50
|
|
|
|
58
|
= ref $values eq 'ARRAY' ? @$values : defined $values ? $values : (); |
|
|
|
100
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
|
|
317
|
12
|
50
|
|
|
|
30
|
@values <= $max |
|
318
|
|
|
|
|
|
|
or error "too many elements for `{tag}', max {max} found {nr} at {path}" |
|
319
|
|
|
|
|
|
|
, tag => $label, max => $max, nr => (scalar @values) |
|
320
|
|
|
|
|
|
|
, path => $path; |
|
321
|
|
|
|
|
|
|
|
|
322
|
12
|
|
|
|
|
25
|
my @d = map { $required->($doc, shift @values) } 1..$min; |
|
|
3
|
|
|
|
|
8
|
|
|
323
|
12
|
|
66
|
|
|
64
|
push @d, $optional->($doc, shift @values) |
|
324
|
|
|
|
|
|
|
while @values && @d < $max; |
|
325
|
|
|
|
|
|
|
|
|
326
|
12
|
100
|
|
|
|
44
|
@d ? @d : (undef); |
|
327
|
11
|
|
|
|
|
105
|
}; |
|
328
|
|
|
|
|
|
|
} |
|
329
|
|
|
|
|
|
|
|
|
330
|
|
|
|
|
|
|
# To reflect the difference between a block which did not "succeed hence |
|
331
|
|
|
|
|
|
|
# produced nothing", and "did succeed by producing nothing" (minOccurs=0) |
|
332
|
|
|
|
|
|
|
# the later is represented by an undef value. |
|
333
|
|
|
|
|
|
|
sub makeBlockHandler |
|
334
|
267
|
|
|
267
|
0
|
2239
|
{ my ($self, $path, $label, $min, $max, $process, $kind, $multi) = @_; |
|
335
|
|
|
|
|
|
|
|
|
336
|
267
|
100
|
100
|
|
|
935
|
if($min==0 && $max eq 'unbounded') |
|
337
|
|
|
|
|
|
|
{ my $code = sub { |
|
338
|
14
|
|
|
14
|
|
90
|
my $doc = shift; |
|
339
|
14
|
50
|
|
|
|
64
|
my $values = $_[0] ? delete shift->{$multi} : undef; |
|
340
|
14
|
50
|
|
|
|
63
|
ref $values eq 'ARRAY' ? (map {$process->($doc, {%$_})} @$values) |
|
|
23
|
100
|
|
|
|
149
|
|
|
341
|
|
|
|
|
|
|
: defined $values ? $process->($doc, $values) |
|
342
|
|
|
|
|
|
|
: (undef); |
|
343
|
14
|
|
|
|
|
57
|
}; |
|
344
|
14
|
|
|
|
|
74
|
return ($multi, bless($code, 'BLOCK')); |
|
345
|
|
|
|
|
|
|
} |
|
346
|
|
|
|
|
|
|
|
|
347
|
253
|
100
|
|
|
|
666
|
if($max eq 'unbounded') |
|
348
|
|
|
|
|
|
|
{ my $code = sub { |
|
349
|
4
|
|
|
4
|
|
9
|
my $doc = shift; |
|
350
|
4
|
50
|
|
|
|
16
|
my $values = $_[0] ? delete shift->{$multi} : undef; |
|
351
|
4
|
0
|
|
|
|
18
|
my @values = ref $values eq 'ARRAY' ? @$values |
|
|
|
50
|
|
|
|
|
|
|
352
|
|
|
|
|
|
|
: defined $values ? $values : (); |
|
353
|
|
|
|
|
|
|
|
|
354
|
4
|
50
|
|
|
|
14
|
@values >= $min |
|
355
|
|
|
|
|
|
|
or error __x"too few blocks for `{tag}' specified, got {found} need {min} at {path}" |
|
356
|
|
|
|
|
|
|
, tag => $multi, found => scalar @values |
|
357
|
|
|
|
|
|
|
, min => $min, path => $path, _class => 'misfit'; |
|
358
|
|
|
|
|
|
|
|
|
359
|
4
|
|
|
|
|
10
|
map {$process->($doc, {%$_}) } @values; |
|
|
13
|
|
|
|
|
75
|
|
|
360
|
5
|
|
|
|
|
28
|
}; |
|
361
|
5
|
|
|
|
|
39
|
return ($multi, bless($code, 'BLOCK')); |
|
362
|
|
|
|
|
|
|
} |
|
363
|
|
|
|
|
|
|
|
|
364
|
248
|
100
|
100
|
|
|
2458
|
if($min==0 && $max==1) |
|
365
|
|
|
|
|
|
|
{ my $code = sub { |
|
366
|
5
|
|
|
5
|
|
14
|
my ($doc, $values) = @_; |
|
367
|
5
|
50
|
|
|
|
24
|
my @values = ref $values eq 'ARRAY' ? @$values |
|
|
|
50
|
|
|
|
|
|
|
368
|
|
|
|
|
|
|
: defined $values ? $values : (); |
|
369
|
5
|
50
|
|
|
|
16
|
@values <= 1 |
|
370
|
|
|
|
|
|
|
or error __x"only one block value for `{tag}', not {count} at {path}" |
|
371
|
|
|
|
|
|
|
, tag => $multi, count => scalar @values |
|
372
|
|
|
|
|
|
|
, path => $path, _class => 'misfit'; |
|
373
|
|
|
|
|
|
|
|
|
374
|
|
|
|
|
|
|
# @values ? $process->($doc, $values[0]) : undef; |
|
375
|
5
|
50
|
|
|
|
13
|
@values or return undef; |
|
376
|
|
|
|
|
|
|
|
|
377
|
5
|
|
|
|
|
13
|
my $starter = keys %$values; |
|
378
|
5
|
|
|
|
|
34
|
my @d = try { $process->($doc, $values[0]) }; |
|
|
5
|
|
|
|
|
1454
|
|
|
379
|
5
|
100
|
100
|
|
|
789
|
$@->wasFatal(class => 'misfit') && $starter==keys %$values |
|
380
|
|
|
|
|
|
|
or $@->reportAll; |
|
381
|
4
|
|
|
|
|
177
|
@d; |
|
382
|
5
|
|
|
|
|
32
|
}; |
|
383
|
5
|
|
|
|
|
35
|
return ($label, bless($code, 'BLOCK')); |
|
384
|
|
|
|
|
|
|
} |
|
385
|
|
|
|
|
|
|
|
|
386
|
243
|
100
|
100
|
|
|
1066
|
if($min==1 && $max==1) |
|
387
|
|
|
|
|
|
|
{ my $code = sub { |
|
388
|
225
|
|
|
225
|
|
529
|
my @d = $process->(@_); |
|
389
|
216
|
100
|
|
|
|
551
|
@d or error __x"no match for required block `{tag}' at {path}" |
|
390
|
|
|
|
|
|
|
, tag => $multi, path => $path, _class => 'misfit'; |
|
391
|
215
|
|
|
|
|
639
|
@d; |
|
392
|
232
|
|
|
|
|
2749
|
}; |
|
393
|
232
|
|
|
|
|
1220
|
return ($label, bless($code, 'BLOCK')); |
|
394
|
|
|
|
|
|
|
} |
|
395
|
|
|
|
|
|
|
|
|
396
|
11
|
|
|
|
|
25
|
my $opt = $max - $min; |
|
397
|
|
|
|
|
|
|
my $code = sub { |
|
398
|
10
|
|
|
10
|
|
23
|
my $doc = shift; |
|
399
|
10
|
|
|
|
|
29
|
my $values = delete shift->{$multi}; |
|
400
|
10
|
50
|
|
|
|
53
|
my @values = ref $values eq 'ARRAY' ? @$values |
|
|
|
100
|
|
|
|
|
|
|
401
|
|
|
|
|
|
|
: defined $values ? $values : (); |
|
402
|
|
|
|
|
|
|
|
|
403
|
10
|
100
|
100
|
|
|
71
|
@values >= $min && @values <= $max |
|
404
|
|
|
|
|
|
|
or error __x"found {found} blocks for `{tag}', must be between {min} and {max} inclusive at {path}" |
|
405
|
|
|
|
|
|
|
, tag => $multi, min => $min, max => $max, path => $path |
|
406
|
|
|
|
|
|
|
, found => scalar @values, _class => 'misfit'; |
|
407
|
|
|
|
|
|
|
|
|
408
|
7
|
|
|
|
|
16
|
map { $process->($doc, {%$_}) } @values; |
|
|
10
|
|
|
|
|
73
|
|
|
409
|
11
|
|
|
|
|
55
|
}; |
|
410
|
|
|
|
|
|
|
|
|
411
|
11
|
|
|
|
|
73
|
($multi, bless($code, 'BLOCK')); |
|
412
|
|
|
|
|
|
|
} |
|
413
|
|
|
|
|
|
|
|
|
414
|
|
|
|
|
|
|
sub makeRequired |
|
415
|
344
|
|
|
344
|
0
|
868
|
{ my ($self, $path, $label, $do) = @_; |
|
416
|
|
|
|
|
|
|
my $req = sub { |
|
417
|
299
|
|
|
299
|
|
644
|
my @nodes = $do->(@_); |
|
418
|
295
|
100
|
|
|
|
1190
|
return @nodes if @nodes; |
|
419
|
|
|
|
|
|
|
|
|
420
|
8
|
50
|
|
|
|
36
|
error __x"required data for block (starts with `{tag}') missing at {path}" |
|
421
|
|
|
|
|
|
|
, tag => $label, path => $path, _class => 'misfit' |
|
422
|
|
|
|
|
|
|
if ref $do eq 'BLOCK'; |
|
423
|
|
|
|
|
|
|
|
|
424
|
8
|
|
|
|
|
33
|
error __x"required value for element `{tag}' missing at {path}" |
|
425
|
|
|
|
|
|
|
, tag => $label, path => $path, _class => 'misfit'; |
|
426
|
344
|
|
|
|
|
1417
|
}; |
|
427
|
344
|
50
|
|
|
|
953
|
bless $req, 'BLOCK' if ref $do eq 'BLOCK'; |
|
428
|
344
|
|
|
|
|
788
|
$req; |
|
429
|
|
|
|
|
|
|
} |
|
430
|
|
|
|
|
|
|
|
|
431
|
|
|
|
|
|
|
sub makeElement |
|
432
|
791
|
|
|
791
|
0
|
3498
|
{ my ($self, $path, $ns, $childname, $do) = @_; |
|
433
|
791
|
100
|
|
767
|
|
2728
|
sub { defined $_[1] ? $do->(@_) : () }; |
|
|
767
|
|
|
|
|
2149
|
|
|
434
|
|
|
|
|
|
|
} |
|
435
|
|
|
|
|
|
|
|
|
436
|
|
|
|
|
|
|
sub makeElementFixed |
|
437
|
4
|
|
|
4
|
0
|
12
|
{ my ($self, $path, $ns, $childname, $do, $fixed) = @_; |
|
438
|
4
|
50
|
|
|
|
10
|
$fixed = $fixed->value if ref $fixed; |
|
439
|
|
|
|
|
|
|
|
|
440
|
|
|
|
|
|
|
sub { |
|
441
|
4
|
|
|
4
|
|
9
|
my ($doc, $value) = @_; |
|
442
|
4
|
100
|
|
|
|
14
|
my $ret = defined $value ? $do->($doc, $value) : return; |
|
443
|
3
|
100
|
66
|
|
|
40
|
return $ret |
|
444
|
|
|
|
|
|
|
if defined $ret && $ret->textContent eq $fixed; |
|
445
|
|
|
|
|
|
|
|
|
446
|
1
|
50
|
|
|
|
5
|
defined $ret |
|
447
|
|
|
|
|
|
|
or error __x"required element `{name}' with fixed value `{fixed}' missing at {path}" |
|
448
|
|
|
|
|
|
|
, name => $childname, fixed => $fixed, path => $path, |
|
449
|
|
|
|
|
|
|
, _class => 'misfit'; |
|
450
|
|
|
|
|
|
|
|
|
451
|
1
|
|
|
|
|
8
|
error __x"element `{name}' has value fixed to `{fixed}', got `{value}' at {path}" |
|
452
|
|
|
|
|
|
|
, name => $childname, fixed => $fixed |
|
453
|
|
|
|
|
|
|
, value => $ret->textContent, path => $path, _class => 'misfit'; |
|
454
|
4
|
|
|
|
|
18
|
}; |
|
455
|
|
|
|
|
|
|
} |
|
456
|
|
|
|
|
|
|
|
|
457
|
|
|
|
|
|
|
sub makeElementDefault |
|
458
|
18
|
|
|
18
|
0
|
51
|
{ my ($self, $path, $ns, $childname, $do, $default) = @_; |
|
459
|
18
|
|
|
|
|
35
|
my $mode = $self->{default_values}; |
|
460
|
|
|
|
|
|
|
|
|
461
|
|
|
|
|
|
|
$mode eq 'IGNORE' |
|
462
|
18
|
100
|
|
14
|
|
73
|
and return sub { defined $_[1] ? $do->(@_) : () }; |
|
|
14
|
100
|
|
|
|
50
|
|
|
463
|
|
|
|
|
|
|
|
|
464
|
|
|
|
|
|
|
$mode eq 'EXTEND' |
|
465
|
4
|
100
|
|
2
|
|
18
|
and return sub { $do->($_[0], (defined $_[1] ? $_[1] : $default)) }; |
|
|
2
|
100
|
|
|
|
8
|
|
|
466
|
|
|
|
|
|
|
|
|
467
|
|
|
|
|
|
|
$mode eq 'MINIMAL' |
|
468
|
2
|
100
|
66
|
2
|
|
14
|
and return sub { defined $_[1] && $_[1] ne $default ? $do->(@_) : () }; |
|
|
2
|
50
|
|
|
|
15
|
|
|
469
|
|
|
|
|
|
|
|
|
470
|
0
|
|
|
|
|
0
|
error __x"illegal default_values mode `{mode}'", mode => $mode; |
|
471
|
|
|
|
|
|
|
} |
|
472
|
|
|
|
|
|
|
|
|
473
|
|
|
|
|
|
|
sub makeElementAbstract |
|
474
|
7
|
|
|
7
|
0
|
29
|
{ my ($self, $path, $ns, $childname, $do, $default) = @_; |
|
475
|
1
|
50
|
|
1
|
|
2
|
sub { defined $_[1] or return (); |
|
476
|
1
|
|
|
|
|
4
|
error __x"attempt to instantiate abstract element `{name}' at {where}" |
|
477
|
|
|
|
|
|
|
, name => $childname, where => $path; |
|
478
|
7
|
|
|
|
|
26
|
}; |
|
479
|
|
|
|
|
|
|
} |
|
480
|
|
|
|
|
|
|
|
|
481
|
|
|
|
|
|
|
# |
|
482
|
|
|
|
|
|
|
# complexType/ComplexContent |
|
483
|
|
|
|
|
|
|
# |
|
484
|
|
|
|
|
|
|
|
|
485
|
|
|
|
|
|
|
sub nil($) |
|
486
|
20
|
|
|
20
|
0
|
44
|
{ my ($self, $path) = @_; |
|
487
|
20
|
|
|
|
|
48
|
$self->makeTagQualified($path, undef, 'nil', SCHEMA2001i); |
|
488
|
|
|
|
|
|
|
} |
|
489
|
|
|
|
|
|
|
|
|
490
|
|
|
|
|
|
|
sub makeComplexElement |
|
491
|
235
|
|
|
235
|
0
|
798
|
{ my ($self, $path, $tag, $elems, $attrs, $any_attr,undef, $is_nillable) = @_; |
|
492
|
235
|
|
|
|
|
746
|
my @elems = odd_elements @$elems; |
|
493
|
235
|
|
|
|
|
503
|
my @attrs = @$attrs; |
|
494
|
235
|
|
|
|
|
667
|
my $tags = join ', ', grep defined |
|
495
|
|
|
|
|
|
|
, even_elements(@$elems), even_elements(@attrs); |
|
496
|
235
|
|
|
|
|
535
|
my @anya = @$any_attr; |
|
497
|
235
|
|
|
|
|
478
|
my $iut = $self->{ignore_unused_tags}; |
|
498
|
235
|
100
|
|
|
|
502
|
my $nilattr = $is_nillable ? $self->nil($path) : undef; |
|
499
|
|
|
|
|
|
|
|
|
500
|
|
|
|
|
|
|
return |
|
501
|
|
|
|
|
|
|
sub |
|
502
|
236
|
|
|
236
|
|
441
|
{ my ($doc, $data) = @_; |
|
503
|
236
|
50
|
|
|
|
696
|
$data = { _ => 'NIL' } if $data eq 'NIL'; |
|
504
|
|
|
|
|
|
|
|
|
505
|
236
|
50
|
|
|
|
661
|
return $doc->importNode($data) |
|
506
|
|
|
|
|
|
|
if UNIVERSAL::isa($data, 'XML::LibXML::Element'); |
|
507
|
|
|
|
|
|
|
|
|
508
|
236
|
50
|
|
|
|
597
|
unless(UNIVERSAL::isa($data, 'HASH')) |
|
509
|
0
|
0
|
|
|
|
0
|
{ defined $data |
|
510
|
|
|
|
|
|
|
or error __x"complex `{tag}' requires data at {path}" |
|
511
|
|
|
|
|
|
|
, tag => $tag, path => $path, _class => 'misfit'; |
|
512
|
|
|
|
|
|
|
|
|
513
|
0
|
|
0
|
|
|
0
|
error __x"complex `{tag}' requires a HASH of input data, not `{got}' at {path}" |
|
514
|
|
|
|
|
|
|
, tag => $tag, got => (ref $data || $data), path => $path; |
|
515
|
|
|
|
|
|
|
} |
|
516
|
|
|
|
|
|
|
|
|
517
|
236
|
|
|
|
|
865
|
my $copy = { %$data }; # do not destroy callers hash |
|
518
|
|
|
|
|
|
|
|
|
519
|
236
|
100
|
100
|
|
|
1225
|
my @childs = ($is_nillable && (delete $copy->{_} || '') eq 'NIL') |
|
520
|
|
|
|
|
|
|
? $doc->createAttribute($nilattr => 'true') |
|
521
|
|
|
|
|
|
|
: map($_->($doc, $copy), @elems); |
|
522
|
|
|
|
|
|
|
|
|
523
|
223
|
|
|
|
|
698
|
for(my $i=0; $i<@attrs; $i+=2) |
|
524
|
90
|
|
|
|
|
300
|
{ push @childs, $attrs[$i+1]->($doc, delete $copy->{$attrs[$i]}); |
|
525
|
|
|
|
|
|
|
} |
|
526
|
|
|
|
|
|
|
|
|
527
|
|
|
|
|
|
|
push @childs, $_->($doc, $copy) |
|
528
|
221
|
|
|
|
|
479
|
for @anya; |
|
529
|
|
|
|
|
|
|
|
|
530
|
221
|
100
|
|
|
|
498
|
if(%$copy) |
|
531
|
|
|
|
|
|
|
{ my @not_used |
|
532
|
3
|
50
|
|
|
|
15
|
= defined $iut ? (grep $_ !~ $iut, keys %$copy) : keys %$copy; |
|
533
|
|
|
|
|
|
|
|
|
534
|
3
|
50
|
|
|
|
10
|
if(@not_used) |
|
535
|
3
|
|
|
|
|
21
|
{ trace "available tags are: $tags"; |
|
536
|
3
|
|
|
|
|
220
|
mistake __xn "tag `{tags}' not used at {path}" |
|
537
|
|
|
|
|
|
|
, "unused tags {tags} at {path}" |
|
538
|
|
|
|
|
|
|
, scalar @not_used, tags => [sort @not_used], path => $path; |
|
539
|
|
|
|
|
|
|
} |
|
540
|
|
|
|
|
|
|
} |
|
541
|
|
|
|
|
|
|
|
|
542
|
221
|
|
|
|
|
1820
|
my $node = $doc->createElement($tag); |
|
543
|
|
|
|
|
|
|
|
|
544
|
221
|
|
|
|
|
438
|
foreach my $child (@childs) |
|
545
|
508
|
100
|
|
|
|
3377
|
{ defined $child or next; |
|
546
|
460
|
50
|
|
|
|
887
|
if(ref $child) |
|
547
|
460
|
50
|
33
|
|
|
1512
|
{ next if UNIVERSAL::isa($child, 'XML::LibXML::Text') |
|
548
|
|
|
|
|
|
|
&& $child->data eq ''; |
|
549
|
|
|
|
|
|
|
} |
|
550
|
|
|
|
|
|
|
else |
|
551
|
0
|
0
|
|
|
|
0
|
{ length $child or next; |
|
552
|
0
|
|
|
|
|
0
|
$child = XML::LibXML::Text->new($child); |
|
553
|
|
|
|
|
|
|
} |
|
554
|
460
|
|
|
|
|
3711
|
$node->addChild($child); |
|
555
|
|
|
|
|
|
|
} |
|
556
|
|
|
|
|
|
|
|
|
557
|
221
|
|
|
|
|
2034
|
$node; |
|
558
|
235
|
|
|
|
|
1816
|
}; |
|
559
|
|
|
|
|
|
|
} |
|
560
|
|
|
|
|
|
|
|
|
561
|
|
|
|
|
|
|
# |
|
562
|
|
|
|
|
|
|
# complexType/simpleContent |
|
563
|
|
|
|
|
|
|
# |
|
564
|
|
|
|
|
|
|
|
|
565
|
|
|
|
|
|
|
sub makeTaggedElement |
|
566
|
9
|
|
|
9
|
0
|
29
|
{ my ($self, $path, $tag, $st, $attrs, $attrs_any,undef, $is_nillable) = @_; |
|
567
|
9
|
|
|
|
|
23
|
my @attrs = @$attrs; |
|
568
|
9
|
|
|
|
|
14
|
my @anya = @$attrs_any; |
|
569
|
9
|
100
|
|
|
|
23
|
my $nilattr = $is_nillable ? $self->nil($path) : undef; |
|
570
|
|
|
|
|
|
|
|
|
571
|
|
|
|
|
|
|
return sub { |
|
572
|
9
|
|
|
9
|
|
17
|
my ($doc, $data) = @_; |
|
573
|
9
|
50
|
|
|
|
29
|
return $doc->importNode($data) |
|
574
|
|
|
|
|
|
|
if UNIVERSAL::isa($data, 'XML::LibXML::Element'); |
|
575
|
|
|
|
|
|
|
|
|
576
|
9
|
50
|
|
|
|
49
|
my $copy = UNIVERSAL::isa($data,'HASH') ? {%$data} : {_ => $data}; |
|
577
|
9
|
|
|
|
|
21
|
my $content = delete $copy->{_}; |
|
578
|
|
|
|
|
|
|
|
|
579
|
9
|
|
|
|
|
15
|
my ($node, @childs); |
|
580
|
9
|
50
|
66
|
|
|
51
|
if(UNIVERSAL::isa($content, 'XML::LibXML::Node')) |
|
|
|
100
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
581
|
0
|
|
|
|
|
0
|
{ $node = $doc->importNode($content); |
|
582
|
|
|
|
|
|
|
} |
|
583
|
|
|
|
|
|
|
elsif($is_nillable && $content eq 'NIL') |
|
584
|
1
|
|
|
|
|
11
|
{ push @childs, $doc->createAttribute($nilattr => 'true'); |
|
585
|
|
|
|
|
|
|
} |
|
586
|
|
|
|
|
|
|
elsif(defined $content) |
|
587
|
8
|
|
|
|
|
20
|
{ push @childs, $st->($doc, $content); |
|
588
|
|
|
|
|
|
|
} |
|
589
|
|
|
|
|
|
|
|
|
590
|
9
|
|
|
|
|
32
|
for(my $i=0; $i<@attrs; $i+=2) |
|
591
|
10
|
|
|
|
|
40
|
{ push @childs, $attrs[$i+1]->($doc, delete $copy->{$attrs[$i]}); |
|
592
|
|
|
|
|
|
|
} |
|
593
|
|
|
|
|
|
|
|
|
594
|
|
|
|
|
|
|
push @childs, $_->($doc, $copy) |
|
595
|
9
|
|
|
|
|
23
|
for @anya; |
|
596
|
|
|
|
|
|
|
|
|
597
|
9
|
50
|
|
|
|
40
|
if(my @not_used = sort keys %$copy) |
|
598
|
0
|
|
|
|
|
0
|
{ error __xn "tag `{tags}' not processed at {path}" |
|
599
|
|
|
|
|
|
|
, "unprocessed tags {tags} at {path}" |
|
600
|
|
|
|
|
|
|
, scalar @not_used, tags => \@not_used, path => $path; |
|
601
|
|
|
|
|
|
|
} |
|
602
|
|
|
|
|
|
|
|
|
603
|
9
|
50
|
33
|
|
|
40
|
$node or @childs or return (); |
|
604
|
9
|
|
33
|
|
|
105
|
$node ||= $doc->createElement($tag); |
|
605
|
|
|
|
|
|
|
$node->addChild |
|
606
|
|
|
|
|
|
|
( UNIVERSAL::isa($_, 'XML::LibXML::Node') ? $_ |
|
607
|
|
|
|
|
|
|
: $doc->createTextNode(defined $_ ? $_ : '')) |
|
608
|
9
|
50
|
|
|
|
191
|
for @childs; |
|
|
|
100
|
|
|
|
|
|
|
609
|
9
|
|
|
|
|
37
|
$node; |
|
610
|
9
|
|
|
|
|
67
|
}; |
|
611
|
|
|
|
|
|
|
} |
|
612
|
|
|
|
|
|
|
|
|
613
|
|
|
|
|
|
|
# |
|
614
|
|
|
|
|
|
|
# complexType mixed or complexContent mixed |
|
615
|
|
|
|
|
|
|
# |
|
616
|
|
|
|
|
|
|
|
|
617
|
|
|
|
|
|
|
sub makeMixedElement |
|
618
|
1
|
|
|
1
|
0
|
3
|
{ my ($self, $path, $tag, $elems, $attrs, $attrs_any,undef, $is_nillable) =@_; |
|
619
|
1
|
|
|
|
|
5
|
my @attrs = @$attrs; |
|
620
|
1
|
|
|
|
|
3
|
my @anya = @$attrs_any; |
|
621
|
1
|
50
|
|
|
|
5
|
my $nilattr = $is_nillable ? $self->nil($path) : undef; |
|
622
|
1
|
|
|
|
|
5
|
(my $locname = $tag) =~ s/.*\://; |
|
623
|
|
|
|
|
|
|
|
|
624
|
1
|
|
|
|
|
4
|
my $mixed = $self->{mixed_elements}; |
|
625
|
1
|
50
|
|
|
|
3
|
if($mixed eq 'ATTRIBUTES') { ; } |
|
|
|
0
|
|
|
|
|
|
|
626
|
|
|
|
|
|
|
elsif($mixed eq 'STRUCTURAL') |
|
627
|
|
|
|
|
|
|
{ # mixed_element eq STRUCTURAL is handled earlier |
|
628
|
0
|
|
|
|
|
0
|
panic "mixed structural handled as normal element"; |
|
629
|
|
|
|
|
|
|
} |
|
630
|
0
|
|
|
|
|
0
|
else { error __x"unknown mixed_elements value `{value}'", value => $mixed } |
|
631
|
|
|
|
|
|
|
|
|
632
|
1
|
0
|
33
|
|
|
4
|
if(!@attrs && !@anya) |
|
633
|
|
|
|
|
|
|
{ return |
|
634
|
0
|
|
|
0
|
|
0
|
sub { my ($doc, $data) = @_; |
|
635
|
0
|
0
|
|
|
|
0
|
my $node = ref $data eq 'HASH' ? $data->{_} : $data; |
|
636
|
0
|
0
|
|
|
|
0
|
return $doc->importNode($node) |
|
637
|
|
|
|
|
|
|
if UNIVERSAL::isa($node, 'XML::LibXML::Element'); |
|
638
|
0
|
|
|
|
|
0
|
error __x"mixed `{tag}' requires XML::LibXML::Node, not `{found}' at {path}" |
|
639
|
|
|
|
|
|
|
, tag => $tag, found => $data, path => $path; |
|
640
|
0
|
|
|
|
|
0
|
}; |
|
641
|
|
|
|
|
|
|
} |
|
642
|
|
|
|
|
|
|
|
|
643
|
1
|
|
|
|
|
2
|
my $iut = $self->{ignore_unused_tags}; |
|
644
|
2
|
|
|
2
|
|
4
|
sub { my ($doc, $data) = @_; |
|
645
|
2
|
50
|
|
|
|
5
|
defined $data or return; |
|
646
|
|
|
|
|
|
|
|
|
647
|
2
|
100
|
|
|
|
38
|
return $doc->importNode($data) |
|
648
|
|
|
|
|
|
|
if UNIVERSAL::isa($data, 'XML::LibXML::Element'); |
|
649
|
|
|
|
|
|
|
|
|
650
|
1
|
50
|
|
|
|
7
|
my $copy = UNIVERSAL::isa($data, 'HASH') ? {%$data} : {_ => $data}; |
|
651
|
1
|
|
|
|
|
3
|
my $content = delete $copy->{_}; |
|
652
|
1
|
50
|
|
|
|
4
|
defined $content or return; |
|
653
|
|
|
|
|
|
|
|
|
654
|
|
|
|
|
|
|
#XXX there are no regression test for these options |
|
655
|
1
|
|
|
|
|
2
|
my $node; |
|
656
|
1
|
50
|
33
|
|
|
11
|
if(blessed $content && $content->isa('XML::LibXML::Node')) |
|
|
|
0
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
657
|
1
|
|
|
|
|
7
|
{ $node = $doc->importNode($content); |
|
658
|
|
|
|
|
|
|
} |
|
659
|
|
|
|
|
|
|
elsif($is_nillable && $content eq 'NIL') |
|
660
|
|
|
|
|
|
|
{ # nillable element |
|
661
|
0
|
|
|
|
|
0
|
$node = $doc->createElement($tag); |
|
662
|
0
|
|
|
|
|
0
|
$node->setAttribute($nilattr => 'true'); |
|
663
|
|
|
|
|
|
|
} |
|
664
|
|
|
|
|
|
|
elsif($content =~ /\<.*?\>|\&\w+\;/) |
|
665
|
|
|
|
|
|
|
{ # XXX I do not know a way to fill text nodes without getting |
|
666
|
|
|
|
|
|
|
# entity encoding on them. Apparently, libxml2 has a |
|
667
|
|
|
|
|
|
|
# xmlStringTextNoenc, which is not provided in XML::LibXML. |
|
668
|
|
|
|
|
|
|
# Now, we need the expensive roundtrip, via the parser. |
|
669
|
|
|
|
|
|
|
|
|
670
|
0
|
|
|
|
|
0
|
my $frag = XML::LibXML->new |
|
671
|
|
|
|
|
|
|
->parse_balanced_chunk(encode utf8 => $content); |
|
672
|
|
|
|
|
|
|
|
|
673
|
0
|
|
|
|
|
0
|
$node = $frag->firstChild; |
|
674
|
0
|
0
|
|
|
|
0
|
if($node->localName ne $locname) |
|
675
|
|
|
|
|
|
|
{ # --> <$locname>$nodes$locname> |
|
676
|
0
|
|
|
|
|
0
|
my $c = $node; |
|
677
|
0
|
|
|
|
|
0
|
$node = $doc->createElement($tag); |
|
678
|
0
|
|
|
|
|
0
|
$node->appendChild($frag); |
|
679
|
|
|
|
|
|
|
} |
|
680
|
|
|
|
|
|
|
} |
|
681
|
|
|
|
|
|
|
else |
|
682
|
|
|
|
|
|
|
{ # Plain text |
|
683
|
0
|
|
|
|
|
0
|
$node = $doc->createElement($tag); |
|
684
|
0
|
|
|
|
|
0
|
$node->appendText($content); |
|
685
|
|
|
|
|
|
|
} |
|
686
|
|
|
|
|
|
|
|
|
687
|
1
|
|
|
|
|
2
|
my @childs; |
|
688
|
1
|
|
|
|
|
4
|
for(my $i=0; $i<@attrs; $i+=2) |
|
689
|
1
|
|
|
|
|
1908
|
{ push @childs, $attrs[$i+1]->($doc, delete $copy->{$attrs[$i]}); |
|
690
|
|
|
|
|
|
|
} |
|
691
|
|
|
|
|
|
|
|
|
692
|
|
|
|
|
|
|
push @childs, $_->($doc, $copy) |
|
693
|
1
|
|
|
|
|
3
|
for @anya; |
|
694
|
|
|
|
|
|
|
|
|
695
|
1
|
50
|
|
|
|
4
|
if(%$copy) |
|
696
|
|
|
|
|
|
|
{ my @not_used |
|
697
|
0
|
0
|
|
|
|
0
|
= defined $iut ? (grep $_ !~ $iut, keys %$copy) : keys %$copy; |
|
698
|
|
|
|
|
|
|
|
|
699
|
0
|
0
|
|
|
|
0
|
if(my @not_used = sort keys %$copy) |
|
700
|
0
|
|
|
|
|
0
|
{ error __xn "tag `{tags}' not processed at {path}" |
|
701
|
|
|
|
|
|
|
, "unprocessed tags {tags} at {path}", scalar @not_used |
|
702
|
|
|
|
|
|
|
, tags => [sort @not_used], path => $path; |
|
703
|
|
|
|
|
|
|
} |
|
704
|
|
|
|
|
|
|
} |
|
705
|
|
|
|
|
|
|
|
|
706
|
1
|
50
|
|
|
|
3
|
@childs or return $node; |
|
707
|
|
|
|
|
|
|
$node->addChild |
|
708
|
|
|
|
|
|
|
( ref $_ && $_->isa('XML::LibXML::Node') ? $_ |
|
709
|
|
|
|
|
|
|
: $doc->createTextNode(defined $_ ? $_ : '')) |
|
710
|
1
|
0
|
33
|
|
|
29
|
for @childs; |
|
|
|
50
|
|
|
|
|
|
|
711
|
1
|
|
|
|
|
4
|
$node; |
|
712
|
1
|
|
|
|
|
7
|
}; |
|
713
|
|
|
|
|
|
|
} |
|
714
|
|
|
|
|
|
|
|
|
715
|
|
|
|
|
|
|
# |
|
716
|
|
|
|
|
|
|
# simpleType |
|
717
|
|
|
|
|
|
|
# |
|
718
|
|
|
|
|
|
|
|
|
719
|
|
|
|
|
|
|
sub makeSimpleElement |
|
720
|
575
|
|
|
575
|
0
|
1683
|
{ my ($self, $path, $tag, $st, undef, undef, undef, $is_nillable) = @_; |
|
721
|
575
|
100
|
|
|
|
3001
|
my $nilattr = $is_nillable ? $self->nil($path) : undef; |
|
722
|
|
|
|
|
|
|
|
|
723
|
|
|
|
|
|
|
sub { |
|
724
|
498
|
|
|
498
|
|
855
|
my ($doc, $data) = @_; |
|
725
|
498
|
50
|
|
|
|
1506
|
return $doc->importNode($data) |
|
726
|
|
|
|
|
|
|
if UNIVERSAL::isa($data, 'XML::LibXML::Element'); |
|
727
|
|
|
|
|
|
|
$data = $data->{_} |
|
728
|
498
|
100
|
|
|
|
1125
|
if ref $data eq 'HASH'; |
|
729
|
|
|
|
|
|
|
|
|
730
|
498
|
100
|
100
|
|
|
1689
|
my $value = ($is_nillable && $data eq 'NIL') |
|
731
|
|
|
|
|
|
|
? $doc->createAttribute($nilattr => 'true') |
|
732
|
|
|
|
|
|
|
: $st->($doc, $data); |
|
733
|
|
|
|
|
|
|
|
|
734
|
467
|
50
|
|
|
|
1314
|
defined $value |
|
735
|
|
|
|
|
|
|
or return (); |
|
736
|
|
|
|
|
|
|
|
|
737
|
467
|
|
|
|
|
3025
|
my $node = $doc->createElement($tag); |
|
738
|
467
|
50
|
33
|
|
|
1916
|
error __x"expected single value for {tag}, but got {type}" |
|
739
|
|
|
|
|
|
|
, tag => $tag, type => ref($value) |
|
740
|
|
|
|
|
|
|
if ref $value eq 'ARRAY' || ref $value eq 'HASH'; |
|
741
|
|
|
|
|
|
|
|
|
742
|
467
|
50
|
|
|
|
7611
|
$node->addChild |
|
|
|
100
|
|
|
|
|
|
|
743
|
|
|
|
|
|
|
( UNIVERSAL::isa($value, 'XML::LibXML::Node') ? $value |
|
744
|
|
|
|
|
|
|
: $doc->createTextNode(defined $value ? $value : '')); |
|
745
|
467
|
|
|
|
|
2099
|
$node; |
|
746
|
575
|
|
|
|
|
2989
|
}; |
|
747
|
|
|
|
|
|
|
} |
|
748
|
|
|
|
|
|
|
|
|
749
|
|
|
|
|
|
|
sub makeBuiltin |
|
750
|
705
|
|
|
705
|
0
|
1705
|
{ my ($self, $path, $node, $type, $def, $check_values) = @_; |
|
751
|
705
|
50
|
|
|
|
1669
|
my $check = $check_values ? $def->{check} : undef; |
|
752
|
705
|
100
|
|
|
|
2547
|
my $err = $path eq $type |
|
753
|
|
|
|
|
|
|
? N__"illegal value `{value}' for type {type}" |
|
754
|
|
|
|
|
|
|
: N__"illegal value `{value}' for type {type} at {path}"; |
|
755
|
|
|
|
|
|
|
|
|
756
|
705
|
|
|
|
|
2388
|
my $format = $def->{format}; |
|
757
|
705
|
|
|
|
|
1008
|
my $trans = $self->{prefixes}; |
|
758
|
|
|
|
|
|
|
|
|
759
|
|
|
|
|
|
|
$check |
|
760
|
|
|
|
|
|
|
? ( defined $format |
|
761
|
526
|
100
|
|
526
|
|
2774
|
? sub { defined $_[1] or return undef; |
|
762
|
504
|
|
|
|
|
3193
|
my $value = $format->($_[1], $trans, $path); |
|
763
|
503
|
100
|
66
|
|
|
5808
|
return $value if defined $value && $check->($value); |
|
764
|
11
|
|
|
|
|
36
|
error __x$err, value => $value, type => $type, path => $path; |
|
765
|
|
|
|
|
|
|
} |
|
766
|
28
|
50
|
33
|
28
|
|
159
|
: sub { return $_[1] if !defined $_[1] || $check->($_[1]); |
|
767
|
0
|
|
|
|
|
0
|
error __x$err, value => $_[1], type => $type, path => $path; |
|
768
|
|
|
|
|
|
|
} |
|
769
|
|
|
|
|
|
|
) |
|
770
|
|
|
|
|
|
|
: ( defined $format |
|
771
|
6
|
50
|
|
6
|
|
30
|
? sub { defined $_[1] ? $format->($_[1], $trans, $path) : undef } |
|
772
|
45
|
|
|
45
|
|
97
|
: sub { $_[1] } |
|
773
|
705
|
100
|
|
|
|
4689
|
); |
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
774
|
|
|
|
|
|
|
} |
|
775
|
|
|
|
|
|
|
|
|
776
|
|
|
|
|
|
|
# simpleType |
|
777
|
|
|
|
|
|
|
|
|
778
|
|
|
|
|
|
|
sub makeList |
|
779
|
28
|
|
|
28
|
0
|
60
|
{ my ($self, $path, $st) = @_; |
|
780
|
34
|
|
|
34
|
|
62
|
sub { my ($doc, $v) = @_; |
|
781
|
34
|
50
|
|
|
|
71
|
defined $v or return undef; |
|
782
|
34
|
100
|
|
|
|
92
|
join ' ', grep defined, map {$st->($doc, $_)} |
|
|
49
|
|
|
|
|
135
|
|
|
783
|
|
|
|
|
|
|
ref $v eq 'ARRAY' ? @$v : $v; |
|
784
|
28
|
|
|
|
|
127
|
}; |
|
785
|
|
|
|
|
|
|
} |
|
786
|
|
|
|
|
|
|
|
|
787
|
|
|
|
|
|
|
sub makeFacetsList |
|
788
|
12
|
|
|
12
|
0
|
30
|
{ my ($self, $path, $st, $info, $early, $late) = @_; |
|
789
|
12
|
|
|
|
|
27
|
my @e = grep defined, @$early; |
|
790
|
12
|
|
|
|
|
34
|
my @l = grep defined, @$late; |
|
791
|
12
|
|
|
12
|
|
21
|
sub { my ($doc, $v) = @_; |
|
792
|
12
|
50
|
|
|
|
26
|
defined $v or return undef; |
|
793
|
12
|
|
|
|
|
35
|
$_->($v) for @l; |
|
794
|
8
|
50
|
|
|
|
39
|
my $list = join ' ', map $st->($doc, $_), ref $v eq 'ARRAY' ? @$v : $v; |
|
795
|
8
|
50
|
33
|
|
|
35
|
defined $list && length $list or return; |
|
796
|
8
|
|
|
|
|
18
|
do { $list = $_->($list) } for @e; |
|
|
4
|
|
|
|
|
9
|
|
|
797
|
7
|
|
|
|
|
14
|
$list; |
|
798
|
|
|
|
|
|
|
} |
|
799
|
12
|
|
|
|
|
72
|
} |
|
800
|
|
|
|
|
|
|
|
|
801
|
|
|
|
|
|
|
sub makeFacets |
|
802
|
87
|
|
|
87
|
0
|
242
|
{ my ($self, $path, $st, $info, $early, $late) = @_; |
|
803
|
87
|
100
|
100
|
|
|
368
|
@$early || @$late or return $st; |
|
804
|
74
|
|
|
74
|
|
161
|
sub { my ($doc, $v) = @_; |
|
805
|
74
|
50
|
|
|
|
177
|
defined $v or return undef; |
|
806
|
74
|
|
|
|
|
255
|
$v = $_->($v) for @$late; |
|
807
|
54
|
|
|
|
|
262
|
$v = $st->($doc, $v); |
|
808
|
53
|
50
|
|
|
|
170
|
defined $v or return undef; |
|
809
|
53
|
|
|
|
|
123
|
$v = $_->($v) for @$early; |
|
810
|
52
|
|
|
|
|
104
|
$v; |
|
811
|
86
|
|
|
|
|
556
|
}; |
|
812
|
|
|
|
|
|
|
} |
|
813
|
|
|
|
|
|
|
|
|
814
|
|
|
|
|
|
|
sub makeUnion |
|
815
|
18
|
|
|
18
|
0
|
50
|
{ my ($self, $path, @types) = @_; |
|
816
|
25
|
|
|
25
|
|
39
|
sub { my ($doc, $value) = @_; |
|
817
|
25
|
50
|
|
|
|
53
|
defined $value or return undef; |
|
818
|
25
|
100
|
|
|
|
49
|
for(@types) {my $v = try { $_->($doc, $value) }; $@ or return $v } |
|
|
37
|
|
|
|
|
246
|
|
|
|
37
|
|
|
|
|
12513
|
|
|
|
37
|
|
|
|
|
3734
|
|
|
819
|
|
|
|
|
|
|
|
|
820
|
2
|
50
|
|
|
|
21
|
substr $value, 20, -5, '...' if length($value) > 50; |
|
821
|
2
|
|
|
|
|
7
|
error __x"no match for `{text}' in union at {path}" |
|
822
|
|
|
|
|
|
|
, text => $value, path => $path; |
|
823
|
18
|
|
|
|
|
73
|
}; |
|
824
|
|
|
|
|
|
|
} |
|
825
|
|
|
|
|
|
|
|
|
826
|
|
|
|
|
|
|
sub makeSubstgroup |
|
827
|
8
|
|
|
8
|
0
|
39
|
{ my ($self, $path, $type, %done) = @_; |
|
828
|
|
|
|
|
|
|
|
|
829
|
8
|
50
|
|
0
|
|
28
|
keys %done or return bless sub { () }, 'BLOCK'; |
|
|
0
|
|
|
|
|
0
|
|
|
830
|
8
|
|
|
|
|
28
|
my %do = map { @$_ } values %done; |
|
|
23
|
|
|
|
|
116
|
|
|
831
|
|
|
|
|
|
|
|
|
832
|
|
|
|
|
|
|
bless |
|
833
|
10
|
|
|
10
|
|
19
|
sub { my ($doc, $values) = @_; |
|
834
|
|
|
|
|
|
|
#warn "SUBST($type) AVAILABLE ARE ", join ', ', keys %do; |
|
835
|
10
|
|
|
|
|
33
|
foreach my $take (keys %do) |
|
836
|
17
|
|
|
|
|
48
|
{ my $subst = delete $values->{$take}; |
|
837
|
17
|
100
|
|
|
|
47
|
defined $subst or next; |
|
838
|
|
|
|
|
|
|
|
|
839
|
10
|
|
|
|
|
28
|
return $do{$take}->($doc, $subst); |
|
840
|
|
|
|
|
|
|
} |
|
841
|
0
|
|
|
|
|
0
|
(); |
|
842
|
8
|
|
|
|
|
67
|
}, 'BLOCK'; |
|
843
|
|
|
|
|
|
|
} |
|
844
|
|
|
|
|
|
|
|
|
845
|
|
|
|
|
|
|
# Attributes |
|
846
|
|
|
|
|
|
|
|
|
847
|
|
|
|
|
|
|
sub makeAttributeRequired |
|
848
|
11
|
|
|
11
|
0
|
26
|
{ my ($self, $path, $ns, $tag, $label, $do) = @_; |
|
849
|
|
|
|
|
|
|
|
|
850
|
10
|
|
|
10
|
|
22
|
sub { my $value = $do->(@_); |
|
851
|
10
|
50
|
|
|
|
103
|
return $_[0]->createAttribute($tag, $value) |
|
852
|
|
|
|
|
|
|
if defined $value; |
|
853
|
|
|
|
|
|
|
|
|
854
|
0
|
|
|
|
|
0
|
error __x"attribute `{tag}' is required at {path}" |
|
855
|
|
|
|
|
|
|
, tag => $tag, path => $path; |
|
856
|
11
|
|
|
|
|
63
|
}; |
|
857
|
|
|
|
|
|
|
} |
|
858
|
|
|
|
|
|
|
|
|
859
|
|
|
|
|
|
|
sub makeAttributeProhibited |
|
860
|
3
|
|
|
3
|
0
|
8
|
{ my ($self, $path, $ns, $tag, $label, $do) = @_; |
|
861
|
|
|
|
|
|
|
|
|
862
|
3
|
|
|
3
|
|
7
|
sub { my $value = $do->(@_); |
|
863
|
3
|
100
|
|
|
|
9
|
defined $value or return (); |
|
864
|
|
|
|
|
|
|
|
|
865
|
1
|
|
|
|
|
3
|
error __x"attribute `{tag}' is prohibited at {path}" |
|
866
|
|
|
|
|
|
|
, tag => $tag, path => $path; |
|
867
|
3
|
|
|
|
|
11
|
}; |
|
868
|
|
|
|
|
|
|
} |
|
869
|
|
|
|
|
|
|
|
|
870
|
|
|
|
|
|
|
sub makeAttribute |
|
871
|
82
|
|
|
82
|
0
|
211
|
{ my ($self, $path, $ns, $tag, $label, $do) = @_; |
|
872
|
80
|
|
|
80
|
|
190
|
sub { my $value = $do->(@_); |
|
873
|
79
|
100
|
|
|
|
855
|
defined $value ? $_[0]->createAttribute($tag, $value) : (); |
|
874
|
82
|
|
|
|
|
2036
|
}; |
|
875
|
|
|
|
|
|
|
} |
|
876
|
|
|
|
|
|
|
|
|
877
|
|
|
|
|
|
|
sub makeAttributeDefault |
|
878
|
7
|
|
|
7
|
0
|
21
|
{ my ($self, $path, $ns, $tag, $label, $do, $default_node) = @_; |
|
879
|
|
|
|
|
|
|
|
|
880
|
7
|
|
|
|
|
14
|
my $mode = $self->{default_values}; |
|
881
|
|
|
|
|
|
|
$mode eq 'IGNORE' |
|
882
|
|
|
|
|
|
|
and return sub |
|
883
|
3
|
|
|
3
|
|
6
|
{ my $value = $do->(@_); |
|
884
|
3
|
100
|
|
|
|
17
|
defined $value ? $_[0]->createAttribute($tag, $value) : (); |
|
885
|
7
|
100
|
|
|
|
41
|
}; |
|
886
|
|
|
|
|
|
|
|
|
887
|
4
|
|
|
|
|
19
|
my $default = $default_node->value; |
|
888
|
|
|
|
|
|
|
$mode eq 'EXTEND' |
|
889
|
|
|
|
|
|
|
and return sub |
|
890
|
2
|
|
|
2
|
|
6
|
{ my $value = $do->(@_); |
|
891
|
2
|
100
|
|
|
|
6
|
defined $value or $value = $default; |
|
892
|
2
|
|
|
|
|
15
|
$_[0]->createAttribute($tag, $value); |
|
893
|
4
|
100
|
|
|
|
18
|
}; |
|
894
|
|
|
|
|
|
|
|
|
895
|
|
|
|
|
|
|
$mode eq 'MINIMAL' |
|
896
|
|
|
|
|
|
|
and return sub |
|
897
|
2
|
|
|
2
|
|
7
|
{ my $value = $do->(@_); |
|
898
|
2
|
100
|
66
|
|
|
15
|
return () if defined $value && $value eq $default; |
|
899
|
1
|
|
|
|
|
9
|
$_[0]->createAttribute($tag, $value); |
|
900
|
2
|
50
|
|
|
|
13
|
}; |
|
901
|
|
|
|
|
|
|
|
|
902
|
0
|
|
|
|
|
0
|
error __x"illegal default_values mode `{mode}'", mode => $mode; |
|
903
|
|
|
|
|
|
|
} |
|
904
|
|
|
|
|
|
|
|
|
905
|
|
|
|
|
|
|
sub makeAttributeFixed |
|
906
|
6
|
|
|
6
|
0
|
15
|
{ my ($self, $path, $ns, $tag, $label, $do, $fixed) = @_; |
|
907
|
6
|
50
|
|
|
|
32
|
$fixed = $fixed->value if ref $fixed; |
|
908
|
|
|
|
|
|
|
|
|
909
|
5
|
|
|
5
|
|
7
|
sub { my ($doc, $value) = @_; |
|
910
|
5
|
100
|
|
|
|
12
|
defined $value or return (); |
|
911
|
|
|
|
|
|
|
|
|
912
|
4
|
100
|
|
|
|
13
|
$value eq $fixed |
|
913
|
|
|
|
|
|
|
or error __x"value of attribute `{tag}' is fixed to `{fixed}', not `{got}' at {path}" |
|
914
|
|
|
|
|
|
|
, tag => $tag, got => $value, fixed => $fixed, path => $path; |
|
915
|
|
|
|
|
|
|
|
|
916
|
3
|
|
|
|
|
21
|
$doc->createAttribute($tag, $fixed); |
|
917
|
6
|
|
|
|
|
37
|
}; |
|
918
|
|
|
|
|
|
|
} |
|
919
|
|
|
|
|
|
|
|
|
920
|
|
|
|
|
|
|
# any |
|
921
|
|
|
|
|
|
|
|
|
922
|
|
|
|
|
|
|
sub _split_any_list($$$) |
|
923
|
14
|
|
|
14
|
|
29
|
{ my ($path, $type, $v) = @_; |
|
924
|
14
|
50
|
|
|
|
70
|
my @nodes = ref $v eq 'ARRAY' ? @$v : defined $v ? $v : return ([], []); |
|
|
|
100
|
|
|
|
|
|
|
925
|
14
|
|
|
|
|
26
|
my (@attrs, @elems); |
|
926
|
|
|
|
|
|
|
|
|
927
|
14
|
|
|
|
|
25
|
foreach my $node (@nodes) |
|
928
|
14
|
50
|
|
|
|
47
|
{ UNIVERSAL::isa($node, 'XML::LibXML::Node') |
|
929
|
|
|
|
|
|
|
or error __x"elements for 'any' are XML::LibXML nodes, not {string} at {path}" |
|
930
|
|
|
|
|
|
|
, string => $node, path => $path; |
|
931
|
|
|
|
|
|
|
|
|
932
|
14
|
100
|
|
|
|
41
|
if($node->isa('XML::LibXML::Attr')) |
|
933
|
12
|
|
|
|
|
20
|
{ push @attrs, $node; |
|
934
|
12
|
|
|
|
|
24
|
next; |
|
935
|
|
|
|
|
|
|
} |
|
936
|
|
|
|
|
|
|
|
|
937
|
2
|
50
|
|
|
|
9
|
if($node->isa('XML::LibXML::Element')) |
|
938
|
2
|
|
|
|
|
4
|
{ push @elems, $node; |
|
939
|
2
|
|
|
|
|
5
|
next; |
|
940
|
|
|
|
|
|
|
} |
|
941
|
|
|
|
|
|
|
|
|
942
|
0
|
|
|
|
|
0
|
error __x"an XML::LibXML::Element or ::Attr is expected as 'any' or 'anyAttribute value with {type}, but a {kind} was found at {path}" |
|
943
|
|
|
|
|
|
|
, type => $type, kind => ref $node, path => $path; |
|
944
|
|
|
|
|
|
|
} |
|
945
|
|
|
|
|
|
|
|
|
946
|
14
|
|
|
|
|
51
|
return (\@attrs, \@elems); |
|
947
|
|
|
|
|
|
|
} |
|
948
|
|
|
|
|
|
|
|
|
949
|
|
|
|
|
|
|
sub makeAnyAttribute |
|
950
|
5
|
|
|
5
|
0
|
17
|
{ my ($self, $path, $handler, $yes, $no, $process) = @_; |
|
951
|
5
|
100
|
|
|
|
8
|
my %yes = map +($_ => 1), @{$yes || []}; |
|
|
5
|
|
|
|
|
27
|
|
|
952
|
5
|
100
|
|
|
|
10
|
my %no = map +($_ => 1), @{$no || []}; |
|
|
5
|
|
|
|
|
24
|
|
|
953
|
5
|
|
|
|
|
12
|
my $prefs = $self->{prefixes}; |
|
954
|
|
|
|
|
|
|
|
|
955
|
5
|
|
|
|
|
14
|
weaken $self; |
|
956
|
|
|
|
|
|
|
|
|
957
|
|
|
|
|
|
|
bless |
|
958
|
5
|
|
|
5
|
|
12
|
sub { my ($doc, $values) = @_; |
|
959
|
|
|
|
|
|
|
|
|
960
|
5
|
|
|
|
|
8
|
my @res; |
|
961
|
5
|
|
|
|
|
18
|
foreach my $label (sort keys %$values) |
|
962
|
10
|
|
|
|
|
17
|
{ my ($type, $ns, $local); |
|
963
|
10
|
50
|
|
|
|
27
|
if(substr($label, 0, 1) eq '{') |
|
|
|
0
|
|
|
|
|
|
|
964
|
10
|
|
|
|
|
21
|
{ ($ns, $local) = unpack_type $label; |
|
965
|
10
|
|
|
|
|
24
|
$type = $label; |
|
966
|
|
|
|
|
|
|
} |
|
967
|
|
|
|
|
|
|
elsif(index($label, ':') >= 0) |
|
968
|
0
|
|
|
|
|
0
|
{ (my $prefix, $local) = split ':', $label, 2; |
|
969
|
0
|
|
|
|
|
0
|
my $match = first {$_->{prefix} eq $prefix} values %$prefs; |
|
|
0
|
|
|
|
|
0
|
|
|
970
|
0
|
0
|
|
|
|
0
|
my $ns = $match ? $match->{uri} : undef; |
|
971
|
0
|
|
|
|
|
0
|
$type = pack_type $ns, $local; |
|
972
|
|
|
|
|
|
|
} |
|
973
|
0
|
|
|
|
|
0
|
else {next} # not fully qualified, not an 'any' |
|
974
|
|
|
|
|
|
|
|
|
975
|
10
|
100
|
100
|
|
|
30
|
$yes{$ns} or next if keys %yes; |
|
976
|
8
|
100
|
100
|
|
|
23
|
$no{$ns} and next if keys %no; |
|
977
|
|
|
|
|
|
|
|
|
978
|
6
|
50
|
|
|
|
16
|
my $value = delete $values->{$label} or next; |
|
979
|
6
|
|
|
|
|
14
|
my ($attrs, $elems) = _split_any_list $path, $type, $value; |
|
980
|
|
|
|
|
|
|
|
|
981
|
6
|
50
|
|
|
|
17
|
$values->{$type} = $elems if @$elems; |
|
982
|
6
|
50
|
|
|
|
13
|
@$attrs or next; |
|
983
|
|
|
|
|
|
|
|
|
984
|
6
|
|
|
|
|
16
|
foreach my $node (@$attrs) |
|
985
|
6
|
|
|
|
|
14
|
{ my $nodetype = type_of_node $node; |
|
986
|
6
|
50
|
|
|
|
22
|
next if $nodetype eq $type; |
|
987
|
|
|
|
|
|
|
|
|
988
|
0
|
|
|
|
|
0
|
error __x"provided 'anyAttribute' node has type {type}, but labeled with {other} at {path}" |
|
989
|
|
|
|
|
|
|
, type => $nodetype, other => $type, path => $path |
|
990
|
|
|
|
|
|
|
} |
|
991
|
|
|
|
|
|
|
|
|
992
|
6
|
|
|
|
|
19
|
push @res, @$attrs; |
|
993
|
|
|
|
|
|
|
} |
|
994
|
5
|
|
|
|
|
16
|
@res; |
|
995
|
5
|
|
|
|
|
70
|
}, 'ANY'; |
|
996
|
|
|
|
|
|
|
} |
|
997
|
|
|
|
|
|
|
|
|
998
|
|
|
|
|
|
|
sub makeAnyElement |
|
999
|
5
|
|
|
5
|
0
|
17
|
{ my ($self, $path, $handler, $yes, $no, $process, $min, $max) = @_; |
|
1000
|
5
|
100
|
|
|
|
10
|
my %yes = map +($_ => 1), @{$yes || []}; |
|
|
5
|
|
|
|
|
30
|
|
|
1001
|
5
|
100
|
|
|
|
9
|
my %no = map +($_ => 1), @{$no || []}; |
|
|
5
|
|
|
|
|
61
|
|
|
1002
|
5
|
|
|
|
|
29
|
my $prefs = $self->{prefixes}; |
|
1003
|
|
|
|
|
|
|
|
|
1004
|
5
|
|
100
|
|
|
24
|
$handler ||= 'SKIP_ALL'; |
|
1005
|
5
|
|
|
|
|
21
|
weaken $self; |
|
1006
|
|
|
|
|
|
|
|
|
1007
|
|
|
|
|
|
|
bless |
|
1008
|
5
|
|
|
5
|
|
16
|
sub { my ($doc, $values) = @_; |
|
1009
|
5
|
|
|
|
|
11
|
my @res; |
|
1010
|
|
|
|
|
|
|
|
|
1011
|
5
|
|
|
|
|
27
|
foreach my $label (sort keys %$values) |
|
1012
|
17
|
|
|
|
|
26
|
{ my ($type, $ns, $local); |
|
1013
|
17
|
100
|
|
|
|
53
|
if(substr($label, 0, 1) eq '{') |
|
|
|
100
|
|
|
|
|
|
|
1014
|
10
|
|
|
|
|
26
|
{ ($ns, $local) = unpack_type $label; |
|
1015
|
10
|
|
|
|
|
21
|
$type = $label; |
|
1016
|
|
|
|
|
|
|
} |
|
1017
|
|
|
|
|
|
|
elsif(index($label, ':') >= 0) |
|
1018
|
2
|
|
|
|
|
9
|
{ (my $prefix, $local) = split ':', $label, 2; |
|
1019
|
2
|
|
|
|
|
15
|
my $match = first {$_->{prefix} eq $prefix} values %$prefs; |
|
|
5
|
|
|
|
|
23
|
|
|
1020
|
2
|
50
|
|
|
|
13
|
$ns = $match ? $match->{uri} : undef; |
|
1021
|
2
|
|
|
|
|
8
|
$type = pack_type $ns, $local; |
|
1022
|
|
|
|
|
|
|
} |
|
1023
|
5
|
|
|
|
|
11
|
else {next} # not fully qualified, not an 'any' |
|
1024
|
|
|
|
|
|
|
|
|
1025
|
12
|
100
|
100
|
|
|
40
|
$yes{$ns} or next if keys %yes; |
|
1026
|
10
|
100
|
100
|
|
|
26
|
$no{$ns} and next if keys %no; |
|
1027
|
|
|
|
|
|
|
|
|
1028
|
8
|
50
|
|
|
|
33
|
my $value = delete $values->{$label} or next; |
|
1029
|
8
|
|
|
|
|
54
|
my ($attrs, $elems) = _split_any_list $path, $type, $value; |
|
1030
|
|
|
|
|
|
|
|
|
1031
|
8
|
100
|
|
|
|
26
|
$values->{$type} = $attrs if @$attrs; |
|
1032
|
8
|
100
|
|
|
|
23
|
@$elems or next; |
|
1033
|
|
|
|
|
|
|
|
|
1034
|
2
|
|
|
|
|
5
|
foreach my $node (@$elems) |
|
1035
|
2
|
|
|
|
|
10
|
{ my $nodens = $node->namespaceURI; |
|
1036
|
2
|
50
|
|
|
|
7
|
defined $nodens or next; # see README.todo work-around |
|
1037
|
|
|
|
|
|
|
|
|
1038
|
2
|
|
|
|
|
7
|
my $nodetype = type_of_node $node; |
|
1039
|
2
|
50
|
|
|
|
10
|
next if $nodetype eq $type; |
|
1040
|
|
|
|
|
|
|
|
|
1041
|
0
|
|
|
|
|
0
|
error __x"provided 'any' element node has type {type}, but labeled with {other} at {path}" |
|
1042
|
|
|
|
|
|
|
, type => $nodetype, other => $type, path => $path |
|
1043
|
|
|
|
|
|
|
} |
|
1044
|
|
|
|
|
|
|
|
|
1045
|
2
|
|
|
|
|
6
|
push @res, @$elems; |
|
1046
|
2
|
50
|
33
|
|
|
19
|
$max eq 'unbounded' || @res <= $max |
|
1047
|
|
|
|
|
|
|
or error __x"too many 'any' elements after consuming {count} nodes of {type}, max {max} at {path}" |
|
1048
|
|
|
|
|
|
|
, count => scalar @$elems, type => $type |
|
1049
|
|
|
|
|
|
|
, max => $max, path => $path; |
|
1050
|
|
|
|
|
|
|
} |
|
1051
|
|
|
|
|
|
|
|
|
1052
|
5
|
50
|
|
|
|
21
|
@res >= $min |
|
1053
|
|
|
|
|
|
|
or error __x"too few 'any' elements, got {count} for minimum {min} at {path}" |
|
1054
|
|
|
|
|
|
|
, count => scalar @res, min => $min, path => $path; |
|
1055
|
|
|
|
|
|
|
|
|
1056
|
5
|
100
|
|
|
|
42
|
@res ? @res : undef; # empty, then "0 but true" |
|
1057
|
5
|
|
|
|
|
71
|
}, 'ANY'; |
|
1058
|
|
|
|
|
|
|
} |
|
1059
|
|
|
|
|
|
|
|
|
1060
|
|
|
|
|
|
|
# xsi:type handling |
|
1061
|
|
|
|
|
|
|
|
|
1062
|
|
|
|
|
|
|
sub makeXsiTypeSwitch($$$$) |
|
1063
|
3
|
|
|
3
|
0
|
12
|
{ my ($self, $where, $elem, $default_type, $types) = @_; |
|
1064
|
3
|
|
|
|
|
12
|
my $xsi = $self->_registerNSprefix(xsi => SCHEMA2001i, 1) . ':type'; |
|
1065
|
3
|
|
|
|
|
7
|
my %types; |
|
1066
|
3
|
|
|
|
|
23
|
foreach my $type (sort keys %$types) |
|
1067
|
6
|
|
|
|
|
17
|
{ my ($ns, $local) = unpack_type $type; |
|
1068
|
6
|
|
|
|
|
33
|
my $tag = $self->makeTagQualified($where, undef, $local, $ns); |
|
1069
|
|
|
|
|
|
|
|
|
1070
|
|
|
|
|
|
|
# register code under both prefixed and full type name |
|
1071
|
6
|
|
|
|
|
26
|
$types{$self->prefixed($type)} = $types{$type} = [$tag,$types->{$type}]; |
|
1072
|
|
|
|
|
|
|
} |
|
1073
|
|
|
|
|
|
|
|
|
1074
|
|
|
|
|
|
|
sub { |
|
1075
|
6
|
|
|
6
|
|
12
|
my ($doc, $values) = @_; |
|
1076
|
|
|
|
|
|
|
ref $values eq 'HASH' && $values->{XSI_TYPE} |
|
1077
|
6
|
50
|
33
|
|
|
34
|
or return $types{$default_type}[1]->(@_); |
|
1078
|
|
|
|
|
|
|
|
|
1079
|
6
|
|
|
|
|
28
|
my %v = %$values; |
|
1080
|
6
|
|
|
|
|
15
|
my $type = delete $v{XSI_TYPE}; |
|
1081
|
6
|
50
|
|
|
|
17
|
my $def = $types{$type} |
|
1082
|
|
|
|
|
|
|
or error __x"specified xsi:type list for `{default}' does not contain `{got}'" |
|
1083
|
|
|
|
|
|
|
, default => $default_type, got => $type; |
|
1084
|
|
|
|
|
|
|
|
|
1085
|
6
|
|
|
|
|
13
|
my ($t, $code) = @$def; |
|
1086
|
6
|
50
|
|
|
|
13
|
my $node = $code->($doc, \%v) |
|
1087
|
|
|
|
|
|
|
or return; |
|
1088
|
6
|
|
|
|
|
92
|
$node->setAttribute($xsi, $t); |
|
1089
|
6
|
|
|
|
|
76
|
$node; |
|
1090
|
3
|
|
|
|
|
38
|
}; |
|
1091
|
|
|
|
|
|
|
} |
|
1092
|
|
|
|
|
|
|
|
|
1093
|
|
|
|
|
|
|
sub makeHook($$$$$$$) |
|
1094
|
9
|
|
|
9
|
0
|
32
|
{ my ($self, $path, $r, $tag, $before, $replace, $after, $fulltype) = @_; |
|
1095
|
9
|
50
|
100
|
|
|
37
|
return $r unless $before || $replace || $after; |
|
|
|
|
66
|
|
|
|
|
|
1096
|
|
|
|
|
|
|
|
|
1097
|
9
|
|
|
|
|
15
|
my $do_replace; |
|
1098
|
9
|
100
|
|
|
|
21
|
if($replace) |
|
1099
|
1
|
50
|
|
1
|
|
11
|
{ return sub {()} if grep $_ eq 'SKIP', @$replace; |
|
|
1
|
|
|
|
|
3
|
|
|
1100
|
|
|
|
|
|
|
|
|
1101
|
|
|
|
|
|
|
# Input for replace is Perl, output is XML... so we cannot stack them |
|
1102
|
0
|
0
|
|
|
|
0
|
error __x"writer only supports one replace hook (for {type})" |
|
1103
|
|
|
|
|
|
|
, type => $fulltype |
|
1104
|
|
|
|
|
|
|
if @$replace > 1; |
|
1105
|
|
|
|
|
|
|
|
|
1106
|
0
|
|
|
|
|
0
|
$do_replace = $self->_decodeReplace($path, $replace->[0]); |
|
1107
|
|
|
|
|
|
|
} |
|
1108
|
|
|
|
|
|
|
|
|
1109
|
8
|
100
|
|
|
|
34
|
my @do_before = $before ? map $self->_decodeBefore($path,$_), @$before :(); |
|
1110
|
8
|
100
|
|
|
|
30
|
my @do_after = $after ? map $self->_decodeAfter($path,$_), @$after :(); |
|
1111
|
|
|
|
|
|
|
|
|
1112
|
|
|
|
|
|
|
sub |
|
1113
|
8
|
|
|
8
|
|
18
|
{ my ($doc, $val) = @_; |
|
1114
|
8
|
50
|
|
|
|
22
|
defined $val or return; |
|
1115
|
8
|
|
|
|
|
16
|
foreach (@do_before) |
|
1116
|
6
|
|
|
|
|
20
|
{ $val = $_->($doc, $val, $path, $fulltype); |
|
1117
|
6
|
50
|
|
|
|
4962
|
defined $val or return (); |
|
1118
|
|
|
|
|
|
|
} |
|
1119
|
|
|
|
|
|
|
|
|
1120
|
8
|
50
|
|
|
|
32
|
my $xml = $do_replace |
|
1121
|
|
|
|
|
|
|
? $do_replace->($doc, $val, $path, $tag, $r, $fulltype) |
|
1122
|
|
|
|
|
|
|
: $r->($doc, $val); |
|
1123
|
8
|
50
|
|
|
|
76
|
defined $xml or return (); |
|
1124
|
|
|
|
|
|
|
|
|
1125
|
8
|
|
|
|
|
19
|
foreach (@do_after) |
|
1126
|
5
|
|
|
|
|
14
|
{ $xml = $_->($doc, $xml, $path, $val, $fulltype); |
|
1127
|
5
|
50
|
|
|
|
25
|
defined $xml or return (); |
|
1128
|
|
|
|
|
|
|
} |
|
1129
|
|
|
|
|
|
|
|
|
1130
|
8
|
|
|
|
|
16
|
$xml; |
|
1131
|
8
|
|
|
|
|
59
|
}; |
|
1132
|
|
|
|
|
|
|
} |
|
1133
|
|
|
|
|
|
|
|
|
1134
|
|
|
|
|
|
|
sub _decodeBefore($$) |
|
1135
|
6
|
|
|
6
|
|
19
|
{ my ($self, $path, $call) = @_; |
|
1136
|
6
|
50
|
|
|
|
30
|
return $call if ref $call eq 'CODE'; |
|
1137
|
|
|
|
|
|
|
|
|
1138
|
|
|
|
|
|
|
# $code->($doc, $values, $path) |
|
1139
|
0
|
|
|
0
|
|
0
|
$call eq 'PRINT_PATH' ? sub { print "$_[2]\n"; $_[1] } |
|
|
0
|
|
|
|
|
0
|
|
|
1140
|
0
|
0
|
|
|
|
0
|
: error __x"labeled before hook `{name}' undefined for WRITER", name=>$call; |
|
1141
|
|
|
|
|
|
|
} |
|
1142
|
|
|
|
|
|
|
|
|
1143
|
|
|
|
|
|
|
sub _decodeReplace($$) |
|
1144
|
0
|
|
|
0
|
|
0
|
{ my ($self, $path, $call) = @_; |
|
1145
|
0
|
0
|
|
|
|
0
|
return $call if ref $call eq 'CODE'; |
|
1146
|
|
|
|
|
|
|
|
|
1147
|
|
|
|
|
|
|
# SKIP already handled |
|
1148
|
|
|
|
|
|
|
# $replace->($doc, $val, $path, $tag, $replaced) |
|
1149
|
0
|
|
|
|
|
0
|
error __x"labeled replace hook `{name}' undefined for WRITER", name=>$call; |
|
1150
|
|
|
|
|
|
|
} |
|
1151
|
|
|
|
|
|
|
|
|
1152
|
|
|
|
|
|
|
sub _decodeAfter($$) |
|
1153
|
5
|
|
|
5
|
|
9
|
{ my ($self, $path, $call) = @_; |
|
1154
|
5
|
100
|
|
|
|
18
|
return $call if ref $call eq 'CODE'; |
|
1155
|
|
|
|
|
|
|
|
|
1156
|
1
|
|
|
1
|
|
7
|
$call eq 'PRINT_PATH' ? sub { print "$_[2]\n"; $_[1] } |
|
|
1
|
|
|
|
|
3
|
|
|
1157
|
1
|
50
|
|
|
|
8
|
: error __x"labeled after hook `{name}' undefined for WRITER", name=>$call; |
|
1158
|
|
|
|
|
|
|
} |
|
1159
|
|
|
|
|
|
|
|
|
1160
|
|
|
|
|
|
|
sub makeBlocked($$$) |
|
1161
|
19
|
|
|
19
|
0
|
68
|
{ my ($self, $where, $class, $type) = @_; |
|
1162
|
19
|
|
|
|
|
88
|
my $err_type = $self->prefixed($type); |
|
1163
|
|
|
|
|
|
|
|
|
1164
|
|
|
|
|
|
|
# errors are produced in class=misfit to allow other choices to succeed. |
|
1165
|
|
|
|
|
|
|
$class eq 'anyType' |
|
1166
|
4
|
|
|
4
|
|
18
|
? { st => sub { error __x"use of `{type}' blocked at {where}" |
|
1167
|
|
|
|
|
|
|
, type => $err_type, where => $where, _class => 'misfit'; |
|
1168
|
|
|
|
|
|
|
}} |
|
1169
|
|
|
|
|
|
|
: $class eq 'simpleType' |
|
1170
|
2
|
|
|
2
|
|
12
|
? { st => sub { error __x"use of {class} `{type}' blocked at {where}" |
|
1171
|
|
|
|
|
|
|
, class => $class, type => $err_type, where => $where |
|
1172
|
|
|
|
|
|
|
, _class => 'misfit'; |
|
1173
|
|
|
|
|
|
|
}} |
|
1174
|
|
|
|
|
|
|
: $class eq 'complexType' |
|
1175
|
|
|
|
|
|
|
? { elems => [] } |
|
1176
|
|
|
|
|
|
|
: $class eq 'ref' |
|
1177
|
0
|
|
|
0
|
|
0
|
? { st => sub { error __x"use of referenced `{type}' blocked at {where}" |
|
1178
|
|
|
|
|
|
|
, type => $err_type, where => $where, _class => 'misfit'; |
|
1179
|
|
|
|
|
|
|
}} |
|
1180
|
19
|
50
|
|
|
|
241
|
: panic "blocking of $class for $type not implemented"; |
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
1181
|
|
|
|
|
|
|
} |
|
1182
|
|
|
|
|
|
|
|
|
1183
|
|
|
|
|
|
|
sub addTypeAttribute($$) |
|
1184
|
1
|
|
|
1
|
0
|
3
|
{ my ($self, $type, $do) = @_; |
|
1185
|
1
|
|
|
|
|
4
|
my $xsi = $self->_registerNSprefix(xsi => SCHEMA2001i, 1) . ':type'; |
|
1186
|
1
|
|
|
|
|
3
|
my $xsd = $self->_registerNSprefix(xsd => SCHEMA2001, 1); |
|
1187
|
1
|
|
|
|
|
3
|
my $typed = $self->prefixed($type); |
|
1188
|
|
|
|
|
|
|
|
|
1189
|
|
|
|
|
|
|
sub { |
|
1190
|
1
|
|
|
1
|
|
3
|
my $r = $do->(@_); |
|
1191
|
1
|
50
|
33
|
|
|
6
|
$type && $r && UNIVERSAL::isa($r, 'XML::LibXML::Element') or return $r; |
|
|
|
|
33
|
|
|
|
|
|
1192
|
1
|
50
|
|
|
|
40
|
return $r if $r->getAttributeNS(SCHEMA2001i, 'type'); |
|
1193
|
1
|
|
|
|
|
24
|
$r->setAttribute($xsi, $typed); |
|
1194
|
1
|
|
|
|
|
17
|
$r; |
|
1195
|
1
|
|
|
|
|
6
|
}; |
|
1196
|
|
|
|
|
|
|
} |
|
1197
|
|
|
|
|
|
|
|
|
1198
|
|
|
|
|
|
|
#------------ |
|
1199
|
|
|
|
|
|
|
|
|
1200
|
|
|
|
|
|
|
1; |