| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%6/6
$config->{"any"} or $config->{"namespace"} and $config->{"namespace"} eq "any"
$config->{"namespace"} and $config->{"namespace"} eq "any"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 18 | ▶ | if ($namespace->[0] eq NOT) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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'
MC/DC100%1/1
$config->{'process'} || 'skip'
$config->{'process'}
Truth table100%2/2
A
A= $config->{'process'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 26 | ▶ | return $self->error_value('wildcard process', $process, @PROCESS_OPTS) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 21 | my $own = $self->{ namespace }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 21 | ▶ | if ($own) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 15 | ▶ | return 1 if ! $namespace || $namespace ne $own; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $namespace or $namespace ne $own
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 3 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 6 | ▶ | return defined $namespace ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | # assume select = ONE | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 85 | ▶ | return 0 unless $namespace; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | $self->DEBUG("matching [$namespace] against [", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | join(', ', keys %{ $self->{ namespace } }), "]\n") | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 53 | ▶ | return $self->{ namespace }->{ $namespace } ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||