XMLSchema/HFP.pm untested

filter: Statementstmt 0.0% 0 / 77 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 19 Podpod 0.0% 0 / 10 totaltotal 0.0% 0 / 132 CC 9 SCAR 17.8
CC
9
Cov
0%
handle_start_hasProperty
12.0
name
12.0
name
12.0
CRAP 5.9
1 package Rinchi::XMLSchema::HFP;
2  
3 use 5.006;
4 use strict;
5 use FileHandle;
6 use strict;
7 use Carp;
8 use XML::Parser;
9 use Class::ISA;
10  
11 our @ISA = qw();
12  
13 our @EXPORT = qw();
14 our @EXPORT_OK = qw();
15  
16 our $VERSION = 0.01;
17  
18 =head1 NAME
19  
20 Rinchi::XMLSchema::HFP - Module for creating XML Schema objects.
21  
22 =head1 SYNOPSIS
23  
24 use Rinchi::XMLSchema;
25 use Rinchi::XMLSchema::HFP;
26 my $nsdef = Rinchi::HFP->namespace_def();
27 $nsdef->{'Prefix'} = 'hfp';
28 Rinchi::XMLSchema->add_namespace($nsdef);
29 my $Document = Rinchi::XMLSchema->parsefile('datatypes.xsd');
30 $document = Rinchi::XMLSchema->parse($file);
31  
32 =head1 DESCRIPTION
33  
34 Description.
35  
36 =head2 EXPORT
37  
38 None by default.
39  
40 =cut
41  
42 #===============================================================================
43
44 sub handle_start_hasFacet() {
45 my ($expat,$tag,%attrs) = @_;
46 my $HasFacet = Rinchi::XMLSchema::HFP::HasFacet->new();
47
48 if (exists($attrs{'name'})) {
49 $HasFacet->name($attrs{'name'});
50 }
51 return $HasFacet;
52 }
53
54 #-------------------------------------------------------------------------------
55
56 sub handle_end_hasFacet() {
57 my ($expat,$tag,$HasFacet) = @_;
58 }
59
60 #===============================================================================
61
62 sub handle_start_hasProperty() {
63 my ($expat,$tag,%attrs) = @_;
64 my $HasProperty = Rinchi::XMLSchema::HFP::HasProperty->new();
65
66 if (exists($attrs{'name'})) {
67 $HasProperty->name($attrs{'name'});
68 }
69 if (exists($attrs{'value'})) {
70 $HasProperty->value($attrs{'value'});
71 }
72
73 return $HasProperty;
74 }
75
76 #-------------------------------------------------------------------------------
77
78 sub handle_end_hasProperty() {
79 my ($expat,$tag,$HasProperty) = @_;
80 }
81
82 #===============================================================================
83
84 my %sax_start_handlers = (
85 'hasFacet' => \&handle_start_hasFacet,
86 'hasProperty' => \&handle_start_hasProperty,
87 );
88  
89 my %sax_end_handlers = (
90 'hasFacet' => \&handle_end_hasFacet,
91 'hasProperty' => \&handle_end_hasProperty,
92 );
93
94 my $schema_namespace='http://www.w3.org/2001/XMLSchema-hasFacetAndProperty';
95  
96 #=================================================================
97  
98 =item $nsdef = Rinchi::XMLSchema->namespace_def();
99  
100 Returns a hash reference containing the following key-value pairs:
101  
102 Start Hash reference to SAX Start event handlers
103 End Hash reference to SAX End event handlers
104 Namespace Namespace URI
105  
106 =cut
107  
108 sub namespace_def() {
109 my $self = shift @_;
110
111 return {'Start'=>\%sax_start_handlers,'End'=>\%sax_end_handlers, 'Namespace'=>$schema_namespace};
112 }
113  
114 #===============================================================================
115
116 package Rinchi::XMLSchema::HFP::HasFacet;
117 use Carp;
118  
119 sub new() {
120 my $class = shift;
121
122 $class = ref($class) || $class;
123 my $self = {};
124 bless($self,$class);
125 return $self;
126 }
127  
128 #===============================================================================
129
130 sub name() {
131 my $self = shift;
132 if (@_) {
133 if ($_[0] =~ /^[-0-9A-Za-z_.:]+$/) {
134 $self->{'_name'} = shift;
135 } else {
136 carp 'Found value \'' . $_[0] . '\', expecting NMTOKEN.'
137 }
138 }
139 return $self->{'_name'};
140 }
141  
142 #===============================================================================
143
144 package Rinchi::XMLSchema::HFP::HasProperty;
145 use Carp;
146  
147 sub new() {
148 my $class = shift;
149
150 $class = ref($class) || $class;
151 my $self = {};
152 bless($self,$class);
153 return $self;
154 }
155  
156 #===============================================================================
157
158 sub name() {
159 my $self = shift;
160 if (@_) {
161 if ($_[0] =~ /^[-0-9A-Za-z_.:]+$/) {
162 $self->{'_name'} = shift;
163 } else {
164 carp 'Found value \'' . $_[0] . '\', expecting NMTOKEN.'
165 }
166 }
167 return $self->{'_name'};
168 }
169  
170 #===============================================================================
171
172 sub value() {
173 my $self = shift;
174 if (@_) {
175 $self->{'_value'} = shift;
176 }
177 return $self->{'_value'};
178 }
179  
180