lib/XML/Schema/Wildcard.pm

filter: Statementstmt 98.4% 64 / 65 Branchbran 88.2% 30 / 34 Conditioncond 100% 11 / 11 MC/DCmcdc 100% 6 / 6 Subroutinesub 100% 10 / 10 Podpod 20.0% 1 / 5 totaltotal 93.1% 122 / 131 CC 21 SCAR 21.3
CC
21
Cov
95%
init
12.0
accept
10.0
BEGIN
1.0
CRAP 8.4
« blib/lib/XML/Schema/Handler/Schema.pm ↑ Summary lib/XML/Schema/Scoped.pm »
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 <abw@kfs.org>
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 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 2 ▶use XML::Schema::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 2 ▶use base qw( XML::Schema::Base );
Subroutine BEGIN: called CC=1 SCAR=0.0
32 2 ▶use XML::Schema::Constants qw( :wildcard );
Subroutine BEGIN: called CC=1 SCAR=0.0
33 2 ▶use vars qw( $VERSION $DEBUG $ERROR @MANDATORY @OPTIONAL );
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 2 $VERSION = sprintf("%d.%02d", q$Revision: 1.1 $ =~ /(\d+)\.(\d+)/);
36 2 ▶$DEBUG = 0 unless defined $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $XML::Schema::Wildcard::DEBUG 2 0 2
37 2 $ERROR = '';
38  
39 # @MANDATORY = qw( name );
40 2 @OPTIONAL = qw( annotation );
41  
42  
43 #------------------------------------------------------------------------
44 # build regexen to match valid process values
45 #------------------------------------------------------------------------
46  
47 2 my @PROCESS_OPTS = ( SKIP, LAX, STRICT );
48 2 my $PROCESS_REGEX = join('|', @PROCESS_OPTS);
49 2 $PROCESS_REGEX = qr/^$PROCESS_REGEX$/;
50  
51  
52  
53 #------------------------------------------------------------------------
54 # init()
55 #
56 # Initiliasation method called by base class new() constructor.
57 #------------------------------------------------------------------------
58  
59 27 ▶sub init {
Subroutine init: called CC=12 SCAR=24.9
Pod documented
60 27 my ($self, $config) = @_;
61 27 my ($namespace, $select, $process);
62  
63 27 ▶ $self->init_mandopt($config)
Branch: 1 branch
BranchTrueFalseTotal
$self->init_mandopt($config) or return 27 0 27
64 || return;
65  
66 # look for the various options which can be used to specify
67 # the namespace(s)
68  
69 27 ▶ if ($config->{ any } || $config->{ namespace }
Branch: 3 branches
BranchTrueFalseTotal
if ($config->{'any'} or $config->{'namespace'} and $config->{'namespace'} eq 'any') { } 7 20 27
elsif ($namespace = $config->{'not'}) { } 1 19 20
elsif ($namespace = $config->{'namespace'}) { } 18 1 19
Condition100%6/6
$config->{"any"} or $config->{"namespace"} and $config->{"namespace"} eq "any"
l!l&&r!l&&!r
4320
$config->{"namespace"} and $config->{"namespace"} eq "any"
!ll&&!rl&&r
2183
MC/DC100%3/3
$config->{"any"} or $config->{"namespace"} and $config->{"namespace"} eq "any"
$config->{"any"} $config->{"namespace"} $config->{"namespace"} eq "any"
Truth table100%4/4
A or B and C
A= $config->{"any"}B= $config->{"namespace"}C= $config->{"namespace"} eq "any"
ABCresult
1XX1
0111
00X0
0100
70 && $config->{ namespace } eq ANY) {
71 7 $select = ANY;
72 }
73 elsif ($namespace = $config->{ not }) {
74 1 $select = NOT;
75 }
76 elsif ($namespace = $config->{ namespace }) {
77 18 ▶ $namespace = [ $namespace ] unless ref $namespace eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $namespace eq "ARRAY" 15 3 18
78 18 ▶ if ($namespace->[0] eq NOT) {
Branch: 1 branch
BranchTrueFalseTotal
if ($namespace->[0] eq 'not') { } 5 13 18
79 5 ($select, $namespace) = @$namespace;
80 }
81 else {
82 13 $select = ONE;
83 13 $namespace = { map { ($_, 1) } @$namespace };
84 }
85 }
86 else {
87 1 return $self->error('no namespace specified');
88 }
89  
90 # determine or default the process mode
91 26 ▶ $process = $config->{ process } || SKIP;
Condition100%2/2
$config->{'process'} || 'skip'
l!l
224
MC/DC100%1/1
$config->{'process'} || 'skip'
$config->{'process'}
Truth table100%2/2
A
A= $config->{'process'}
Aresult
11
00
92 26 ▶ return $self->error_value('wildcard process', $process, @PROCESS_OPTS)
Branch: 1 branch
BranchTrueFalseTotal
unless $process =~ /$PROCESS_REGEX/ 1 25 26
93 unless $process =~ $PROCESS_REGEX;
94  
95 25 $self->{ select } = $select;
96 25 $self->{ process } = $process;
97 25 $self->{ namespace } = $namespace;
98  
99 25 ▶ $self->DEBUG("wildcard [$select] [$namespace] [$process]\n") if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $XML::Schema::Wildcard::DEBUG 0 25 25
100  
101 25 return $self;
102 }
103  
104  
105 9 ▶sub select {
Subroutine select: called CC=1 SCAR=0.0
Pod undocumented
106 9 my $self = shift;
107 9 return $self->{ select };
108 }
109  
110 1 ▶sub process {
Subroutine process: called CC=1 SCAR=0.0
Pod undocumented
111 1 my $self = shift;
112 1 return $self->{ process };
113 }
114  
115  
116 5 ▶sub namespace {
Subroutine namespace: called CC=1 SCAR=0.0
Pod undocumented
117 5 my $self = shift;
118 5 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 128 ▶sub accept {
Subroutine accept: called CC=10 SCAR=23.0
Pod undocumented
131 128 my ($self, $value) = @_;
132 128 my $namespace;
133  
134 # anything goes?
135 128 my $select = $self->{ select };
136 128 ▶ return 1 if $select eq ANY;
Branch: 1 branch
BranchTrueFalseTotal
if $select eq "any" 22 106 128
137  
138 # extract namespace from candidate
139 106 $value =~ s/^(?:([a-zA-Z_][\w\-.]*):)?(.*)$/$2/;
140 106 $namespace = $1;
141  
142 # denied?
143 106 ▶ if ($select eq NOT) {
Branch: 1 branch
BranchTrueFalseTotal
if ($select eq "not") 21 85 106
144 21 my $own = $self->{ namespace };
145 21 ▶ if ($own) {
Branch: 1 branch
BranchTrueFalseTotal
if ($own) { } 15 6 21
146 15 ▶ return 1 if ! $namespace || $namespace ne $own;
Branch: 1 branch
BranchTrueFalseTotal
if not $namespace or $namespace ne $own 12 3 15
Condition100%3/3
not $namespace or $namespace ne $own
l!l&&r!l&&!r
483
MC/DC100%2/2
not $namespace or $namespace ne $own
not $namespace $namespace ne $own
Truth table100%3/3
not(A) or B
A= not $namespaceB= $namespace ne $own
ABresult
1X1
011
000
147 3 return 0;
148 }
149 else {
150 6 ▶ return defined $namespace ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $namespace ? : 4 2 6
151 }
152 }
153
154 # assume select = ONE
155 85 ▶ return 0 unless $namespace;
Branch: 1 branch
BranchTrueFalseTotal
unless $namespace 32 53 85
156  
157 $self->DEBUG("matching [$namespace] against [",
158 0 ▶ join(', ', keys %{ $self->{ namespace } }), "]\n")
Branch: 1 branch
BranchTrueFalseTotal
if $XML::Schema::Wildcard::DEBUG 0 53 53
159 if $DEBUG;
160  
161 53 ▶ return $self->{ namespace }->{ $namespace } ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'namespace'}{$namespace} ? : 26 27 53
162 }
163  
164
165  
166  
167 2 1;
168  
169 __END__
« blib/lib/XML/Schema/Handler/Schema.pm ↑ Summary lib/XML/Schema/Scoped.pm »