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 'MERGE_RANGE' => 'Excel::Template::Element::MergeRange',
20 'IMAGE' => 'Excel::Template::Element::Image',
21 'RANGE' => 'Excel::Template::Element::Range',
22 'VAR' => 'Excel::Template::Element::Var',
24 'FORMAT' => 'Excel::Template::Container::Format',
26 # These are all the Format short-cut objects
27 # They are also instantiable
28 'BOLD' => 'Excel::Template::Container::Bold',
29 'HIDDEN' => 'Excel::Template::Container::Hidden',
30 'ITALIC' => 'Excel::Template::Container::Italic',
31 'LOCKED' => 'Excel::Template::Container::Locked',
32 'OUTLINE' => 'Excel::Template::Container::Outline',
33 'SHADOW' => 'Excel::Template::Container::Shadow',
34 'STRIKEOUT' => 'Excel::Template::Container::Strikeout',
36 'KEEP_LEADING_ZEROS' => 'Excel::Template::Container::KeepLeadingZeros',
38 # These are the helper objects
39 # They are also in here to make E::T::Factory::isa() work.
40 'CONTEXT' => 'Excel::Template::Context',
41 'ITERATOR' => 'Excel::Template::Iterator',
42 'TEXTOBJECT' => 'Excel::Template::TextObject',
44 'CONTAINER' => 'Excel::Template::Container',
45 'ELEMENT' => 'Excel::Template::Element',
47 'BASE' => 'Excel::Template::Base',
50 my %isBuildable = map { $_ => ~~1 } qw(
52 FORMAT BOLD HIDDEN ITALIC LOCKED OUTLINE SHADOW STRIKEOUT
53 IF ROW LOOP SCOPE KEEP_LEADING_ZEROS
54 CELL FORMULA FREEZEPANES IMAGE MERGE_RANGE
65 unless ( exists $Loaded{$class} )
67 (my $filename = $class) =~ s!::!/!g;
69 require "$filename.pm";
71 die "Cannot find or compile PM file for '$class' ($filename) because $@\n";
74 $Loaded{$class} = ~~1;
82 my @param_names = qw(name class isa);
92 warn "$_ was not supplied to register()\n" if $^W;
97 my $name = uc $params{name};
98 if (exists $Manifest{$name})
100 warn "$params{name} already exists in the manifest.\n" if $^W;
104 my $isa = uc $params{isa};
105 unless (exists $Manifest{$isa})
107 warn "$params{isa} does not exist in the manifest.\n" if $^W;
113 unshift @{"$params{class}::ISA"}, $Manifest{$isa};
116 $self->_load_class( $Manifest{$isa} );
117 $self->_load_class( $params{class} );
119 $Manifest{$name} = $params{class};
120 $isBuildable{$name} = ~~1;
131 return unless exists $Manifest{$name};
133 $self->_load_class( $Manifest{$name} );
135 return $Manifest{$name}->new(@_);
143 return unless exists $isBuildable{$name};
145 return $self->_create($name, @_);
150 return unless @_ >= 2;
151 exists $Manifest{uc $_[1]}
152 ? UNIVERSAL::isa($_[0], $Manifest{uc $_[1]})
158 return unless @_ >= 1;
160 isa( $_[0], $_ ) && return ~~1 for qw( VAR BACKREF RANGE );
169 Excel::Template::Factory - Excel::Template::Factory
173 To provide a common way to instantiate Excel::Template nodes
179 Use this to register your own nodes.
187 This is a customized isa() wrapper for syntactic sugar
193 Rob Kinyon (rob.kinyon@gmail.com)