| 1 | #============================================================= -*-perl-*- | ||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||
| 3 | # XML::Schema::Handler::Simple.pm | ||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||
| 5 | # DESCRIPTION | ||||||||||||||||||||||||||||
| 6 | # Module implementing a parser handler for simple content. | ||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||
| 8 | # AUTHOR | ||||||||||||||||||||||||||||
| 9 | # Andy Wardley <abw@kfs.org> | ||||||||||||||||||||||||||||
| 10 | # | ||||||||||||||||||||||||||||
| 11 | # COPYRIGHT | ||||||||||||||||||||||||||||
| 12 | # Copyright (C) 2001 Canon Research Centre Europe Ltd. | ||||||||||||||||||||||||||||
| 13 | # All Rights Reserved. | ||||||||||||||||||||||||||||
| 14 | # | ||||||||||||||||||||||||||||
| 15 | # This module is free software; you can redistribute it and/or | ||||||||||||||||||||||||||||
| 16 | # modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 17 | # | ||||||||||||||||||||||||||||
| 18 | # REVISION | ||||||||||||||||||||||||||||
| 19 | # $Id: Simple.pm,v 1.1.1.1 2001/08/29 14:30:17 abw Exp $ | ||||||||||||||||||||||||||||
| 20 | # | ||||||||||||||||||||||||||||
| 21 | #======================================================================== | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | package XML::Schema::Handler::Simple; | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 1 | ▶ | use XML::Schema::Handler; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 1 | ▶ | use base qw( XML::Schema::Handler ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | 1 | ▶ | use vars qw( $VERSION $DEBUG $ERROR @SCHEDULES @MANDATORY ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 1 | $VERSION = sprintf("%d.%02d", q$Revision: 1.1.1.1 $ =~ /(\d+)\.(\d+)/); | |||||||||||||||||||||||||||
| 31 | 1 | ▶ | $DEBUG = 0 unless defined $DEBUG; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 1 | $ERROR = ''; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 1 | @MANDATORY = qw( type ); | |||||||||||||||||||||||||||
| 35 | 1 | @SCHEDULES = qw( instance ); | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 39 | # start_element($instance, $name, \%attr) | ||||||||||||||||||||||||||||
| 40 | # | ||||||||||||||||||||||||||||
| 41 | # Called at start tag. | ||||||||||||||||||||||||||||
| 42 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 4 | ▶ | sub start_element { | ||||||||||||||||||||||||||
|
Subroutine
start_element: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 45 | 4 | my ($self, $instance, $name, $attr) = @_; | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 4 | ▶ | $self->TRACE("<$name>") if $DEBUG; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 4 | $self->{ instance } = $instance; | |||||||||||||||||||||||||||
| 50 | 4 | $self->{ name } = $name; | |||||||||||||||||||||||||||
| 51 | 4 | $self->{ text } = ''; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 4 | ▶ | return $self->error("simple element type cannot contain attributes") | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$attr and %$attr
MC/DC50%1/2
$attr and %$attr
$attr
%$attr
Truth table66%2/3
A and B
A= $attrB= %$attr
| |||||||||||||||||||||||||||||
| 54 | if $attr && %$attr; | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 3 | return 1; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 61 | # start_child($instance, $name, $attr) | ||||||||||||||||||||||||||||
| 62 | # | ||||||||||||||||||||||||||||
| 63 | # Should not be called: simple content can have no elements. | ||||||||||||||||||||||||||||
| 64 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 1 | ▶ | sub start_child { | ||||||||||||||||||||||||||
|
Subroutine
start_child: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 67 | 1 | my ($self, $instance, $name, $attr) = @_; | |||||||||||||||||||||||||||
| 68 | 1 | ▶ | $self->TRACE("<$self->{ name }> <$name>") if $DEBUG; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 1 | $self->error("simple element type cannot contain child elements"); | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 74 | # end_child($instance, $name, $child) | ||||||||||||||||||||||||||||
| 75 | # | ||||||||||||||||||||||||||||
| 76 | # Should not be called: as above. | ||||||||||||||||||||||||||||
| 77 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | ▶ | sub end_child { | ||||||||||||||||||||||||||
|
Subroutine
end_child: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 80 | 0 | my ($self, $instance, $name) = @_; | |||||||||||||||||||||||||||
| 81 | 0 | ▶ | $self->TRACE("<$self->{ name }> </$name>") if $DEBUG; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 0 | $self->error("simple element type cannot contain child elements"); | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 87 | # text($instance, $text) | ||||||||||||||||||||||||||||
| 88 | # | ||||||||||||||||||||||||||||
| 89 | # Called to store character content. | ||||||||||||||||||||||||||||
| 90 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 3 | ▶ | sub text { | ||||||||||||||||||||||||||
|
Subroutine
text: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 93 | 3 | my ($self, $instance, $text) = @_; | |||||||||||||||||||||||||||
| 94 | 3 | ▶ | $self->TRACE("text => ", $self->_text_snippet($text)) if $DEBUG; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | 3 | $self->{ text } .= $text; | |||||||||||||||||||||||||||
| 96 | 3 | return 1; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 101 | # end_element($instance, $name) | ||||||||||||||||||||||||||||
| 102 | # | ||||||||||||||||||||||||||||
| 103 | # Called at end tag. Instantiates and returns a simple type instance. | ||||||||||||||||||||||||||||
| 104 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 3 | ▶ | sub end_element { | ||||||||||||||||||||||||||
|
Subroutine
end_element: called CC=5 SCAR=16.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 107 | 3 | my ($self, $instance, $name) = @_; | |||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 3 | ▶ | $self->TRACE("instance => $instance, name => $name") if $DEBUG; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | $self->throw($self->ID . " caught end of '$name' (expected $self->{ name })") | ||||||||||||||||||||||||||||
| 112 | 3 | ▶ | unless $name eq $self->{ name }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 3 | my $type = $self->{ type }; | |||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | # copy 'text' to 'value' for validation to assert | ||||||||||||||||||||||||||||
| 117 | 3 | $self->{ value } = $self->{ text }; | |||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 3 | ▶ | $type->validate_instance($self) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | || return $self->error($type->error()); | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | # copy 'value' to 'result' for scheduled actions to modify | ||||||||||||||||||||||||||||
| 123 | 2 | $self->{ result } = $self->{ value }; | |||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | # activate any type specific actions | ||||||||||||||||||||||||||||
| 126 | 2 | ▶ | $type->activate_instance($self) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | || return $self->error($type->error()); | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | # activate handler specific actions | ||||||||||||||||||||||||||||
| 130 | 2 | $self->activate_instance($self); | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 0 | ▶ | sub ID { | ||||||||||||||||||||||||||
|
Subroutine
ID: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 135 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 136 | 0 | return "Simple_Handler[$self->{ name }]"; | |||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 1 | 1; | |||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | __END__ | ||||||||||||||||||||||||||||