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 'RANGE' => 'Excel::Template::Element::Range',
19 'VAR' => 'Excel::Template::Element::Var',
21 'FORMAT' => 'Excel::Template::Container::Format',
23 # These are all the Format short-cut objects
24 # They are also instantiable
25 'BOLD' => 'Excel::Template::Container::Bold',
26 'HIDDEN' => 'Excel::Template::Container::Hidden',
27 'ITALIC' => 'Excel::Template::Container::Italic',
28 'LOCKED' => 'Excel::Template::Container::Locked',
29 'OUTLINE' => 'Excel::Template::Container::Outline',
30 'SHADOW' => 'Excel::Template::Container::Shadow',
31 'STRIKEOUT' => 'Excel::Template::Container::Strikeout',
33 'KEEP_LEADING_ZEROS' => 'Excel::Template::Container::KeepLeadingZeros',
35 # These are the helper objects
36 # They are also in here to make E::T::Factory::isa() work.
37 'CONTEXT' => 'Excel::Template::Context',
38 'ITERATOR' => 'Excel::Template::Iterator',
39 'TEXTOBJECT' => 'Excel::Template::TextObject',
41 'CONTAINER' => 'Excel::Template::Container',
42 'ELEMENT' => 'Excel::Template::Element',
44 'BASE' => 'Excel::Template::Base',
47 my %isBuildable = map { $_ => ~~1 } qw(
49 FORMAT BOLD HIDDEN ITALIC LOCKED OUTLINE SHADOW STRIKEOUT
50 IF ROW LOOP SCOPE KEEP_LEADING_ZEROS
62 unless ( exists $Loaded{$class} )
64 (my $filename = $class) =~ s!::!/!g;
66 require "$filename.pm";
68 die "Cannot find or compile PM file for '$class' ($filename)\n";
71 $Loaded{$class} = ~~1;
79 my @param_names = qw(name class isa);
89 warn "$_ was not supplied to register()\n" if $^W;
94 my $name = uc $params{name};
95 if (exists $Manifest{$name})
97 warn "$params{name} already exists in the manifest.\n" if $^W;
101 my $isa = uc $params{isa};
102 unless (exists $Manifest{$isa})
104 warn "$params{isa} does not exist in the manifest.\n" if $^W;
110 unshift @{"$params{class}::ISA"}, $Manifest{$isa};
113 $self->_load_class( $Manifest{$isa} );
114 $self->_load_class( $params{class} );
116 $Manifest{$name} = $params{class};
117 $isBuildable{$name} = ~~1;
128 return unless exists $Manifest{$name};
130 $self->_load_class( $Manifest{$name} );
132 return $Manifest{$name}->new(@_);
140 return unless exists $isBuildable{$name};
142 return $self->_create($name, @_);
147 return unless @_ >= 2;
148 exists $Manifest{uc $_[1]}
149 ? UNIVERSAL::isa($_[0], $Manifest{uc $_[1]})
155 return unless @_ >= 1;
157 isa( $_[0], $_ ) && return ~~1 for qw( VAR BACKREF RANGE );
166 Excel::Template::Factory
170 To provide a common way to instantiate Excel::Template nodes
176 Use this to register your own nodes.
184 This is a customized isa() wrapper for syntactic sugar
190 Rob Kinyon (rob.kinyon@gmail.com)