Generator/Action.pm

filter: Statementstmt 57.1% 44 / 77 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 64.2% 9 / 14 Podpod 100% 1 / 1 totaltotal 53.4% 54 / 101 CC 5 SCAR 16.9
CC
5
Cov
52%
__ANON__
17.8
new
6.0
DESTROY
2.0
CRAP 5.4
« Generator/Control.pm ↑ Summary Generator/Extension.pm »
1 package XML::XForms::Generator::Action;
2 ######################################################################
3 ## ##
4 ## Package: Action.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 $action ( @XFORMS_ACTION )
37 {
38 ## We need to temporarily remove the namespace prefix.
39 60 $action =~ s/^xforms://g;
40  
41 ## I prefer the below function, but it seems that Exporter
42 ## will throw warnings whenever I use it.
43 #Exporter::export_tags( "xforms_$action" );
44 60 push( @EXPORT, "xforms_$action" );
45
46 60 ▶ *{ "xforms_$action" } = sub {
Subroutine __ANON__: not called CC=1 SCAR=4.6
47  
48 0 my( $attributes, @children ) = @_;
49  
50 0 my $node = XML::XForms::Generator::Action->new( $action );
51  
52 0 __xforms_attribute( $node, $attributes );
53 0 __xforms_children( $node, @children );
54  
55 0 return( $node );
56 60 };
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::Action default contstructor. ##
69 ##----------------------------------------------##
70 sub new
71 0 ▶{
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
72 ## Pull in what type of an object we will be.
73 0 my $type = shift;
74 ## Pull in any arguments provided to the constructor.
75 0 my %params = @_;
76 ## The object we are generating is going to be a child class of
77 ## XML::LibXML's DOM objects.
78 0 my $self = XML::LibXML::Element->new( $params{__type__} );
79 ## We need to clean up the parameter ...
80 0 delete( $params{__type__} );
81 ## Determine what exact class we will be blessing this instance into.
82 0 ▶ my $class = ref( $type ) || $type;
Condition0%0/3
ref $type || $type
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $type || $type
ref $type $type
Truth table0%0/3
A || B
A= ref $typeB= $type
ABresult
1X1
011
000
83 ## Bless the class for it is good [tm].
84 0 bless( $self, $class );
85 ## We need to set our namespace on our model element and activate it.
86 0 $self->setNamespace( $XFORMS_NAMESPACE{xforms}, "xforms", 1 );
87 ## Send it back to the caller all happy like.
88 0 return( $self );
89 }
90  
91 ##----------------------------------------------##
92 ## DESTROY ##
93 ##----------------------------------------------##
94 ## XForms::Action default deconstructor. ##
95 ##----------------------------------------------##
96 sub DESTROY
97 0 ▶{
Subroutine DESTROY: not called CC=1 SCAR=6.9
98 ## This is mainly a placeholder to keep things like mod_perl happy.
99 0 return;
100 }
101  
102 ##==================================================================##
103 ## Method(s) ##
104 ##==================================================================##
105  
106 5 ▶no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
107  
108 5 foreach my $element ( @XFORMS_ACTION )
109 {
110 ## We need to temporarily remove the namespace prefix for our work.
111 60 $element =~ s/^xforms://g;
112  
113 ##----------------------------------------------##
114 ## appendCHILDENAME ##
115 ##----------------------------------------------##
116 ## Method generation for the common child ##
117 ## elements of controls. ##
118 ##----------------------------------------------##
119 60 ▶ *{ "append" . ucfirst( $element ) } = sub {
Subroutine __ANON__: not called CC=4 SCAR=28.8
120  
121 0 my( $self, $attributes, @children ) = @_;
122  
123 ## We need to determine what type of control we are working with.
124 0 my $type = $self->nodeName;
125  
126 ## We set a status bit to false indicating that at the momment we
127 ## don't know if this particular control has the potential of
128 ## having the child element in question attached to it.
129 0 my $status = 0;
130  
131 ## Loop through all the potential child elements looking for it.
132 0 foreach( @{ $XFORMS_SCHEMA{ $type }->[3] },
133 0 @{ $XFORMS_SCHEMA{ $type }->[4] } )
134 {
135 ## When we find it, make sure we change our status bit.
136 0 ▶ if( $_ eq "$element" )
Branch: 1 branch
BranchTrueFalseTotal
if ($_ eq "$element") 0 0 0
137 {
138 0 $status = 1;
139 }
140 }
141  
142 0 ▶ if( $status )
Branch: 1 branch
BranchTrueFalseTotal
if ($status) { } 0 0 0
143 {
144 ## If status is true, then proceed to build and append the
145 ## child element.
146 0 my $node = XML::LibXML::Element->new( $element );
147  
148 0 $self->appendChild( $node );
149  
150 0 $node->setNamespace( $XFORMS_NAMESPACE{xforms}, "xforms", 1 );
151  
152 0 __xforms_attribute( $node, $attributes );
153 0 __xforms_children( $node, @children );
154
155 0 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 60 };
163  
164 ##----------------------------------------------##
165 ## getCHILDENAME ##
166 ##----------------------------------------------##
167 ## Method for retrieval of the control child ##
168 ## elements. ##
169 ##----------------------------------------------##
170 60 ▶ *{ "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 60 };
180 }
181  
182 5 ▶use strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
183 ##==================================================================##
184 ## Function(s) ##
185 ##==================================================================##
186  
187 ##==================================================================##
188 ## Internal Function(s) ##
189 ##==================================================================##
190  
191 ##==================================================================##
192 ## End of Code ##
193 ##==================================================================##
194 5 1;
195  
196 ##==================================================================##
197 ## Plain Old Documentation (POD) ##
198 ##==================================================================##
199  
200 __END__
« Generator/Control.pm ↑ Summary Generator/Extension.pm »