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(
76 (my $filename = $class) =~ s!::!/!g;
78 require "$filename.pm";
80 die "Cannot find or compile PM file for '$class' ($filename)\n";
87 my @param_names = qw(name class isa);
97 warn "$_ was not supplied to register()\n" if $^W;
102 my $name = uc $params{name};
103 if (exists $Manifest{$name})
105 warn "$params{name} already exists in the manifest.\n" if $^W;
109 my $isa = uc $params{isa};
110 unless (exists $Manifest{$isa})
112 warn "$params{isa} does not exist in the manifest.\n" if $^W;
118 unshift @{"$params{class}::ISA"}, $Manifest{$isa};
121 $self->_load_class( $Manifest{$isa} );
122 $self->_load_class( $params{class} );
124 $Manifest{$name} = $params{class};
125 $isBuildable{$name} = ~~1;
136 return unless exists $Manifest{$name};
138 $self->_load_class( $Manifest{$name} );
140 return $Manifest{$name}->new(@_);
148 return unless exists $isBuildable{$name};
150 return $self->_create($name, @_);
155 return unless @_ >= 2;
156 exists $Manifest{uc $_[1]}
157 ? UNIVERSAL::isa($_[0], $Manifest{uc $_[1]})
163 return unless @_ >= 1;
165 isa( $_[0], $_ ) && return ~~1 for qw( VAR BACKREF RANGE );
174 Excel::Template::Factory
178 To provide a common way to instantiate Excel::Template nodes
184 Use this to register your own nodes.
192 This is a customized isa() wrapper for syntactic sugar
198 Rob Kinyon (rob.kinyon@gmail.com)