use strict;
-BEGIN {
- use vars qw(%Manifest %isBuildable);
-}
-
-%Manifest = (
+my %Manifest = (
# These are the instantiable nodes
'IF' => 'Excel::Template::Container::Conditional',
'WORKBOOK' => 'Excel::Template::Container::Workbook',
'WORKSHEET' => 'Excel::Template::Container::Worksheet',
- 'CELL' => 'Excel::Template::Element::Cell',
- 'FORMULA' => 'Excel::Template::Element::Formula',
- 'VAR' => 'Excel::Template::Element::Var',
+ 'BACKREF' => 'Excel::Template::Element::Backref',
+ 'CELL' => 'Excel::Template::Element::Cell',
+ 'FORMULA' => 'Excel::Template::Element::Formula',
+ 'FREEZEPANES' => 'Excel::Template::Element::FreezePanes',
+ 'IMAGE' => 'Excel::Template::Element::Image',
+ 'RANGE' => 'Excel::Template::Element::Range',
+ 'VAR' => 'Excel::Template::Element::Var',
'FORMAT' => 'Excel::Template::Container::Format',
# These are all the Format short-cut objects
+# They are also instantiable
'BOLD' => 'Excel::Template::Container::Bold',
'HIDDEN' => 'Excel::Template::Container::Hidden',
'ITALIC' => 'Excel::Template::Container::Italic',
'SHADOW' => 'Excel::Template::Container::Shadow',
'STRIKEOUT' => 'Excel::Template::Container::Strikeout',
-# These are the helper objects
+ 'KEEP_LEADING_ZEROS' => 'Excel::Template::Container::KeepLeadingZeros',
+# These are the helper objects
+# They are also in here to make E::T::Factory::isa() work.
'CONTEXT' => 'Excel::Template::Context',
'ITERATOR' => 'Excel::Template::Iterator',
'TEXTOBJECT' => 'Excel::Template::TextObject',
'BASE' => 'Excel::Template::Base',
);
-%isBuildable = map { $_ => 1 } qw(
- BOLD
- CELL
- FORMAT
- FORMULA
- IF
- ITALIC
- OUTLINE
- LOOP
- ROW
- SHADOW
- STRIKEOUT
- VAR
- WORKBOOK
- WORKSHEET
+my %isBuildable = map { $_ => ~~1 } qw(
+ WORKBOOK WORKSHEET
+ FORMAT BOLD HIDDEN ITALIC LOCKED OUTLINE SHADOW STRIKEOUT
+ IF ROW LOOP SCOPE KEEP_LEADING_ZEROS
+ CELL FORMULA FREEZEPANES IMAGE
+ VAR BACKREF RANGE
);
-sub register
{
- my %params = @_;
-
- my @param_names = qw(name class isa);
- for (@param_names)
+ my %Loaded;
+ sub _load_class
{
- unless ($params{$_})
+ my $self = shift;
+ my ($class) = @_;
+
+ unless ( exists $Loaded{$class} )
{
- warn "$_ was not supplied to register()\n";
- return 0;
+ (my $filename = $class) =~ s!::!/!g;
+ eval {
+ require "$filename.pm";
+ }; if ($@) {
+ die "Cannot find or compile PM file for '$class' ($filename)\n";
+ }
+
+ $Loaded{$class} = ~~1;
}
- }
- my $name = uc $params{name};
- if (exists $Manifest{$name})
- {
- warn "$params{name} already exists in the manifest.\n";
- return 0;
+ return ~~1;
}
+}
- my $isa = uc $params{isa};
- unless (exists $Manifest{$isa})
+{
+ my @param_names = qw(name class isa);
+ sub register
{
- warn "$params{isa} does not exist in the manifest.\n";
- return 0;
- }
+ my $self = shift;
+ my %params = @_;
- $Manifest{$name} = $params{class};
- $isBuildable{$name} = 1;
+ for (@param_names)
+ {
+ unless ($params{$_})
+ {
+ warn "$_ was not supplied to register()\n" if $^W;
+ return;
+ }
+ }
- {
- no strict 'refs';
- unshift @{"$params{class}::ISA"}, $Manifest{$isa};
- }
+ my $name = uc $params{name};
+ if (exists $Manifest{$name})
+ {
+ warn "$params{name} already exists in the manifest.\n" if $^W;
+ return;
+ }
- return 1;
+ my $isa = uc $params{isa};
+ unless (exists $Manifest{$isa})
+ {
+ warn "$params{isa} does not exist in the manifest.\n" if $^W;
+ return;
+ }
+
+ {
+ no strict 'refs';
+ unshift @{"$params{class}::ISA"}, $Manifest{$isa};
+ }
+
+ $self->_load_class( $Manifest{$isa} );
+ $self->_load_class( $params{class} );
+
+ $Manifest{$name} = $params{class};
+ $isBuildable{$name} = ~~1;
+
+ return ~~1;
+ }
}
-sub create
+sub _create
{
- my $class = shift;
+ my $self = shift;
my $name = uc shift;
return unless exists $Manifest{$name};
- (my $filename = $Manifest{$name}) =~ s!::!/!g;
-
- eval {
- require "$filename.pm";
- }; if ($@) {
- die "Cannot find or compile PM file for '$name' ($filename)\n";
- }
+ $self->_load_class( $Manifest{$name} );
return $Manifest{$name}->new(@_);
}
-sub create_node
+sub _create_node
{
- my $class = shift;
+ my $self = shift;
my $name = uc shift;
return unless exists $isBuildable{$name};
- return $class->create($name, @_);
+ return $self->_create($name, @_);
}
sub isa
: UNIVERSAL::isa(@_)
}
+sub is_embedded
+{
+ return unless @_ >= 1;
+
+ isa( $_[0], $_ ) && return ~~1 for qw( VAR BACKREF RANGE );
+ return;
+}
+
1;
__END__
=head1 PURPOSE
-=head1 NODE NAME
+To provide a common way to instantiate Excel::Template nodes
-=head1 INHERITANCE
+=head1 USAGE
-=head1 ATTRIBUTES
+=head2 register()
-=head1 CHILDREN
+Use this to register your own nodes.
-=head1 AFFECTS
+Example forthcoming.
-=head1 DEPENDENCIES
+=head1 METHODS
-=head1 USAGE
+=head2 isa
+
+This is a customized isa() wrapper for syntactic sugar
+
+=head2 is_embedded
=head1 AUTHOR
-Rob Kinyon (rkinyon@columbus.rr.com)
+Rob Kinyon (rob.kinyon@gmail.com)
=head1 SEE ALSO