lib/PDF/FromHTML/Template/Factory.pm untested

filter: Statementstmt 0.0% 0 / 51 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 3 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 82 CC 8 SCAR 22.4
CC
8
Cov
0%
register
20.0
create
12.0
create_node
6.0
CRAP 9.4
1 package PDF::FromHTML::Template::Factory;
2  
3 use strict;
4  
5 BEGIN {
6 use vars qw(%Manifest %isBuildable);
7 }
8  
9 %Manifest = (
10  
11 # These are the instantiable nodes
12 'ALWAYS' => 'PDF::FromHTML::Template::Container::Always',
13 'CONDITIONAL' => 'PDF::FromHTML::Template::Container::Conditional',
14 'FONT' => 'PDF::FromHTML::Template::Container::Font',
15 'IF' => 'PDF::FromHTML::Template::Container::Conditional',
16 'LOOP' => 'PDF::FromHTML::Template::Container::Loop',
17 'PAGEDEF' => 'PDF::FromHTML::Template::Container::PageDef',
18 'PDFTEMPLATE' => 'PDF::FromHTML::Template::Container::PdfTemplate',
19 'ROW' => 'PDF::FromHTML::Template::Container::Row',
20 'SCOPE' => 'PDF::FromHTML::Template::Container::Scope',
21 'SECTION' => 'PDF::FromHTML::Template::Container::Section',
22 'HEADER' => 'PDF::FromHTML::Template::Container::Header',
23 'FOOTER' => 'PDF::FromHTML::Template::Container::Footer',
24  
25 'BOOKMARK' => 'PDF::FromHTML::Template::Element::Bookmark',
26 'CIRCLE' => 'PDF::FromHTML::Template::Element::Circle',
27 'HR' => 'PDF::FromHTML::Template::Element::HorizontalRule',
28 'IMAGE' => 'PDF::FromHTML::Template::Element::Image',
29 'PAGEBREAK' => 'PDF::FromHTML::Template::Element::PageBreak',
30 'LINE' => 'PDF::FromHTML::Template::Element::Line',
31 'TEXTBOX' => 'PDF::FromHTML::Template::Element::TextBox',
32 'VAR' => 'PDF::FromHTML::Template::Element::Var',
33 'WEBLINK' => 'PDF::FromHTML::Template::Element::Weblink',
34  
35 # These are the helper objects
36  
37 'TEXTOBJECT' => 'PDF::FromHTML::Template::TextObject',
38 'CONTEXT' => 'PDF::FromHTML::Template::Context',
39 'ITERATOR' => 'PDF::FromHTML::Template::Iterator',
40  
41 'MARGIN' => 'PDF::FromHTML::Template::Container::Margin',
42  
43 'CONTAINER' => 'PDF::FromHTML::Template::Container',
44 'ELEMENT' => 'PDF::FromHTML::Template::Element',
45  
46 'BASE' => 'PDF::FromHTML::Template::Base',
47 );
48  
49 %isBuildable = map { $_ => 1 } qw(
50 ALWAYS
51 BOOKMARK
52 CIRCLE
53 CONDITIONAL
54 FONT
55 FOOTER
56 HEADER
57 HR
58 IF
59 IMAGE
60 LINE
61 LOOP
62 PAGEBREAK
63 PAGEDEF
64 PDFTEMPLATE
65 ROW
66 SCOPE
67 SECTION
68 TEXTBOX
69 VAR
70 WEBLINK
71 );
72  
73 sub register
74 {
75 my %params = @_;
76  
77 my @param_names = qw(name class isa);
78 for (@param_names)
79 {
80 unless ($params{$_})
81 {
82 warn "$_ was not supplied to register()\n";
83 return 0;
84 }
85 }
86  
87 my $name = uc $params{name};
88 if (exists $Manifest{$name})
89 {
90 warn "$params{name} already exists in the manifest.\n";
91 return 0;
92 }
93  
94 my $isa = uc $params{isa};
95 unless (exists $Manifest{$isa})
96 {
97 warn "$params{isa} does not exist in the manifest.\n";
98 return 0;
99 }
100  
101 $Manifest{$name} = $params{class};
102 $isBuildable{$name} = 1;
103  
104 {
105 no strict 'refs';
106 unshift @{"$params{class}::ISA"}, $Manifest{$isa};
107 }
108  
109 return 1;
110 }
111  
112 sub create
113 {
114 my $class = shift;
115 my $name = uc shift;
116  
117 return unless exists $Manifest{$name};
118  
119 (my $filename = $Manifest{$name}) =~ s!::!/!g;
120  
121 eval {
122 require "$filename.pm";
123 }; if ($@) {
124 die "Cannot find or compile PM file for '$name' ($filename)\n";
125 }
126  
127 return $Manifest{$name}->new(@_);
128 }
129  
130 sub create_node
131 {
132 my $class = shift;
133 my $name = uc shift;
134  
135 return unless exists $isBuildable{$name};
136  
137 return $class->create($name, @_);
138 }
139  
140 sub isa
141 {
142 return UNIVERSAL::isa($_[0], $Manifest{uc $_[1]})
143 if @_ >= 2 && exists $Manifest{uc $_[1]};
144  
145 UNIVERSAL::isa(@_)
146 }
147  
148 1;
149 __END__