line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package XML::XForms::Generator::Control; |
2
|
|
|
|
|
|
|
###################################################################### |
3
|
|
|
|
|
|
|
## ## |
4
|
|
|
|
|
|
|
## Package: Control.pm ## |
5
|
|
|
|
|
|
|
## Author: D. Hageman ## |
6
|
|
|
|
|
|
|
## ## |
7
|
|
|
|
|
|
|
## Description: ## |
8
|
|
|
|
|
|
|
## ## |
9
|
|
|
|
|
|
|
## Perl object to assist in the generation of XML compliant with ## |
10
|
|
|
|
|
|
|
## the W3's XForms specification. ## |
11
|
|
|
|
|
|
|
## ## |
12
|
|
|
|
|
|
|
###################################################################### |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
##==================================================================## |
15
|
|
|
|
|
|
|
## Libraries and Variables ## |
16
|
|
|
|
|
|
|
##==================================================================## |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
require 5.006; |
19
|
|
|
|
|
|
|
require Exporter; |
20
|
|
|
|
|
|
|
|
21
|
5
|
|
|
5
|
|
5922
|
use strict; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
185
|
|
22
|
5
|
|
|
5
|
|
27
|
use warnings; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
224
|
|
23
|
|
|
|
|
|
|
|
24
|
5
|
|
|
5
|
|
23
|
use Carp; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
396
|
|
25
|
5
|
|
|
5
|
|
2762
|
use XML::LibXML; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
use XML::XForms::Generator::Common; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
our @ISA = qw( Exporter XML::LibXML::Element ); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
our @EXPORT = qw(); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
our $VERSION = "0.70"; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
no strict 'refs'; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
foreach my $control ( @XFORMS_CONTROL ) |
37
|
|
|
|
|
|
|
{ |
38
|
|
|
|
|
|
|
## We need to temporarily remove the namespace prefix. |
39
|
|
|
|
|
|
|
$control =~ s/^xforms://g; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
## I really hate the fact that I have to use the push function |
42
|
|
|
|
|
|
|
## instead of the Exporter. Oh well. |
43
|
|
|
|
|
|
|
#Exporter::export_tags( "xforms_$control" ); |
44
|
|
|
|
|
|
|
push( @EXPORT, "xforms_$control" ); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
*{ "xforms_$control" } = sub { |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
my( $attributes, @children ) = @_; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
my $node = XML::XForms::Generator::Control->new( $control ); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
__xforms_attribute( $node, $attributes ); |
53
|
|
|
|
|
|
|
__xforms_children( $node, @children ); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
return( $node ); |
56
|
|
|
|
|
|
|
}; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
use strict 'refs'; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
##==================================================================## |
62
|
|
|
|
|
|
|
## Constructor(s)/Deconstructor(s) ## |
63
|
|
|
|
|
|
|
##==================================================================## |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
##----------------------------------------------## |
66
|
|
|
|
|
|
|
## new ## |
67
|
|
|
|
|
|
|
##----------------------------------------------## |
68
|
|
|
|
|
|
|
## XForms::Control default contstructor. ## |
69
|
|
|
|
|
|
|
##----------------------------------------------## |
70
|
|
|
|
|
|
|
sub new |
71
|
|
|
|
|
|
|
{ |
72
|
|
|
|
|
|
|
## Pull in what type of an object we will be. |
73
|
|
|
|
|
|
|
my $type = shift; |
74
|
|
|
|
|
|
|
## Grab the name of the control. |
75
|
|
|
|
|
|
|
my $control = shift; |
76
|
|
|
|
|
|
|
## The object we are generating is going to be a child class of |
77
|
|
|
|
|
|
|
## XML::LibXML's DOM objects. |
78
|
|
|
|
|
|
|
my $self = XML::LibXML::Element->new( $control ); |
79
|
|
|
|
|
|
|
## Determine what exact class we will be blessing this instance into. |
80
|
|
|
|
|
|
|
my $class = ref( $type ) || $type; |
81
|
|
|
|
|
|
|
## Bless the class for it is good [tm]. |
82
|
|
|
|
|
|
|
bless( $self, $class ); |
83
|
|
|
|
|
|
|
## We need to set our namespace on our model element and activate it. |
84
|
|
|
|
|
|
|
$self->setNamespace( $XFORMS_NAMESPACE{xforms}, "xforms", 1 ); |
85
|
|
|
|
|
|
|
## Send it back to the caller all happy like. |
86
|
|
|
|
|
|
|
return( $self ); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
##----------------------------------------------## |
90
|
|
|
|
|
|
|
## DESTROY ## |
91
|
|
|
|
|
|
|
##----------------------------------------------## |
92
|
|
|
|
|
|
|
## XForms::Control default deconstructor. ## |
93
|
|
|
|
|
|
|
##----------------------------------------------## |
94
|
|
|
|
|
|
|
sub DESTROY |
95
|
|
|
|
|
|
|
{ |
96
|
|
|
|
|
|
|
## This is mainly a placeholder to keep things like mod_perl happy. |
97
|
|
|
|
|
|
|
return; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
##==================================================================## |
101
|
|
|
|
|
|
|
## Method(s) ## |
102
|
|
|
|
|
|
|
##==================================================================## |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
no strict 'refs'; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
foreach my $element ( @XFORMS_CONTROL_ELEMENT ) |
107
|
|
|
|
|
|
|
{ |
108
|
|
|
|
|
|
|
## We need to temporarily remove the namespace prefix for our work. |
109
|
|
|
|
|
|
|
$element =~ s/^xforms://g; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
##----------------------------------------------## |
112
|
|
|
|
|
|
|
## appendCHILDENAME ## |
113
|
|
|
|
|
|
|
##----------------------------------------------## |
114
|
|
|
|
|
|
|
## Method generation for the common child ## |
115
|
|
|
|
|
|
|
## elements of controls. ## |
116
|
|
|
|
|
|
|
##----------------------------------------------## |
117
|
|
|
|
|
|
|
*{ "append" . ucfirst( $element ) } = sub { |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
my( $self, $attributes, @children ) = @_; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
## We need to determine what type of control we are working with. |
122
|
|
|
|
|
|
|
my $type = $self->nodeName; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
## We set a status bit to false indicating that at the momment we |
125
|
|
|
|
|
|
|
## don't know if this particular control has the potential of |
126
|
|
|
|
|
|
|
## having the child element in question attached to it. |
127
|
|
|
|
|
|
|
my $status = 0; |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
## Loop through all the potential child elements looking for it. |
130
|
|
|
|
|
|
|
foreach( @{ $XFORMS_SCHEMA{ $type }->[3] }, |
131
|
|
|
|
|
|
|
@{ $XFORMS_SCHEMA{ $type }->[4] } ) |
132
|
|
|
|
|
|
|
{ |
133
|
|
|
|
|
|
|
## When we find it, make sure we change our status bit. |
134
|
|
|
|
|
|
|
if( ( $_ eq "$element" ) || ( $_ eq "xforms:$element" ) ) |
135
|
|
|
|
|
|
|
{ |
136
|
|
|
|
|
|
|
$status = 1; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
if( $status ) |
141
|
|
|
|
|
|
|
{ |
142
|
|
|
|
|
|
|
## If status is true, then proceed to build and append the |
143
|
|
|
|
|
|
|
## child element. |
144
|
|
|
|
|
|
|
my $node = XML::LibXML::Element->new( $element ); |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
bless( $node, __PACKAGE__ ); |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
$self->appendChild( $node ); |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
$node->setNamespace( $XFORMS_NAMESPACE{xforms}, "xforms", 1 ); |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
__xforms_attribute( $node, $attributes ); |
153
|
|
|
|
|
|
|
__xforms_children( $node, @children ); |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
return( $node ); |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
else |
158
|
|
|
|
|
|
|
{ |
159
|
|
|
|
|
|
|
croak( qq|Error: $type control does not have the ability to have |, |
160
|
|
|
|
|
|
|
qq|a $element child element| ); |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
}; |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
##----------------------------------------------## |
165
|
|
|
|
|
|
|
## getCHILDENAME ## |
166
|
|
|
|
|
|
|
##----------------------------------------------## |
167
|
|
|
|
|
|
|
## Method for retrieval of the control child ## |
168
|
|
|
|
|
|
|
## elements. ## |
169
|
|
|
|
|
|
|
##----------------------------------------------## |
170
|
|
|
|
|
|
|
*{ "get" . ucfirst( $element ) } = sub { |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
my $self = shift; |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
my @nodes = |
175
|
|
|
|
|
|
|
$self->getElementsByTagNameNS( $XFORMS_NAMESPACE{ 'xforms' }, |
176
|
|
|
|
|
|
|
$element ); |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
return( @nodes ); |
179
|
|
|
|
|
|
|
}; |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
##----------------------------------------------## |
182
|
|
|
|
|
|
|
## prependCHILDENAME ## |
183
|
|
|
|
|
|
|
##----------------------------------------------## |
184
|
|
|
|
|
|
|
## Method generation for the common child ## |
185
|
|
|
|
|
|
|
## elements of controls. ## |
186
|
|
|
|
|
|
|
##----------------------------------------------## |
187
|
|
|
|
|
|
|
*{ "prepend" . ucfirst( $element ) } = sub { |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
my( $self, $attributes, @children ) = @_; |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
## We need to determine what type of control we are working with. |
192
|
|
|
|
|
|
|
my $type = $self->nodeName; |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
## We set a status bit to false indicating that at the momment we |
195
|
|
|
|
|
|
|
## don't know if this particular control has the potential of |
196
|
|
|
|
|
|
|
## having the child element in question attached to it. |
197
|
|
|
|
|
|
|
my $status = 0; |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
## Loop through all the potential child elements looking for it. |
200
|
|
|
|
|
|
|
foreach( @{ $XFORMS_SCHEMA{ $type }->[3] }, |
201
|
|
|
|
|
|
|
@{ $XFORMS_SCHEMA{ $type }->[4] } ) |
202
|
|
|
|
|
|
|
{ |
203
|
|
|
|
|
|
|
## When we find it, make sure we change our status bit. |
204
|
|
|
|
|
|
|
if( ( $_ eq "$element" ) || ( $_ eq "xforms:$element" ) ) |
205
|
|
|
|
|
|
|
{ |
206
|
|
|
|
|
|
|
$status = 1; |
207
|
|
|
|
|
|
|
} |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
if( $status ) |
211
|
|
|
|
|
|
|
{ |
212
|
|
|
|
|
|
|
## If status is true, then proceed to build and append the |
213
|
|
|
|
|
|
|
## child element. |
214
|
|
|
|
|
|
|
my $node = XML::LibXML::Element->new( $element ); |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
bless( $node, __PACKAGE__ ); |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
my $first_node = $self->firstChild; |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
$self->insertBefore( $node, $first_node ); |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
$node->setNamespace( $XFORMS_NAMESPACE{xforms}, "xforms", 1 ); |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
__xforms_attribute( $node, $attributes ); |
225
|
|
|
|
|
|
|
__xforms_children( $node, @children ); |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
return( $node ); |
228
|
|
|
|
|
|
|
} |
229
|
|
|
|
|
|
|
else |
230
|
|
|
|
|
|
|
{ |
231
|
|
|
|
|
|
|
croak( qq|Error: $type control does not have the ability to have |, |
232
|
|
|
|
|
|
|
qq|a $element child element| ); |
233
|
|
|
|
|
|
|
} |
234
|
|
|
|
|
|
|
}; |
235
|
|
|
|
|
|
|
} |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
use strict 'refs'; |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
##==================================================================## |
240
|
|
|
|
|
|
|
## Internal Function(s) ## |
241
|
|
|
|
|
|
|
##==================================================================## |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
##==================================================================## |
244
|
|
|
|
|
|
|
## End of Code ## |
245
|
|
|
|
|
|
|
##==================================================================## |
246
|
|
|
|
|
|
|
1; |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
##==================================================================## |
249
|
|
|
|
|
|
|
## Plain Old Documentation (POD) ## |
250
|
|
|
|
|
|
|
##==================================================================## |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
__END__ |