File Coverage

lib/XML/Schema/Type/Union.pm
Criterion Covered Total %
statement 28 28 100.0
branch 6 6 100.0
condition 1 2 50.0
subroutine 6 6 100.0
pod 1 2 50.0
total 42 44 95.4


line stmt bran cond sub pod time code
1             #============================================================= -*-perl-*-
2             #
3             # XML::Schema::Type::Union
4             #
5             # DESCRIPTION
6             # Module implementing the XML Schema union datatype.
7             #
8             # AUTHOR
9             # Andy Wardley
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: Union.pm,v 1.1.1.1 2001/08/29 14:30:17 abw Exp $
20             #
21             #========================================================================
22              
23             package XML::Schema::Type::Union;
24              
25 28     28   145 use strict;
  28         53  
  28         923  
26 28     28   143 use XML::Schema::Type::Simple;
  28         71  
  28         596  
27 28     28   137 use base qw( XML::Schema::Type::Simple );
  28         46  
  28         2120  
28 28     28   172 use vars qw( $VERSION $DEBUG $ERROR @MANDATORY );
  28         58  
  28         11130  
29              
30             $VERSION = sprintf("%d.%02d", q$Revision: 1.1.1.1 $ =~ /(\d+)\.(\d+)/);
31             $DEBUG = 0 unless defined $DEBUG;
32             $ERROR = '';
33              
34             @MANDATORY = qw( memberTypes );
35              
36             sub init {
37 2     2 1 5 my ($self, $config) = @_;
38 2 100       11 $self->SUPER::init($config)
39             || return;
40 1         2 $self->{ _VARIETY } = 'union';
41 1         5 return $self;
42             }
43              
44             sub validate_instance {
45 7     7 0 8 my ($self, $infoset) = @_;
46              
47 7 100       49 $self->SUPER::validate_instance($infoset)
48             || return;
49              
50 6         9 my $value = $infoset->{ text };
51 6         8 my ($newval, @errors);
52              
53             my $members = $self->{ memberTypes }
54 6   50     12 || return $self->error('union has no memberTypes');
55              
56 6         14 foreach my $member (@$members) {
57 14         47 $newval = $member->instance($value);
58 14 100       25 if ($newval) {
59 4         5 $infoset->{ value } = $newval;
60 4         14 return 1;
61             }
62 10         37 push(@errors, $member->name() . ': ' . $member->error());
63             }
64 2         8 return $self->error("invalid union: ", join(', ', @errors));
65             }
66              
67             1;
68              
69             __END__