line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#============================================================= -*-perl-*- |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# XML::Schema::Wildcard.pm |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# DESCRIPTION |
6
|
|
|
|
|
|
|
# Module implementing an object to represent wildcards. A wildcard |
7
|
|
|
|
|
|
|
# allows for specification and validation of items based on their |
8
|
|
|
|
|
|
|
# namespace rather than any local definition. |
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
# AUTHOR |
11
|
|
|
|
|
|
|
# Andy Wardley |
12
|
|
|
|
|
|
|
# |
13
|
|
|
|
|
|
|
# COPYRIGHT |
14
|
|
|
|
|
|
|
# Copyright (C) 2001 Canon Research Centre Europe Ltd. |
15
|
|
|
|
|
|
|
# All Rights Reserved. |
16
|
|
|
|
|
|
|
# |
17
|
|
|
|
|
|
|
# This module is free software; you can redistribute it and/or |
18
|
|
|
|
|
|
|
# modify it under the same terms as Perl itself. |
19
|
|
|
|
|
|
|
# |
20
|
|
|
|
|
|
|
# REVISION |
21
|
|
|
|
|
|
|
# $Id: Wildcard.pm,v 1.1 2001/12/20 13:26:27 abw Exp $ |
22
|
|
|
|
|
|
|
# |
23
|
|
|
|
|
|
|
#======================================================================== |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
package XML::Schema::Wildcard; |
26
|
|
|
|
|
|
|
|
27
|
2
|
|
|
2
|
|
570
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
80
|
|
28
|
|
|
|
|
|
|
|
29
|
2
|
|
|
2
|
|
12
|
use XML::Schema::Base; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
58
|
|
30
|
|
|
|
|
|
|
|
31
|
2
|
|
|
2
|
|
11
|
use base qw( XML::Schema::Base ); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
182
|
|
32
|
2
|
|
|
2
|
|
401
|
use XML::Schema::Constants qw( :wildcard ); |
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
364
|
|
33
|
2
|
|
|
2
|
|
13
|
use vars qw( $VERSION $DEBUG $ERROR @MANDATORY @OPTIONAL ); |
|
2
|
|
|
|
|
13
|
|
|
2
|
|
|
|
|
1515
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
$VERSION = sprintf("%d.%02d", q$Revision: 1.1 $ =~ /(\d+)\.(\d+)/); |
36
|
|
|
|
|
|
|
$DEBUG = 0 unless defined $DEBUG; |
37
|
|
|
|
|
|
|
$ERROR = ''; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# @MANDATORY = qw( name ); |
40
|
|
|
|
|
|
|
@OPTIONAL = qw( annotation ); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
44
|
|
|
|
|
|
|
# build regexen to match valid process values |
45
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
my @PROCESS_OPTS = ( SKIP, LAX, STRICT ); |
48
|
|
|
|
|
|
|
my $PROCESS_REGEX = join('|', @PROCESS_OPTS); |
49
|
|
|
|
|
|
|
$PROCESS_REGEX = qr/^$PROCESS_REGEX$/; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
54
|
|
|
|
|
|
|
# init() |
55
|
|
|
|
|
|
|
# |
56
|
|
|
|
|
|
|
# Initiliasation method called by base class new() constructor. |
57
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub init { |
60
|
27
|
|
|
27
|
1
|
46
|
my ($self, $config) = @_; |
61
|
27
|
|
|
|
|
31
|
my ($namespace, $select, $process); |
62
|
|
|
|
|
|
|
|
63
|
27
|
50
|
|
|
|
76
|
$self->init_mandopt($config) |
64
|
|
|
|
|
|
|
|| return; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# look for the various options which can be used to specify |
67
|
|
|
|
|
|
|
# the namespace(s) |
68
|
|
|
|
|
|
|
|
69
|
27
|
100
|
100
|
|
|
212
|
if ($config->{ any } || $config->{ namespace } |
|
|
100
|
66
|
|
|
|
|
|
|
100
|
|
|
|
|
|
70
|
|
|
|
|
|
|
&& $config->{ namespace } eq ANY) { |
71
|
7
|
|
|
|
|
15
|
$select = ANY; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
elsif ($namespace = $config->{ not }) { |
74
|
1
|
|
|
|
|
2
|
$select = NOT; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
elsif ($namespace = $config->{ namespace }) { |
77
|
18
|
100
|
|
|
|
62
|
$namespace = [ $namespace ] unless ref $namespace eq 'ARRAY'; |
78
|
18
|
100
|
|
|
|
85
|
if ($namespace->[0] eq NOT) { |
79
|
5
|
|
|
|
|
9
|
($select, $namespace) = @$namespace; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
else { |
82
|
13
|
|
|
|
|
17
|
$select = ONE; |
83
|
13
|
|
|
|
|
21
|
$namespace = { map { ($_, 1) } @$namespace }; |
|
14
|
|
|
|
|
44
|
|
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
else { |
87
|
1
|
|
|
|
|
5
|
return $self->error('no namespace specified'); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# determine or default the process mode |
91
|
26
|
|
100
|
|
|
106
|
$process = $config->{ process } || SKIP; |
92
|
26
|
100
|
|
|
|
169
|
return $self->error_value('wildcard process', $process, @PROCESS_OPTS) |
93
|
|
|
|
|
|
|
unless $process =~ $PROCESS_REGEX; |
94
|
|
|
|
|
|
|
|
95
|
25
|
|
|
|
|
45
|
$self->{ select } = $select; |
96
|
25
|
|
|
|
|
39
|
$self->{ process } = $process; |
97
|
25
|
|
|
|
|
34
|
$self->{ namespace } = $namespace; |
98
|
|
|
|
|
|
|
|
99
|
25
|
50
|
|
|
|
45
|
$self->DEBUG("wildcard [$select] [$namespace] [$process]\n") if $DEBUG; |
100
|
|
|
|
|
|
|
|
101
|
25
|
|
|
|
|
176
|
return $self; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub select { |
106
|
9
|
|
|
9
|
0
|
14
|
my $self = shift; |
107
|
9
|
|
|
|
|
36
|
return $self->{ select }; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub process { |
111
|
1
|
|
|
1
|
0
|
6
|
my $self = shift; |
112
|
1
|
|
|
|
|
6
|
return $self->{ process }; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub namespace { |
117
|
5
|
|
|
5
|
0
|
9
|
my $self = shift; |
118
|
5
|
|
|
|
|
23
|
return $self->{ namespace }; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
123
|
|
|
|
|
|
|
# accept($value) |
124
|
|
|
|
|
|
|
# |
125
|
|
|
|
|
|
|
# Return a true (1) or false (0) value depending on whether or not the |
126
|
|
|
|
|
|
|
# namespace of the item passed as $value is acceptable according to the |
127
|
|
|
|
|
|
|
# defined namespace contraints for the wildcard. |
128
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub accept { |
131
|
128
|
|
|
128
|
0
|
186
|
my ($self, $value) = @_; |
132
|
128
|
|
|
|
|
115
|
my $namespace; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
# anything goes? |
135
|
128
|
|
|
|
|
178
|
my $select = $self->{ select }; |
136
|
128
|
100
|
|
|
|
308
|
return 1 if $select eq ANY; |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
# extract namespace from candidate |
139
|
106
|
|
|
|
|
475
|
$value =~ s/^(?:([a-zA-Z_][\w\-.]*):)?(.*)$/$2/; |
140
|
106
|
|
|
|
|
187
|
$namespace = $1; |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
# denied? |
143
|
106
|
100
|
|
|
|
205
|
if ($select eq NOT) { |
144
|
21
|
|
|
|
|
127
|
my $own = $self->{ namespace }; |
145
|
21
|
100
|
|
|
|
32
|
if ($own) { |
146
|
15
|
100
|
100
|
|
|
316
|
return 1 if ! $namespace || $namespace ne $own; |
147
|
3
|
|
|
|
|
14
|
return 0; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
else { |
150
|
6
|
100
|
|
|
|
28
|
return defined $namespace ? 1 : 0; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
# assume select = ONE |
155
|
85
|
100
|
|
|
|
286
|
return 0 unless $namespace; |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
$self->DEBUG("matching [$namespace] against [", |
158
|
53
|
50
|
|
|
|
103
|
join(', ', keys %{ $self->{ namespace } }), "]\n") |
|
0
|
|
|
|
|
0
|
|
159
|
|
|
|
|
|
|
if $DEBUG; |
160
|
|
|
|
|
|
|
|
161
|
53
|
100
|
|
|
|
290
|
return $self->{ namespace }->{ $namespace } ? 1 : 0; |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
1; |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
__END__ |