| 1 | #============================================================= -*-perl-*- | ||||||||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||||||||
| 3 | # XML::Schema::Content.pm | ||||||||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||||||||
| 5 | # DESCRIPTION | ||||||||||||||||||||||||||||||||||
| 6 | # Module implementing a class to represent a content model being either | ||||||||||||||||||||||||||||||||||
| 7 | # 'empty', having a 'simple' type, or a pair of particle and model type, | ||||||||||||||||||||||||||||||||||
| 8 | # which can be one of 'mixed' or 'element-only'. | ||||||||||||||||||||||||||||||||||
| 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: Content.pm,v 1.1.1.1 2001/08/29 14:30:17 abw Exp $ | ||||||||||||||||||||||||||||||||||
| 22 | # | ||||||||||||||||||||||||||||||||||
| 23 | #======================================================================== | ||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||
| 25 | package XML::Schema::Content; | ||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||
| 27 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 28 | 9 | ▶ | use XML::Schema; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 29 | 9 | ▶ | use base qw( XML::Schema::Base ); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 30 | 9 | ▶ | use vars qw( $VERSION $DEBUG $ERROR $ETYPE @ARGS ); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||
| 32 | 9 | $VERSION = sprintf("%d.%02d", q$Revision: 1.1.1.1 $ =~ /(\d+)\.(\d+)/); | |||||||||||||||||||||||||||||||||
| 33 | 9 | ▶ | $DEBUG = 0 unless defined $DEBUG; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 34 | 9 | $ERROR = ''; | |||||||||||||||||||||||||||||||||
| 35 | 9 | $ETYPE = 'content'; | |||||||||||||||||||||||||||||||||
| 36 | 9 | @ARGS = qw( type content particle mixed empty ); | |||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||
| 38 | 9 | *FACTORY = \$XML::Schema::FACTORY; | |||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||
| 41 | # alias min() to minOccurs() and max() to maxOccurs() | ||||||||||||||||||||||||||||||||||
| 42 | 9 | *minOccurs = \&min; | |||||||||||||||||||||||||||||||||
| 43 | 9 | *maxOccurs = \&max; | |||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||
| 46 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||
| 47 | # init() | ||||||||||||||||||||||||||||||||||
| 48 | # | ||||||||||||||||||||||||||||||||||
| 49 | # Called automatically by base class new() method. | ||||||||||||||||||||||||||||||||||
| 50 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||
| 52 | 30 | ▶ | sub init { | ||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=10 SCAR=23.3
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 53 | 30 | my ($self, $config) = @_; | |||||||||||||||||||||||||||||||||
| 54 | 30 | my ($type, $content, $particle, $mixed); | |||||||||||||||||||||||||||||||||
| 55 | 30 | ▶ | my $factory = $self->{ FACTORY } ||= $config->{ FACTORY } || $XML::Schema::FACTORY; | ||||||||||||||||||||||||||||||||
|
Condition33%2/6
$self->{"FACTORY"} ||= $config->{"FACTORY"} || $XML::Schema::FACTORY
$config->{'FACTORY'} || $XML::Schema::FACTORY
MC/DC0%0/3
$self->{"FACTORY"} ||= $config->{"FACTORY"} || $XML::Schema::FACTORY
$self->{"FACTORY"}
$config->{'FACTORY'}
$XML::Schema::FACTORY
Truth table0%0/4
A ||= B || C
A= $self->{"FACTORY"}B= $config->{'FACTORY'}C= $XML::Schema::FACTORY
| |||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||
| 57 | 30 | ▶ | $self->TRACE("config => ", $config) if $DEBUG; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||
| 59 | 30 | $self->{ type } = undef; | |||||||||||||||||||||||||||||||||
| 60 | # if ($type = $config->{ type }) { | ||||||||||||||||||||||||||||||||||
| 61 | # # simple type content | ||||||||||||||||||||||||||||||||||
| 62 | # $self->{ type } = $type; | ||||||||||||||||||||||||||||||||||
| 63 | # $self->TRACE("set type to $type") if $DEBUG; | ||||||||||||||||||||||||||||||||||
| 64 | # } | ||||||||||||||||||||||||||||||||||
| 65 | # elsif ($particle = $config->{ particle }) { | ||||||||||||||||||||||||||||||||||
| 66 | 30 | ▶ | if ($particle = $config->{ particle }) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 67 | # particle specified directly, mixed flag also allowed | ||||||||||||||||||||||||||||||||||
| 68 | 4 | $self->{ particle } = $particle; | |||||||||||||||||||||||||||||||||
| 69 | 4 | ▶ | $self->{ mixed } = $config->{ mixed } ? 1 : 0; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||
| 71 | elsif (! $config->{ empty }) { | ||||||||||||||||||||||||||||||||||
| 72 | 14 | ▶ | if ($particle = $factory->create( particle => $config )) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 73 | # have a bash at creating a particle anyway | ||||||||||||||||||||||||||||||||||
| 74 | 9 | $self->{ particle } = $particle; | |||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||
| 76 | else { | ||||||||||||||||||||||||||||||||||
| 77 | 5 | my $error = $factory->error(); | |||||||||||||||||||||||||||||||||
| 78 | # HACK: this might be an empty/text only content model so | ||||||||||||||||||||||||||||||||||
| 79 | # we ignore particle errors that report a missing particle | ||||||||||||||||||||||||||||||||||
| 80 | 5 | ▶ | return $self->error($error) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 81 | unless $error =~ /^particle expects one of:/; | ||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||
| 85 | 28 | ▶ | $self->{ mixed } = $config->{ mixed } ? 1 : 0; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||
| 87 | 28 | return $self; | |||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||
| 90 | 15 | ▶ | sub model { | ||||||||||||||||||||||||||||||||
|
Subroutine
model: called CC=3 SCAR=11.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 91 | 15 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 92 | return $self->{ type } | ||||||||||||||||||||||||||||||||||
| 93 | || $self->{ particle } | ||||||||||||||||||||||||||||||||||
| 94 | 15 | ▶ | || $self->error("no particle defined in content model"); | ||||||||||||||||||||||||||||||||
|
Condition66%4/6
$self->{'type'} || $self->{'particle'} || $self->error('no particle defined in content model')
$self->{"type"} or $self->{"particle"}
MC/DC33%1/3
$self->{'type'} || $self->{'particle'} || $self->error('no particle defined in content model')
$self->{"type"}
$self->{"particle"}
$self->error('no particle defined in content model')
Truth table50%2/4
A or B || C
A= $self->{"type"}B= $self->{"particle"}C= $self->error('no particle defined in content model')
| |||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||
| 97 | 6 | ▶ | sub type { | ||||||||||||||||||||||||||||||||
|
Subroutine
type: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 98 | 6 | return $_[0]->{ type }; | |||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||
| 101 | 15 | ▶ | sub particle { | ||||||||||||||||||||||||||||||||
|
Subroutine
particle: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 102 | 15 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 103 | return $self->{ particle } | ||||||||||||||||||||||||||||||||||
| 104 | 15 | ▶ | || $self->error("no particle defined in content model"); | ||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->{'particle'} || $self->error('no particle defined in content model')
MC/DC50%1/2
$self->{'particle'} || $self->error('no particle defined in content model')
$self->{'particle'}
$self->error('no particle defined in content model')
Truth table66%2/3
A || B
A= $self->{'particle'}B= $self->error('no particle defined in content model')
| |||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||
| 107 | 27 | ▶ | sub args { | ||||||||||||||||||||||||||||||||
|
Subroutine
args: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 108 | 27 | return @ARGS; | |||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||
| 111 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||
| 112 | # mixed($flag) | ||||||||||||||||||||||||||||||||||
| 113 | # | ||||||||||||||||||||||||||||||||||
| 114 | # Used to set (if called with an argument) or get the current value | ||||||||||||||||||||||||||||||||||
| 115 | # for the 'mixed' flag indicating if the complexType accepts mixed | ||||||||||||||||||||||||||||||||||
| 116 | # content. | ||||||||||||||||||||||||||||||||||
| 117 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||
| 119 | 25 | ▶ | sub mixed { | ||||||||||||||||||||||||||||||||
|
Subroutine
mixed: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 120 | 25 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 121 | 25 | ▶ | return @_ ? ($self->{ mixed } = shift) : $self->{ mixed }; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||
| 125 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||
| 126 | # element_only($flag) | ||||||||||||||||||||||||||||||||||
| 127 | # | ||||||||||||||||||||||||||||||||||
| 128 | # The inverse of mixed(). Returns true if mixed is false and vice | ||||||||||||||||||||||||||||||||||
| 129 | # verse. Can also be used to update the mixed flag wih the correct | ||||||||||||||||||||||||||||||||||
| 130 | # truth inversion performed. | ||||||||||||||||||||||||||||||||||
| 131 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||
| 133 | 5 | ▶ | sub element_only { | ||||||||||||||||||||||||||||||||
|
Subroutine
element_only: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 134 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 135 | 5 | ▶ | return @_ ? ! ($self->{ mixed } = ! shift) : ! $self->{ mixed }; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||
| 139 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||
| 140 | # empty() | ||||||||||||||||||||||||||||||||||
| 141 | # | ||||||||||||||||||||||||||||||||||
| 142 | # Returns true if the content model is empty. | ||||||||||||||||||||||||||||||||||
| 143 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||
| 145 | 8 | ▶ | sub empty { | ||||||||||||||||||||||||||||||||
|
Subroutine
empty: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 146 | 8 | ▶ | return ($_[0]->{ type } || $_[0]->{ particle }) ? 0 : 1; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$_[0]{"type"} or $_[0]{"particle"}
MC/DC50%1/2
$_[0]{"type"} or $_[0]{"particle"}
$_[0]{"type"}
$_[0]{"particle"}
Truth table66%2/3
A or B
A= $_[0]{"type"}B= $_[0]{"particle"}
| |||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | sub ID { | ||||||||||||||||||||||||||||||||
|
Subroutine
ID: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 151 | 0 | return 'Content'; | |||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||
| 154 | 9 | 1; | |||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||