1 package Excel::Template::Factory;
6 use vars qw(%Manifest %isBuildable);
11 # These are the instantiable nodes
12 'IF' => 'Excel::Template::Container::Conditional',
13 'LOOP' => 'Excel::Template::Container::Loop',
14 'ROW' => 'Excel::Template::Container::Row',
15 'SCOPE' => 'Excel::Template::Container::Scope',
16 'WORKBOOK' => 'Excel::Template::Container::Workbook',
17 'WORKSHEET' => 'Excel::Template::Container::Worksheet',
19 'CELL' => 'Excel::Template::Element::Cell',
20 'FORMULA' => 'Excel::Template::Element::Formula',
21 'VAR' => 'Excel::Template::Element::Var',
23 'FORMAT' => 'Excel::Template::Container::Format',
25 # These are all the Format short-cut objects
26 'BOLD' => 'Excel::Template::Container::Bold',
27 'HIDDEN' => 'Excel::Template::Container::Hidden',
28 'ITALIC' => 'Excel::Template::Container::Italic',
29 'LOCKED' => 'Excel::Template::Container::Locked',
30 'OUTLINE' => 'Excel::Template::Container::Outline',
31 'SHADOW' => 'Excel::Template::Container::Shadow',
32 'STRIKEOUT' => 'Excel::Template::Container::Strikeout',
34 # These are the helper objects
36 'CONTEXT' => 'Excel::Template::Context',
37 'ITERATOR' => 'Excel::Template::Iterator',
38 'TEXTOBJECT' => 'Excel::Template::TextObject',
40 'CONTAINER' => 'Excel::Template::Container',
41 'ELEMENT' => 'Excel::Template::Element',
43 'BASE' => 'Excel::Template::Base',
46 %isBuildable = map { $_ => 1 } qw(
67 my @param_names = qw(name class isa);
72 warn "$_ was not supplied to register()\n";
77 my $name = uc $params{name};
78 if (exists $Manifest{$name})
80 warn "$params{name} already exists in the manifest.\n";
84 my $isa = uc $params{isa};
85 unless (exists $Manifest{$isa})
87 warn "$params{isa} does not exist in the manifest.\n";
91 $Manifest{$name} = $params{class};
92 $isBuildable{$name} = 1;
96 unshift @{"$params{class}::ISA"}, $Manifest{$isa};
107 return unless exists $Manifest{$name};
109 (my $filename = $Manifest{$name}) =~ s!::!/!g;
112 require "$filename.pm";
114 die "Cannot find or compile PM file for '$name' ($filename)\n";
117 return $Manifest{$name}->new(@_);
125 return unless exists $isBuildable{$name};
127 return $class->create($name, @_);
132 return unless @_ >= 2;
133 exists $Manifest{uc $_[1]}
134 ? UNIVERSAL::isa($_[0], $Manifest{uc $_[1]})
143 Excel::Template::Factory
163 Rob Kinyon (rob.kinyon@gmail.com)