XML/Template/Element/Core.pm untested

filter: Statementstmt 0.0% 0 / 17 Branchbran n/a Conditioncond 0.0% 0 / 2 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 24 SCAR 6.9
CC
1
Cov
0%
element
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 ###############################################################################
2 # XML::Template::Element::Core
3 #
4 # Copyright (c) 2002-2003 Jonathan A. Waxman <jowaxman@law.upenn.edu>
5 # All rights reserved.
6 #
7 # This program is free software; you can redistribute it and/or
8 # modify it under the same terms as Perl itself.
9 ###############################################################################
10 package XML::Template::Element::Core;
11 use base qw(XML::Template::Element);
12  
13 use strict;
14 use XML::Template::Element;
15  
16  
17 =pod
18  
19 =head1 NAME
20  
21 XML::Template::Element::Core - XML::Template plugin module for the core
22 namespace tagset.
23  
24 =head1 SYNOPSIS
25  
26 This XML::Template plugin module implements the core namespace tagset.
27 The core namespace includes tags that rely on XML::Template internals.
28  
29 =head1 CONSTRUCTOR
30  
31 XML::Template::Element::Block inherits its constructor method, C<new>,
32 from L<XML::Template::Element>.
33  
34 =head1 CORE TAGSET METHODS
35  
36 =head2 element
37  
38 This method implements the element tag which provides a way to handle
39 dynamic tag names. The method C<process> in L<XML::Template::Process>
40 replaces all occurances in an XHTML document of
41  
42 <${tagname}
43  
44 with
45  
46 <core:element core:name="${tagname}"
47  
48 When the core:element tag is encountered, this method is called. A new
49 object is created from the module associated with the named tag and the
50 element method is called.
51  
52 =cut
53  
54 sub element {
55 my $self = shift;
56 my ($code, $attribs) = @_;
57  
58 # Protect variables in code.
59 $code =~ s/([\\\$%@])/\\$1/g;
60  
61 my $tag = $self->get_attrib ($attribs, 'name') || 'undef';
62  
63 my $ns_named_params = $self->generate_named_params ($self->{_namespaces}, 1);
64 my $attribs_named_params = $self->generate_named_params ($attribs);
65  
66 my $outcode = qq{
67 do {
68 my \%attribs = ($attribs_named_params);
69  
70 my \%namespaces = ($ns_named_params);
71  
72 #no strict;
73 #\%values;
74 #use strict;
75  
76 my \$tag = $tag;
77 \$tag =~ /^([^:]+):(.*)\$/;
78 my (\$prefix, \$type) = (\$1, \$2);
79 my \$namespace = \$namespaces{\$prefix};
80 my \$namespace_info = \$process->get_namespace_info (\$namespace);
81  
82 if (defined \$namespace_info) {
83 eval "use \$namespace_info->{module}";
84 die \$@ if \$@;
85 my \$object = \$namespace_info->{module}->new (undef, \$namespace);
86 my \$tcode = qq{
87 $code
88 };
89 my \%tattribs;
90 while (my (\$key, \$val) = each \%attribs) {
91 \$tattribs{\$key} = "'\$val'";
92 }
93 my \$code = \$object->\$type (\$tcode, \\\%tattribs);
94 eval \$code;
95 die \$\@ if \$\@;
96 }
97 };
98 };
99  
100 # } else {
101 # print "<\$tag";
102 # while (my (\$attrib, \$val) = each \%attribs) {
103 # print qq\! \$attrib="\$val"\!;
104 # }
105 # print ">\n";
106 # $code
107 # print "</\$tag>\n";
108 # }
109 #};
110 # !;
111 #print $outcode;
112  
113 return $outcode;
114 }
115  
116 =pod
117  
118 =head1 AUTHOR
119  
120 Jonathan Waxman
121 <jowaxman@bbl.med.upenn.edu>
122  
123 =head1 COPYRIGHT
124  
125 Copyright (c) 2002-2003 Jonathan A. Waxman
126 All rights reserved.
127  
128 This program is free software; you can redistribute it and/or
129 modify it under the same terms as Perl itself.
130  
131 =cut
132  
133  
134 1;