| 1 | #============================================================= -*-perl-*- | |||||||||||||||||||||||||||||||
| 2 | # | |||||||||||||||||||||||||||||||
| 3 | # XML::Schema::Scoped | |||||||||||||||||||||||||||||||
| 4 | # | |||||||||||||||||||||||||||||||
| 5 | # DESCRIPTION | |||||||||||||||||||||||||||||||
| 6 | # Module implementing a mixin/base class for providing type | |||||||||||||||||||||||||||||||
| 7 | # management facilities by delegation to an enclosing scope. | |||||||||||||||||||||||||||||||
| 8 | # | |||||||||||||||||||||||||||||||
| 9 | # AUTHOR | |||||||||||||||||||||||||||||||
| 10 | # Andy Wardley <abw@kfs.org> | |||||||||||||||||||||||||||||||
| 11 | # | |||||||||||||||||||||||||||||||
| 12 | # COPYRIGHT | |||||||||||||||||||||||||||||||
| 13 | # Copyright (C) 2001 Canon Research Centre Europe Ltd. | |||||||||||||||||||||||||||||||
| 14 | # All Rights Reserved. | |||||||||||||||||||||||||||||||
| 15 | # | |||||||||||||||||||||||||||||||
| 16 | # This module is free software; you can redistribute it and/or | |||||||||||||||||||||||||||||||
| 17 | # modify it under the same terms as Perl itself. | |||||||||||||||||||||||||||||||
| 18 | # | |||||||||||||||||||||||||||||||
| 19 | # REVISION | |||||||||||||||||||||||||||||||
| 20 | # $Id: Scoped.pm,v 1.1.1.1 2001/08/29 14:30:17 abw Exp $ | |||||||||||||||||||||||||||||||
| 21 | # | |||||||||||||||||||||||||||||||
| 22 | #======================================================================== | |||||||||||||||||||||||||||||||
| 23 | ||||||||||||||||||||||||||||||||
| 24 | package XML::Schema::Scoped; | |||||||||||||||||||||||||||||||
| 25 | ||||||||||||||||||||||||||||||||
| 26 | 28 | ▶ | use strict; | |||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||
| 27 | 28 | ▶ | use XML::Schema; | |||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||
| 28 | 28 | ▶ | use base qw( XML::Schema::Base ); | |||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||
| 29 | 28 | ▶ | use vars qw( $VERSION $DEBUG $ERROR @MANDATORY @OPTIONAL ); | |||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||
| 30 | ||||||||||||||||||||||||||||||||
| 31 | 28 | $VERSION = sprintf("%d.%02d", q$Revision: 1.1.1.1 $ =~ /(\d+)\.(\d+)/); | ||||||||||||||||||||||||||||||
| 32 | 28 | ▶ | $DEBUG = 0 unless defined $DEBUG; | |||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||
| 33 | 28 | $ERROR = ''; | ||||||||||||||||||||||||||||||
| 34 | ||||||||||||||||||||||||||||||||
| 35 | 28 | @MANDATORY = qw( type ); | ||||||||||||||||||||||||||||||
| 36 | 28 | @OPTIONAL = qw( scope ); | ||||||||||||||||||||||||||||||
| 37 | ||||||||||||||||||||||||||||||||
| 38 | ||||||||||||||||||||||||||||||||
| 39 | #------------------------------------------------------------------------ | |||||||||||||||||||||||||||||||
| 40 | # init(\%config) | |||||||||||||||||||||||||||||||
| 41 | # | |||||||||||||||||||||||||||||||
| 42 | # Initialiser method called by base class new() constructor method. | |||||||||||||||||||||||||||||||
| 43 | #------------------------------------------------------------------------ | |||||||||||||||||||||||||||||||
| 44 | ||||||||||||||||||||||||||||||||
| 45 | 103 | ▶ | sub init { | |||||||||||||||||||||||||||||
|
Subroutine
init: called CC=5 SCAR=17.6
Pod
documented
| ||||||||||||||||||||||||||||||||
| 46 | 103 | my ($self, $config) = @_; | ||||||||||||||||||||||||||||||
| 47 | ||||||||||||||||||||||||||||||||
| 48 | my ($mand, $option) | |||||||||||||||||||||||||||||||
| 49 | 103 | = @{ $self->_baseargs( qw( @MANDATORY %OPTIONAL ) ) }; | ||||||||||||||||||||||||||||||
| 50 | ||||||||||||||||||||||||||||||||
| 51 | 103 | ▶ | $self->_mandatory($mand, $config) | |||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition60%3/5
@$mand && ($self->_mandatory($mand, $config) || (return))
$self->_mandatory($mand, $config) or return
MC/DC0%0/2
@$mand && ($self->_mandatory($mand, $config) || (return))
@$mand
$self->_mandatory($mand, $config)
Truth table33%1/3
A && B
A= @$mandB= $self->_mandatory($mand, $config)
| ||||||||||||||||||||||||||||||||
| 52 | || return if @$mand; | |||||||||||||||||||||||||||||||
| 53 | ||||||||||||||||||||||||||||||||
| 54 | 98 | ▶ | $self->_optional($option, $config) | |||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||
| 55 | || return; | |||||||||||||||||||||||||||||||
| 56 | ||||||||||||||||||||||||||||||||
| 57 | $self->{ _FACTORY } = $config->{ FACTORY } | |||||||||||||||||||||||||||||||
| 58 | 98 | ▶ | || $XML::Schema::FACTORY; | |||||||||||||||||||||||||||||
|
Condition33%1/3
$config->{'FACTORY'} || $XML::Schema::FACTORY
MC/DC0%0/2
$config->{'FACTORY'} || $XML::Schema::FACTORY
$config->{'FACTORY'}
$XML::Schema::FACTORY
Truth table33%1/3
A || B
A= $config->{'FACTORY'}B= $XML::Schema::FACTORY
| ||||||||||||||||||||||||||||||||
| 59 | ||||||||||||||||||||||||||||||||
| 60 | 98 | return $self; | ||||||||||||||||||||||||||||||
| 61 | } | |||||||||||||||||||||||||||||||
| 62 | ||||||||||||||||||||||||||||||||
| 63 | ||||||||||||||||||||||||||||||||
| 64 | #------------------------------------------------------------------------ | |||||||||||||||||||||||||||||||
| 65 | # type($name) | |||||||||||||||||||||||||||||||
| 66 | # | |||||||||||||||||||||||||||||||
| 67 | # Return current type object, querying current scope to retrieve | |||||||||||||||||||||||||||||||
| 68 | # object against a name if necessary. This effectively implements | |||||||||||||||||||||||||||||||
| 69 | # lazy evaluation of type names. In other words, it allows an element | |||||||||||||||||||||||||||||||
| 70 | # to specify that it uses type 'fooType' before that type is defined. | |||||||||||||||||||||||||||||||
| 71 | # The type() method provides the automatic resolution of type names to | |||||||||||||||||||||||||||||||
| 72 | # type objects by querying the scope object, i.e. the containing schema | |||||||||||||||||||||||||||||||
| 73 | # or complexType in which the 'fooType' should be defined. | |||||||||||||||||||||||||||||||
| 74 | #------------------------------------------------------------------------ | |||||||||||||||||||||||||||||||
| 75 | ||||||||||||||||||||||||||||||||
| 76 | 121 | ▶ | sub type { | |||||||||||||||||||||||||||||
|
Subroutine
type: called CC=12 SCAR=26.4
Pod
undocumented
| ||||||||||||||||||||||||||||||||
| 77 | 121 | my ($self, $name) = @_; | ||||||||||||||||||||||||||||||
| 78 | 121 | ▶ | $name = $self->{ type } unless defined $name; | |||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||
| 79 | ||||||||||||||||||||||||||||||||
| 80 | 121 | ▶ | $self->TRACE("name => ", $name) if $DEBUG; | |||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||
| 81 | ||||||||||||||||||||||||||||||||
| 82 | 121 | ▶ | return $self->error('no type name specified') | |||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||
| 83 | unless defined $name; | |||||||||||||||||||||||||||||||
| 84 | ||||||||||||||||||||||||||||||||
| 85 | # type may already be a type object | |||||||||||||||||||||||||||||||
| 86 | 121 | ▶ | return $name if ref $name; | |||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||
| 87 | ||||||||||||||||||||||||||||||||
| 88 | # delegate to any defined 'scope' if type not found | |||||||||||||||||||||||||||||||
| 89 | 100 | ▶ | if (my $scope = $self->{ scope }) { | |||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||
| 90 | 91 | ▶ | $self->TRACE("delegating $name to $scope\n") if $DEBUG; | |||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||
| 91 | ||||||||||||||||||||||||||||||||
| 92 | 91 | ▶ | return $scope->type($name) | |||||||||||||||||||||||||||||
|
Condition66%2/3
$scope->type($name) || $self->error($scope->error)
MC/DC50%1/2
$scope->type($name) || $self->error($scope->error)
$scope->type($name)
$self->error($scope->error)
Truth table66%2/3
A || B
A= $scope->type($name)B= $self->error($scope->error)
| ||||||||||||||||||||||||||||||||
| 93 | || $self->error($scope->error()); | |||||||||||||||||||||||||||||||
| 94 | } | |||||||||||||||||||||||||||||||
| 95 | ||||||||||||||||||||||||||||||||
| 96 | # otherwise look for it as a builtin simple type | |||||||||||||||||||||||||||||||
| 97 | my $factory = $self->{ _FACTORY } | |||||||||||||||||||||||||||||||
| 98 | 9 | ▶ | || return $self->error("no factory defined"); | |||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'_FACTORY'} || (return $self->error('no factory defined'))
MC/DC0%0/1
$self->{'_FACTORY'} || (return $self->error('no factory defined'))
$self->{'_FACTORY'}
Truth table50%1/2
A
A= $self->{'_FACTORY'}
| ||||||||||||||||||||||||||||||||
| 99 | ||||||||||||||||||||||||||||||||
| 100 | 9 | ▶ | my $simple = $factory->module('simple') | |||||||||||||||||||||||||||||
|
Condition50%1/2
$factory->module('simple') || (return $self->error($factory->error))
MC/DC0%0/1
$factory->module('simple') || (return $self->error($factory->error))
$factory->module('simple')
Truth table50%1/2
A
A= $factory->module('simple')
| ||||||||||||||||||||||||||||||||
| 101 | || return $self->error($factory->error()); | |||||||||||||||||||||||||||||||
| 102 | ||||||||||||||||||||||||||||||||
| 103 | 9 | ▶ | if (my $class = $simple->builtin($name)) { | |||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||
| 104 | 8 | ▶ | return $class->new() | |||||||||||||||||||||||||||||
|
Condition33%1/3
$class->new || $self->error($class->error)
MC/DC0%0/2
$class->new || $self->error($class->error)
$class->new
$self->error($class->error)
Truth table33%1/3
A || B
A= $class->newB= $self->error($class->error)
| ||||||||||||||||||||||||||||||||
| 105 | || $self->error($class->error()); | |||||||||||||||||||||||||||||||
| 106 | } | |||||||||||||||||||||||||||||||
| 107 | else { | |||||||||||||||||||||||||||||||
| 108 | 1 | return $self->error("no such type: $name"); | ||||||||||||||||||||||||||||||
| 109 | } | |||||||||||||||||||||||||||||||
| 110 | ||||||||||||||||||||||||||||||||
| 111 | # otherwise query scope | |||||||||||||||||||||||||||||||
| 112 | # my $scope = $self->{ scope } | |||||||||||||||||||||||||||||||
| 113 | # || return $self->error("no type definition scope defined"); | |||||||||||||||||||||||||||||||
| 114 | ||||||||||||||||||||||||||||||||
| 115 | # return $scope->type($name) | |||||||||||||||||||||||||||||||
| 116 | # || $self->error($scope->error()); | |||||||||||||||||||||||||||||||
| 117 | } | |||||||||||||||||||||||||||||||
| 118 | ||||||||||||||||||||||||||||||||
| 119 | ||||||||||||||||||||||||||||||||
| 120 | #------------------------------------------------------------------------ | |||||||||||||||||||||||||||||||
| 121 | # typename($name) | |||||||||||||||||||||||||||||||
| 122 | # | |||||||||||||||||||||||||||||||
| 123 | # Return name of current type object. If the type is already an object | |||||||||||||||||||||||||||||||
| 124 | # reference then its name() method is called, otherwise the type name | |||||||||||||||||||||||||||||||
| 125 | # is returned intact. | |||||||||||||||||||||||||||||||
| 126 | #------------------------------------------------------------------------ | |||||||||||||||||||||||||||||||
| 127 | ||||||||||||||||||||||||||||||||
| 128 | 10 | ▶ | sub typename { | |||||||||||||||||||||||||||||
|
Subroutine
typename: called CC=5 SCAR=16.6
Pod
undocumented
| ||||||||||||||||||||||||||||||||
| 129 | 10 | my ($self, $name) = @_; | ||||||||||||||||||||||||||||||
| 130 | 10 | ▶ | $name = $self->{ type } unless defined $name; | |||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||
| 131 | ||||||||||||||||||||||||||||||||
| 132 | 10 | ▶ | return $self->error('no type specified') | |||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||
| 133 | unless defined $name; | |||||||||||||||||||||||||||||||
| 134 | ||||||||||||||||||||||||||||||||
| 135 | # type may be an object ref | |||||||||||||||||||||||||||||||
| 136 | 10 | ▶ | $name = $name->name() if ref $name && UNIVERSAL::can($name, 'name'); | |||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $name and UNIVERSAL::can($name, "name")
MC/DC50%1/2
ref $name and UNIVERSAL::can($name, "name")
ref $name
UNIVERSAL::can($name, "name")
Truth table66%2/3
A and B
A= ref $nameB= UNIVERSAL::can($name, "name")
| ||||||||||||||||||||||||||||||||
| 137 | ||||||||||||||||||||||||||||||||
| 138 | 10 | return $name; | ||||||||||||||||||||||||||||||
| 139 | } | |||||||||||||||||||||||||||||||
| 140 | ||||||||||||||||||||||||||||||||
| 141 | ||||||||||||||||||||||||||||||||
| 142 | #------------------------------------------------------------------------ | |||||||||||||||||||||||||||||||
| 143 | # scope($newscope) | |||||||||||||||||||||||||||||||
| 144 | # | |||||||||||||||||||||||||||||||
| 145 | # Accessor method to retrieve the current scope object (when called | |||||||||||||||||||||||||||||||
| 146 | # without arguments) or to define a new scope object. The scope should | |||||||||||||||||||||||||||||||
| 147 | # be a reference to an object derived from the XML::Schema::Scope base | |||||||||||||||||||||||||||||||
| 148 | # class, ensuring it implements the facility to store and retrieve | |||||||||||||||||||||||||||||||
| 149 | # type objects (definitions) against names. | |||||||||||||||||||||||||||||||
| 150 | #------------------------------------------------------------------------ | |||||||||||||||||||||||||||||||
| 151 | ||||||||||||||||||||||||||||||||
| 152 | 3 | ▶ | sub scope { | |||||||||||||||||||||||||||||
|
Subroutine
scope: called CC=2 SCAR=7.2
Pod
undocumented
| ||||||||||||||||||||||||||||||||
| 153 | 3 | my $self = shift; | ||||||||||||||||||||||||||||||
| 154 | 3 | ▶ | return @_ ? ($self->{ scope } = shift) : $self->{ scope }; | |||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||
| 155 | } | |||||||||||||||||||||||||||||||
| 156 | ||||||||||||||||||||||||||||||||
| 157 | ||||||||||||||||||||||||||||||||
| 158 | 28 | 1; | ||||||||||||||||||||||||||||||
| 159 | ||||||||||||||||||||||||||||||||
| 160 | __END__ | |||||||||||||||||||||||||||||||