1 package Excel::Template::Factory;
7 # These are the instantiable nodes
8 'IF' => 'Excel::Template::Container::Conditional',
9 'LOOP' => 'Excel::Template::Container::Loop',
10 'ROW' => 'Excel::Template::Container::Row',
11 'SCOPE' => 'Excel::Template::Container::Scope',
12 'WORKBOOK' => 'Excel::Template::Container::Workbook',
13 'WORKSHEET' => 'Excel::Template::Container::Worksheet',
15 'BACKREF' => 'Excel::Template::Element::Backref',
16 'CELL' => 'Excel::Template::Element::Cell',
17 'FORMULA' => 'Excel::Template::Element::Formula',
18 'FREEZEPANES' => 'Excel::Template::Element::FreezePanes',
19 'IMAGE' => 'Excel::Template::Element::Image',
20 'RANGE' => 'Excel::Template::Element::Range',
21 'VAR' => 'Excel::Template::Element::Var',
23 'FORMAT' => 'Excel::Template::Container::Format',
25 # These are all the Format short-cut objects
26 # They are also instantiable
27 'BOLD' => 'Excel::Template::Container::Bold',
28 'HIDDEN' => 'Excel::Template::Container::Hidden',
29 'ITALIC' => 'Excel::Template::Container::Italic',
30 'LOCKED' => 'Excel::Template::Container::Locked',
31 'OUTLINE' => 'Excel::Template::Container::Outline',
32 'SHADOW' => 'Excel::Template::Container::Shadow',
33 'STRIKEOUT' => 'Excel::Template::Container::Strikeout',
35 'KEEP_LEADING_ZEROS' => 'Excel::Template::Container::KeepLeadingZeros',
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 my %isBuildable = map { $_ => ~~1 } qw(
51 FORMAT BOLD HIDDEN ITALIC LOCKED OUTLINE SHADOW STRIKEOUT
52 IF ROW LOOP SCOPE KEEP_LEADING_ZEROS
53 CELL FORMULA FREEZEPANES IMAGE
64 unless ( exists $Loaded{$class} )
66 (my $filename = $class) =~ s!::!/!g;
68 require "$filename.pm";
70 die "Cannot find or compile PM file for '$class' ($filename)\n";
73 $Loaded{$class} = ~~1;
81 my @param_names = qw(name class isa);
91 warn "$_ was not supplied to register()\n" if $^W;
96 my $name = uc $params{name};
97 if (exists $Manifest{$name})
99 warn "$params{name} already exists in the manifest.\n" if $^W;
103 my $isa = uc $params{isa};
104 unless (exists $Manifest{$isa})
106 warn "$params{isa} does not exist in the manifest.\n" if $^W;
112 unshift @{"$params{class}::ISA"}, $Manifest{$isa};
115 $self->_load_class( $Manifest{$isa} );
116 $self->_load_class( $params{class} );
118 $Manifest{$name} = $params{class};
119 $isBuildable{$name} = ~~1;
130 return unless exists $Manifest{$name};
132 $self->_load_class( $Manifest{$name} );
134 return $Manifest{$name}->new(@_);
142 return unless exists $isBuildable{$name};
144 return $self->_create($name, @_);
149 return unless @_ >= 2;
150 exists $Manifest{uc $_[1]}
151 ? UNIVERSAL::isa($_[0], $Manifest{uc $_[1]})
157 return unless @_ >= 1;
159 isa( $_[0], $_ ) && return ~~1 for qw( VAR BACKREF RANGE );
168 Excel::Template::Factory
172 To provide a common way to instantiate Excel::Template nodes
178 Use this to register your own nodes.
186 This is a customized isa() wrapper for syntactic sugar
192 Rob Kinyon (rob.kinyon@gmail.com)