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 'BACKREF' => 'Excel::Template::Element::Backref',
20 'CELL' => 'Excel::Template::Element::Cell',
21 'FORMULA' => 'Excel::Template::Element::Formula',
22 'RANGE' => 'Excel::Template::Element::Range',
23 'VAR' => 'Excel::Template::Element::Var',
25 'FORMAT' => 'Excel::Template::Container::Format',
27 # These are all the Format short-cut objects
28 # They are also instantiable
29 'BOLD' => 'Excel::Template::Container::Bold',
30 'HIDDEN' => 'Excel::Template::Container::Hidden',
31 'ITALIC' => 'Excel::Template::Container::Italic',
32 'LOCKED' => 'Excel::Template::Container::Locked',
33 'OUTLINE' => 'Excel::Template::Container::Outline',
34 'SHADOW' => 'Excel::Template::Container::Shadow',
35 'STRIKEOUT' => 'Excel::Template::Container::Strikeout',
37 # These are the helper objects
38 # They are also in here to make E::T::Factory::isa() work.
39 'CONTEXT' => 'Excel::Template::Context',
40 'ITERATOR' => 'Excel::Template::Iterator',
41 'TEXTOBJECT' => 'Excel::Template::TextObject',
43 'CONTAINER' => 'Excel::Template::Container',
44 'ELEMENT' => 'Excel::Template::Element',
46 'BASE' => 'Excel::Template::Base',
49 %isBuildable = map { $_ => 1 } qw(
75 my @param_names = qw(name class isa);
80 warn "$_ was not supplied to register()\n";
85 my $name = uc $params{name};
86 if (exists $Manifest{$name})
88 warn "$params{name} already exists in the manifest.\n";
92 my $isa = uc $params{isa};
93 unless (exists $Manifest{$isa})
95 warn "$params{isa} does not exist in the manifest.\n";
99 $Manifest{$name} = $params{class};
100 $isBuildable{$name} = 1;
104 unshift @{"$params{class}::ISA"}, $Manifest{$isa};
115 return unless exists $Manifest{$name};
117 (my $filename = $Manifest{$name}) =~ s!::!/!g;
120 require "$filename.pm";
122 die "Cannot find or compile PM file for '$name' ($filename)\n";
125 return $Manifest{$name}->new(@_);
133 return unless exists $isBuildable{$name};
135 return $class->create($name, @_);
140 return unless @_ >= 2;
141 exists $Manifest{uc $_[1]}
142 ? UNIVERSAL::isa($_[0], $Manifest{uc $_[1]})
148 return unless @_ >= 1;
150 isa( $_[0], $_ ) && return !!1 for qw( VAR BACKREF RANGE );
159 Excel::Template::Factory
163 To provide a common way to instantiate Excel::Template nodes
169 Use this to register your own nodes.
175 Rob Kinyon (rob.kinyon@gmail.com)