| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#============================================================= -*-perl-*- |
|
2
|
|
|
|
|
|
|
# |
|
3
|
|
|
|
|
|
|
# XML::Schema::Facet |
|
4
|
|
|
|
|
|
|
# |
|
5
|
|
|
|
|
|
|
# DESCRIPTION |
|
6
|
|
|
|
|
|
|
# Module implementing a base object class for representing XML |
|
7
|
|
|
|
|
|
|
# Schema facets. A facet is a mechanism for specifying optional |
|
8
|
|
|
|
|
|
|
# properties which constrain the value space of a datatype. |
|
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: Facet.pm,v 1.1.1.1 2001/08/29 14:30:17 abw Exp $ |
|
22
|
|
|
|
|
|
|
# |
|
23
|
|
|
|
|
|
|
#======================================================================== |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
package XML::Schema::Facet; |
|
26
|
|
|
|
|
|
|
|
|
27
|
28
|
|
|
28
|
|
161
|
use strict; |
|
|
28
|
|
|
|
|
48
|
|
|
|
28
|
|
|
|
|
987
|
|
|
28
|
28
|
|
|
28
|
|
133
|
use base qw( XML::Schema::Base ); |
|
|
28
|
|
|
|
|
46
|
|
|
|
28
|
|
|
|
|
2825
|
|
|
29
|
28
|
|
|
28
|
|
139
|
use vars qw( $VERSION $DEBUG $ERROR @MANDATORY @OPTIONAL ); |
|
|
28
|
|
|
|
|
53
|
|
|
|
28
|
|
|
|
|
25742
|
|
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
$VERSION = sprintf("%d.%02d", q$Revision: 1.1.1.1 $ =~ /(\d+)\.(\d+)/); |
|
32
|
|
|
|
|
|
|
$DEBUG = 0 unless defined $DEBUG; |
|
33
|
|
|
|
|
|
|
$ERROR = ''; |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
@MANDATORY = qw( value ); |
|
36
|
|
|
|
|
|
|
@OPTIONAL = qw( annotation name errmsg ); |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
|
40
|
|
|
|
|
|
|
# new() |
|
41
|
|
|
|
|
|
|
# |
|
42
|
|
|
|
|
|
|
# Specialised constructor which extracts the facet name from the last |
|
43
|
|
|
|
|
|
|
# element of the package name. e.g. for XML:Schema::Facet::minLength |
|
44
|
|
|
|
|
|
|
# the facet name is 'minLength'. The $NAME package variable may be |
|
45
|
|
|
|
|
|
|
# defined to override this behaviour and specify an alternate facet |
|
46
|
|
|
|
|
|
|
# name. |
|
47
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub new { |
|
50
|
306
|
|
|
306
|
1
|
478
|
my $class = shift; |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# make "new($n)" equivalent to "new(value => $n)" |
|
53
|
306
|
100
|
100
|
|
|
1461
|
unshift(@_, 'value') if @_ == 1 && ref $_[0] ne 'HASH'; |
|
54
|
|
|
|
|
|
|
|
|
55
|
306
|
|
|
|
|
1159
|
$class->SUPER::new(@_); |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub init { |
|
60
|
306
|
|
|
306
|
1
|
399
|
my ($self, $config) = @_; |
|
61
|
306
|
|
|
|
|
336
|
my ($mand, $option) = @{ $self->_baseargs( qw( @MANDATORY %OPTIONAL ) ) }; |
|
|
306
|
|
|
|
|
1018
|
|
|
62
|
|
|
|
|
|
|
|
|
63
|
306
|
100
|
|
|
|
1504
|
$self->_mandatory($mand, $config) |
|
64
|
|
|
|
|
|
|
|| return; |
|
65
|
|
|
|
|
|
|
|
|
66
|
303
|
50
|
|
|
|
1249
|
$self->_optional($option, $config) |
|
67
|
|
|
|
|
|
|
|| return; |
|
68
|
|
|
|
|
|
|
|
|
69
|
303
|
|
66
|
|
|
979
|
$self->{ name } ||= do { |
|
70
|
302
|
|
|
|
|
424
|
my $class = ref $self; |
|
71
|
302
|
|
|
|
|
1107
|
$class =~ /.*::(\w+)$/; |
|
72
|
302
|
|
|
|
|
1275
|
$1; |
|
73
|
|
|
|
|
|
|
}; |
|
74
|
|
|
|
|
|
|
|
|
75
|
303
|
|
|
|
|
1807
|
return $self; |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub install { |
|
80
|
234
|
|
|
234
|
0
|
359
|
my ($self, $facets, $table) = @_; |
|
81
|
|
|
|
|
|
|
# $self->DEBUG("installing $self into type as $self->{ name }\n"); |
|
82
|
234
|
|
|
|
|
374
|
push(@$facets, $self); |
|
83
|
234
|
|
|
|
|
775
|
$table->{ $self->{ name } } = $self; |
|
84
|
234
|
|
|
|
|
692
|
return 1; |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub name { |
|
88
|
6
|
|
|
6
|
0
|
22
|
my $self = shift; |
|
89
|
6
|
|
|
|
|
49
|
return $self->{ name }; |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub value { |
|
93
|
6
|
|
|
6
|
0
|
21
|
my $self = shift; |
|
94
|
6
|
|
|
|
|
53
|
return $self->{ value }; |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub annotation { |
|
98
|
3
|
|
|
3
|
0
|
3
|
my $self = shift; |
|
99
|
3
|
|
|
|
|
14
|
return $self->{ annotation }; |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub valid { |
|
103
|
2
|
|
|
2
|
0
|
3
|
my ($self, $instance, $type) = @_; |
|
104
|
2
|
|
|
|
|
8
|
return 1; |
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub invalid { |
|
108
|
61
|
|
|
61
|
0
|
115
|
my ($self, $msg) = @_; |
|
109
|
|
|
|
|
|
|
$self->error($self->{ errmsg } || |
|
110
|
61
|
|
66
|
|
|
406
|
"$msg (required $self->{ name }: $self->{ value })"); |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub accept { |
|
115
|
1
|
|
|
1
|
0
|
1
|
my ($self, $visitor) = @_; |
|
116
|
1
|
|
|
|
|
6
|
$visitor->visit_facet($self); |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
1; |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
__END__ |