File Coverage

blib/lib/XML/XForms/Generator/UserInterface.pm
Criterion Covered Total %
statement 10 12 83.3
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 14 16 87.5


line stmt bran cond sub pod time code
1             package XML::XForms::Generator::UserInterface;
2             ######################################################################
3             ## ##
4             ## Package: UserInterface.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   7446 use strict;
  5         8  
  5         181  
22 5     5   25 use warnings;
  5         11  
  5         121  
23              
24 5     5   23 use Carp;
  5         8  
  5         1328  
25 5     5   3179 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 $userinterface ( @XFORMS_USERINTERFACE )
37             {
38             ## We need to temporarily pop of the namespace prefix for our
39             ## work here.
40             $userinterface =~ s/^xforms://g;
41              
42             ## Can't use the below function - due to screwy logic it will
43             ## throw warnings. Bah!
44             #Exporter::export_tags( "xforms_$userinterface" );
45             push( @EXPORT, "xforms_$userinterface" );
46            
47             *{ "xforms_$userinterface" } = sub {
48              
49             my( $attributes, @children ) = @_;
50              
51             my $node = XML::XForms::Generator::UserInterface->new( $userinterface );
52              
53             __xforms_attribute( $node, $attributes );
54             __xforms_children( $node, @children );
55              
56             return( $node );
57             };
58             }
59              
60             use strict 'refs';
61              
62             ##==================================================================##
63             ## Constructor(s)/Deconstructor(s) ##
64             ##==================================================================##
65              
66             ##----------------------------------------------##
67             ## new ##
68             ##----------------------------------------------##
69             ## UserInterface default contstructor. ##
70             ##----------------------------------------------##
71             sub new
72             {
73             ## Pull in what type of an object we will be.
74             my $type = shift;
75             ## Pull in the parameters ...
76             my $userinterface = shift;
77             ## The object we are generating is going to be a child class of
78             ## XML::LibXML's DOM objects.
79             my $self = XML::LibXML::Element->new( $userinterface );
80             ## Determine what exact class we will be blessing this instance into.
81             my $class = ref( $type ) || $type;
82             ## Bless the class for it is good [tm].
83             bless( $self, $class );
84             ## We need to set our namespace on our model element and activate it.
85             $self->setNamespace( $XFORMS_NAMESPACE{xforms}, "xforms", 1 );
86             ## Send it back to the caller all happy like.
87             return( $self );
88             }
89              
90             ##----------------------------------------------##
91             ## DESTROY ##
92             ##----------------------------------------------##
93             ## UserInterface default deconstructor. ##
94             ##----------------------------------------------##
95             sub DESTROY
96             {
97             ## This is mainly a placeholder to keep things like mod_perl happy.
98             return;
99             }
100              
101             ##==================================================================##
102             ## Method(s) ##
103             ##==================================================================##
104              
105             no strict 'refs';
106              
107             foreach my $element ( @XFORMS_USERINTERFACE_ELEMENT )
108             {
109             ## We need to temporarily remove the namespace prefix for our work.
110             $element =~ s/^xforms://g;
111              
112             ##----------------------------------------------##
113             ## appendCHILDENAME ##
114             ##----------------------------------------------##
115             ## Method generation for the common child ##
116             ## elements of controls. ##
117             ##----------------------------------------------##
118             *{ "append" . ucfirst( $element ) } = sub {
119              
120             my( $self, $attributes, @children ) = @_;
121              
122             ## We need to determine what type of control we are working with.
123             my $type = $self->nodeName;
124              
125             ## We set a status bit to false indicating that at the momment we
126             ## don't know if this particular control has the potential of
127             ## having the child element in question attached to it.
128             my $status = 0;
129              
130             ## Loop through all the potential child elements looking for it.
131             foreach( @{ $XFORMS_SCHEMA{ $type }->[3] },
132             @{ $XFORMS_SCHEMA{ $type }->[4] } )
133             {
134             ## When we find it, make sure we change our status bit.
135             if( ( $_ eq "$element" ) || ( $_ eq "xforms:$element" ) )
136             {
137             $status = 1;
138             }
139             }
140              
141             if( $status )
142             {
143             ## If status is true, then proceed to build and append the
144             ## child element.
145             my $node = XML::LibXML::Element->new( $element );
146              
147             $self->appendChild( $node );
148              
149             $node->setNamespace( $XFORMS_NAMESPACE{xforms}, "xforms", 1 );
150              
151             __xforms_attribute( $node, $attributes );
152             __xforms_children( $node, @children );
153            
154             return( $node );
155             }
156             else
157             {
158             croak( qq|Error: $type control does not have the ability to have |,
159             qq|a $element child element| );
160             }
161             };
162              
163             ##----------------------------------------------##
164             ## getCHILDENAME ##
165             ##----------------------------------------------##
166             ## Method for retrieval of the control child ##
167             ## elements. ##
168             ##----------------------------------------------##
169             *{ "get" . ucfirst( $element ) } = sub {
170              
171             my $self = shift;
172              
173             my @nodes =
174             $self->getElementsByTagNameNS( $XFORMS_NAMESPACE{ 'xforms' },
175             $element );
176              
177             return( @nodes );
178             };
179             }
180              
181             ##==================================================================##
182             ## Internal Function(s) ##
183             ##==================================================================##
184              
185             ##==================================================================##
186             ## End of Code ##
187             ##==================================================================##
188             1;
189              
190             ##==================================================================##
191             ## Plain Old Documentation (POD) ##
192             ##==================================================================##
193              
194             __END__