| 1 | package XML::XForms::Generator::Control; | ||||||||||||||||||||||||||||
| 2 | ###################################################################### | ||||||||||||||||||||||||||||
| 3 | ## ## | ||||||||||||||||||||||||||||
| 4 | ## Package: Control.pm ## | ||||||||||||||||||||||||||||
| 5 | ## Author: D. Hageman <dhageman@dracken.com> ## | ||||||||||||||||||||||||||||
| 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 | 5 | require 5.006; | |||||||||||||||||||||||||||
| 19 | 5 | require Exporter; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 5 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 5 | ▶ | use XML::LibXML; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 5 | ▶ | use XML::XForms::Generator::Common; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 5 | our @ISA = qw( Exporter XML::LibXML::Element ); | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 5 | our @EXPORT = qw(); | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 5 | our $VERSION = "0.70"; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 5 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 5 | foreach my $control ( @XFORMS_CONTROL ) | |||||||||||||||||||||||||||
| 37 | { | ||||||||||||||||||||||||||||
| 38 | ## We need to temporarily remove the namespace prefix. | ||||||||||||||||||||||||||||
| 39 | 55 | $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 | 55 | push( @EXPORT, "xforms_$control" ); | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 55 | ▶ | *{ "xforms_$control" } = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 3 | my( $attributes, @children ) = @_; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 3 | my $node = XML::XForms::Generator::Control->new( $control ); | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 3 | __xforms_attribute( $node, $attributes ); | |||||||||||||||||||||||||||
| 53 | 3 | __xforms_children( $node, @children ); | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 3 | return( $node ); | |||||||||||||||||||||||||||
| 56 | 55 | }; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 5 | ▶ | use strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | ##==================================================================## | ||||||||||||||||||||||||||||
| 62 | ## Constructor(s)/Deconstructor(s) ## | ||||||||||||||||||||||||||||
| 63 | ##==================================================================## | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 66 | ## new ## | ||||||||||||||||||||||||||||
| 67 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 68 | ## XForms::Control default contstructor. ## | ||||||||||||||||||||||||||||
| 69 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 70 | sub new | ||||||||||||||||||||||||||||
| 71 | 3 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 72 | ## Pull in what type of an object we will be. | ||||||||||||||||||||||||||||
| 73 | 3 | my $type = shift; | |||||||||||||||||||||||||||
| 74 | ## Grab the name of the control. | ||||||||||||||||||||||||||||
| 75 | 3 | my $control = shift; | |||||||||||||||||||||||||||
| 76 | ## The object we are generating is going to be a child class of | ||||||||||||||||||||||||||||
| 77 | ## XML::LibXML's DOM objects. | ||||||||||||||||||||||||||||
| 78 | 3 | my $self = XML::LibXML::Element->new( $control ); | |||||||||||||||||||||||||||
| 79 | ## Determine what exact class we will be blessing this instance into. | ||||||||||||||||||||||||||||
| 80 | 3 | ▶ | my $class = ref( $type ) || $type; | ||||||||||||||||||||||||||
|
Condition33%1/3
ref $type || $type
MC/DC0%0/2
ref $type || $type
ref $type
$type
Truth table33%1/3
A || B
A= ref $typeB= $type
| |||||||||||||||||||||||||||||
| 81 | ## Bless the class for it is good [tm]. | ||||||||||||||||||||||||||||
| 82 | 3 | bless( $self, $class ); | |||||||||||||||||||||||||||
| 83 | ## We need to set our namespace on our model element and activate it. | ||||||||||||||||||||||||||||
| 84 | 3 | $self->setNamespace( $XFORMS_NAMESPACE{xforms}, "xforms", 1 ); | |||||||||||||||||||||||||||
| 85 | ## Send it back to the caller all happy like. | ||||||||||||||||||||||||||||
| 86 | 3 | return( $self ); | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 90 | ## DESTROY ## | ||||||||||||||||||||||||||||
| 91 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 92 | ## XForms::Control default deconstructor. ## | ||||||||||||||||||||||||||||
| 93 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 94 | sub DESTROY | ||||||||||||||||||||||||||||
| 95 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 96 | ## This is mainly a placeholder to keep things like mod_perl happy. | ||||||||||||||||||||||||||||
| 97 | 0 | return; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | ##==================================================================## | ||||||||||||||||||||||||||||
| 101 | ## Method(s) ## | ||||||||||||||||||||||||||||
| 102 | ##==================================================================## | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 5 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 5 | foreach my $element ( @XFORMS_CONTROL_ELEMENT ) | |||||||||||||||||||||||||||
| 107 | { | ||||||||||||||||||||||||||||
| 108 | ## We need to temporarily remove the namespace prefix for our work. | ||||||||||||||||||||||||||||
| 109 | 55 | $element =~ s/^xforms://g; | |||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 112 | ## appendCHILDENAME ## | ||||||||||||||||||||||||||||
| 113 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 114 | ## Method generation for the common child ## | ||||||||||||||||||||||||||||
| 115 | ## elements of controls. ## | ||||||||||||||||||||||||||||
| 116 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 117 | 55 | ▶ | *{ "append" . ucfirst( $element ) } = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 4 | my( $self, $attributes, @children ) = @_; | |||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | ## We need to determine what type of control we are working with. | ||||||||||||||||||||||||||||
| 122 | 4 | 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 | 4 | my $status = 0; | |||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | ## Loop through all the potential child elements looking for it. | ||||||||||||||||||||||||||||
| 130 | 4 | foreach( @{ $XFORMS_SCHEMA{ $type }->[3] }, | |||||||||||||||||||||||||||
| 131 | 4 | @{ $XFORMS_SCHEMA{ $type }->[4] } ) | |||||||||||||||||||||||||||
| 132 | { | ||||||||||||||||||||||||||||
| 133 | ## When we find it, make sure we change our status bit. | ||||||||||||||||||||||||||||
| 134 | 68 | ▶ | if( ( $_ eq "$element" ) || ( $_ eq "xforms:$element" ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$_ eq "$element" or $_ eq "xforms:$element"
MC/DC100%2/2
$_ eq "$element" or $_ eq "xforms:$element"
$_ eq "$element"
$_ eq "xforms:$element"
Truth table100%3/3
A or B
A= $_ eq "$element"B= $_ eq "xforms:$element"
| |||||||||||||||||||||||||||||
| 135 | { | ||||||||||||||||||||||||||||
| 136 | 4 | $status = 1; | |||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 4 | ▶ | if( $status ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 141 | { | ||||||||||||||||||||||||||||
| 142 | ## If status is true, then proceed to build and append the | ||||||||||||||||||||||||||||
| 143 | ## child element. | ||||||||||||||||||||||||||||
| 144 | 4 | my $node = XML::LibXML::Element->new( $element ); | |||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 4 | bless( $node, __PACKAGE__ ); | |||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 4 | $self->appendChild( $node ); | |||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 4 | $node->setNamespace( $XFORMS_NAMESPACE{xforms}, "xforms", 1 ); | |||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 4 | __xforms_attribute( $node, $attributes ); | |||||||||||||||||||||||||||
| 153 | 4 | __xforms_children( $node, @children ); | |||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 4 | return( $node ); | |||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | else | ||||||||||||||||||||||||||||
| 158 | { | ||||||||||||||||||||||||||||
| 159 | 0 | croak( qq|Error: $type control does not have the ability to have |, | |||||||||||||||||||||||||||
| 160 | qq|a $element child element| ); | ||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||
| 162 | 55 | }; | |||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 165 | ## getCHILDENAME ## | ||||||||||||||||||||||||||||
| 166 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 167 | ## Method for retrieval of the control child ## | ||||||||||||||||||||||||||||
| 168 | ## elements. ## | ||||||||||||||||||||||||||||
| 169 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 170 | 55 | ▶ | *{ "get" . ucfirst( $element ) } = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=3.5
| |||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | my @nodes = | ||||||||||||||||||||||||||||
| 175 | 0 | $self->getElementsByTagNameNS( $XFORMS_NAMESPACE{ 'xforms' }, | |||||||||||||||||||||||||||
| 176 | $element ); | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | 0 | return( @nodes ); | |||||||||||||||||||||||||||
| 179 | 55 | }; | |||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 182 | ## prependCHILDENAME ## | ||||||||||||||||||||||||||||
| 183 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 184 | ## Method generation for the common child ## | ||||||||||||||||||||||||||||
| 185 | ## elements of controls. ## | ||||||||||||||||||||||||||||
| 186 | ##----------------------------------------------## | ||||||||||||||||||||||||||||
| 187 | 55 | ▶ | *{ "prepend" . ucfirst( $element ) } = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=33.0
| |||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | 0 | my( $self, $attributes, @children ) = @_; | |||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | ## We need to determine what type of control we are working with. | ||||||||||||||||||||||||||||
| 192 | 0 | 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 | 0 | my $status = 0; | |||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | ## Loop through all the potential child elements looking for it. | ||||||||||||||||||||||||||||
| 200 | 0 | foreach( @{ $XFORMS_SCHEMA{ $type }->[3] }, | |||||||||||||||||||||||||||
| 201 | 0 | @{ $XFORMS_SCHEMA{ $type }->[4] } ) | |||||||||||||||||||||||||||
| 202 | { | ||||||||||||||||||||||||||||
| 203 | ## When we find it, make sure we change our status bit. | ||||||||||||||||||||||||||||
| 204 | 0 | ▶ | if( ( $_ eq "$element" ) || ( $_ eq "xforms:$element" ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$_ eq "$element" or $_ eq "xforms:$element"
MC/DC0%0/2
$_ eq "$element" or $_ eq "xforms:$element"
$_ eq "$element"
$_ eq "xforms:$element"
Truth table0%0/3
A or B
A= $_ eq "$element"B= $_ eq "xforms:$element"
| |||||||||||||||||||||||||||||
| 205 | { | ||||||||||||||||||||||||||||
| 206 | 0 | $status = 1; | |||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | 0 | ▶ | if( $status ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 211 | { | ||||||||||||||||||||||||||||
| 212 | ## If status is true, then proceed to build and append the | ||||||||||||||||||||||||||||
| 213 | ## child element. | ||||||||||||||||||||||||||||
| 214 | 0 | my $node = XML::LibXML::Element->new( $element ); | |||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | 0 | bless( $node, __PACKAGE__ ); | |||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | 0 | my $first_node = $self->firstChild; | |||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | 0 | $self->insertBefore( $node, $first_node ); | |||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | 0 | $node->setNamespace( $XFORMS_NAMESPACE{xforms}, "xforms", 1 ); | |||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | 0 | __xforms_attribute( $node, $attributes ); | |||||||||||||||||||||||||||
| 225 | 0 | __xforms_children( $node, @children ); | |||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | 0 | return( $node ); | |||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||
| 229 | else | ||||||||||||||||||||||||||||
| 230 | { | ||||||||||||||||||||||||||||
| 231 | 0 | croak( qq|Error: $type control does not have the ability to have |, | |||||||||||||||||||||||||||
| 232 | qq|a $element child element| ); | ||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||
| 234 | 55 | }; | |||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | 5 | ▶ | use strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | ##==================================================================## | ||||||||||||||||||||||||||||
| 240 | ## Internal Function(s) ## | ||||||||||||||||||||||||||||
| 241 | ##==================================================================## | ||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | ##==================================================================## | ||||||||||||||||||||||||||||
| 244 | ## End of Code ## | ||||||||||||||||||||||||||||
| 245 | ##==================================================================## | ||||||||||||||||||||||||||||
| 246 | 5 | 1; | |||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | ##==================================================================## | ||||||||||||||||||||||||||||
| 249 | ## Plain Old Documentation (POD) ## | ||||||||||||||||||||||||||||
| 250 | ##==================================================================## | ||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | __END__ | ||||||||||||||||||||||||||||