Revision history for Perl distribution Excel::Template
-0.24 ??? Mar 0? ??:00:00 2005
+0.24 Thu Mar 10 11:00:00 2005
- Implemented the KEEP_LEADING_ZEROS node
- This wraps the keep_leading_zeros() worksheet method
- Improved code coverage with more and better tests
+ - Am now above 90% coverage.
+ - Fixed bug involving relative values.
+ - Fixed bug involving formats when multiple Excel-Template objects ran in
+ the same process.
- Improved POD linking
- Every module/node reference in POD should link to the appropriate POD
# http://module-build.sourceforge.net/META-spec.html
#XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX#
name: Excel-Template
-version: 0.23
+version: 0.24
version_from: lib/Excel/Template.pm
installdirs: site
requires:
File::Basename: 0.01
IO::Scalar: 0.01
Spreadsheet::WriteExcel: 0.42
+ Spreadsheet::WriteExcel::Utility: 0.01
Test::More: 0.01
XML::Parser: 0.01
eval {
$self->_prepare_output($xls);
};
+print $@ if $@;
$xls->close;
=item * L<ROW|Excel::Template::Container::Row>
-This node represents a row of data. This is the A in A1.
+This node represents a row of data. This is the 1 in A1. There is no COLUMN node, as of yet.
=item * L<FORMAT|Excel::Template::Container::Format>
Excel::Template is also part of the CPAN Kwalitee initiative, being one of the top 100 non-core modules downloaded from CPAN. If you wish to help out, please feel free to contribute tests, patches, and/or suggestions.
- -----------------------------------------------------------------------
- File stmt brnch cond sub pod time total
- -----------------------------------------------------------------------
- blib/lib/Excel/Template.pm 96.0 62.5 58.8 100.0 100.0 25.2 86.2
- ...ib/Excel/Template/Base.pm 87.0 50.0 66.7 81.8 87.5 8.7 83.0
- ...cel/Template/Container.pm 71.4 50.0 33.3 70.0 80.0 4.9 68.4
- ...emplate/Container/Bold.pm 100.0 n/a n/a 100.0 0.0 0.7 95.0
- .../Container/Conditional.pm 64.9 57.5 66.7 100.0 0.0 0.7 63.9
- ...plate/Container/Format.pm 100.0 n/a n/a 100.0 0.0 0.7 96.6
- ...plate/Container/Hidden.pm 100.0 n/a n/a 100.0 0.0 0.1 95.0
- ...plate/Container/Italic.pm 100.0 n/a n/a 100.0 0.0 0.1 95.0
- ...plate/Container/Locked.pm 100.0 n/a n/a 100.0 0.0 0.1 95.0
- ...emplate/Container/Loop.pm 90.9 50.0 50.0 100.0 50.0 0.5 80.4
- ...late/Container/Outline.pm 100.0 n/a n/a 100.0 0.0 0.1 95.0
- ...Template/Container/Row.pm 100.0 75.0 n/a 100.0 50.0 0.3 93.8
- ...mplate/Container/Scope.pm 100.0 n/a n/a 100.0 n/a 0.1 100.0
- ...plate/Container/Shadow.pm 100.0 n/a n/a 100.0 0.0 0.1 95.0
- ...te/Container/Strikeout.pm 100.0 n/a n/a 100.0 0.0 0.1 95.0
- ...ate/Container/Workbook.pm 100.0 n/a n/a 100.0 n/a 0.9 100.0
- ...te/Container/Worksheet.pm 94.1 50.0 n/a 100.0 0.0 0.9 88.0
- ...Excel/Template/Context.pm 84.3 53.4 54.2 100.0 92.3 19.5 76.0
- ...Excel/Template/Element.pm 100.0 n/a n/a 100.0 n/a 0.5 100.0
- ...mplate/Element/Backref.pm 100.0 50.0 33.3 100.0 0.0 0.1 87.1
- .../Template/Element/Cell.pm 95.8 65.0 80.0 100.0 66.7 3.8 86.9
- ...mplate/Element/Formula.pm 100.0 n/a n/a 100.0 0.0 0.3 94.1
- ...Template/Element/Range.pm 100.0 66.7 n/a 100.0 66.7 0.2 93.3
- ...l/Template/Element/Var.pm 100.0 n/a n/a 100.0 0.0 0.1 94.1
- ...Excel/Template/Factory.pm 100.0 73.1 n/a 100.0 100.0 16.3 92.6
- .../Excel/Template/Format.pm 98.3 81.2 33.3 100.0 100.0 10.0 93.2
- ...xcel/Template/Iterator.pm 98.6 80.0 70.6 100.0 83.3 1.9 90.3
- ...el/Template/TextObject.pm 92.9 62.5 33.3 100.0 50.0 3.1 83.0
- Total 92.0 63.5 58.3 97.5 98.5 100.0 86.0
- -----------------------------------------------------------------------
+ ---------------------------- ------ ------ ------ ------ ------ ------ ------
+ File stmt branch cond sub pod time total
+ ---------------------------- ------ ------ ------ ------ ------ ------ ------
+ blib/lib/Excel/Template.pm 96.0 64.3 58.8 100.0 100.0 26.3 85.8
+ ...ib/Excel/Template/Base.pm 94.4 50.0 n/a 100.0 75.0 6.6 90.0
+ ...cel/Template/Container.pm 100.0 50.0 33.3 100.0 66.7 4.5 88.1
+ ...emplate/Container/Bold.pm 100.0 n/a n/a 100.0 0.0 0.2 95.0
+ .../Container/Conditional.pm 95.9 90.0 66.7 100.0 0.0 1.7 91.0
+ ...plate/Container/Format.pm 100.0 n/a n/a 100.0 0.0 0.6 96.6
+ ...plate/Container/Hidden.pm 100.0 n/a n/a 100.0 0.0 0.2 95.0
+ ...plate/Container/Italic.pm 100.0 n/a n/a 100.0 0.0 0.2 95.0
+ ...ainer/KeepLeadingZeros.pm 100.0 100.0 n/a 100.0 0.0 0.1 96.3
+ ...plate/Container/Locked.pm 100.0 n/a n/a 100.0 0.0 0.1 95.0
+ ...emplate/Container/Loop.pm 96.8 50.0 50.0 100.0 50.0 0.4 84.6
+ ...late/Container/Outline.pm 100.0 n/a n/a 100.0 0.0 0.1 95.0
+ ...Template/Container/Row.pm 100.0 75.0 n/a 100.0 50.0 0.3 93.8
+ ...mplate/Container/Scope.pm 100.0 n/a n/a 100.0 n/a 0.1 100.0
+ ...plate/Container/Shadow.pm 100.0 n/a n/a 100.0 0.0 0.1 95.0
+ ...te/Container/Strikeout.pm 100.0 n/a n/a 100.0 0.0 0.1 95.0
+ ...ate/Container/Workbook.pm 100.0 n/a n/a 100.0 n/a 1.0 100.0
+ ...te/Container/Worksheet.pm 94.7 75.0 n/a 100.0 50.0 1.0 90.3
+ ...Excel/Template/Context.pm 98.0 80.0 75.0 100.0 93.3 23.4 91.8
+ ...Excel/Template/Element.pm 100.0 n/a n/a 100.0 n/a 0.3 100.0
+ ...mplate/Element/Backref.pm 100.0 50.0 33.3 100.0 0.0 0.2 87.1
+ .../Template/Element/Cell.pm 97.9 75.0 80.0 100.0 66.7 3.9 91.1
+ ...mplate/Element/Formula.pm 100.0 n/a n/a 100.0 0.0 0.2 94.1
+ ...Template/Element/Range.pm 100.0 66.7 n/a 100.0 66.7 0.2 93.3
+ ...l/Template/Element/Var.pm 100.0 n/a n/a 100.0 0.0 0.2 94.1
+ ...Excel/Template/Factory.pm 100.0 75.0 n/a 100.0 100.0 15.5 92.4
+ .../Excel/Template/Format.pm 98.4 75.0 33.3 100.0 66.7 8.1 91.2
+ ...xcel/Template/Iterator.pm 98.6 80.0 70.6 100.0 83.3 1.4 90.3
+ ...el/Template/TextObject.pm 92.9 62.5 33.3 100.0 50.0 3.2 83.0
+ Total 98.0 75.2 63.4 100.0 98.5 100.0 92.2
+ ---------------------------- ------ ------ ------ ------ ------ ------ ------
=head1 COPYRIGHT
my ($context) = @_;
my $old_format = $context->active_format;
- my $format = Excel::Template::Format->copy(
+ my $format = $context->format_object->copy(
$context, $old_format,
%{$self},
{
$iterator->next;
- unless ($self->iterate_over_children($context))
- {
- $iterator->back_up;
- last;
- }
+ $self->iterate_over_children($context);
+
+ # It doesn't seem that iterate_over_children() can ever fail, because
+ # I'm not sure that render() can return false. In PDF::Template, where
+ # this module got most of its code, render() can certainly return false,
+ # in the case of page-breaks. I left the code in because it didn't seem
+ # like it would hurt.
+ #unless ($self->iterate_over_children($context))
+ #{
+ # $iterator->back_up;
+ # last;
+ #}
}
$iterator->exit_scope;
return 1;
}
+# These methods are used in PDF::Template to calculate pagebreaks. I'm not sure
+# if they will ever be needed in Excel::Template.
#sub total_of
#{
# my $self = shift;
use Excel::Template::Format;
# This is a helper object. It is not instantiated by the user, nor does it
-# represent an XML object. Rather, every container will use this object to
+# represent an XML node. Rather, every container will use this object to
# maintain the context for its children.
my %isAbsolute = map { $_ => ~~1 } qw(
my $self = $class->SUPER::new(@_);
$self->{ACTIVE_WORKSHEET} = undef;
- $self->{ACTIVE_FORMAT} = Excel::Template::Format->blank_format($self);
+ $self->{FORMAT_OBJECT} = Excel::Template::Format->new;
+ $self->{ACTIVE_FORMAT} = $self->{FORMAT_OBJECT}->blank_format($self);
$self->{WORKSHEET_NAMES} = undef;
$self->{__MARKS} = {};
return $prev_val unless defined $obj_val;
# Prevent divide-by-zero issues.
- return $val if $op eq '/' and $val == 0;
+ return $prev_val if $op eq '/' and $val == 0;
my $new_val;
for ($op)
return @{ $self->{REFERENCES}{$ref}[-1] };
}
+sub format_object { $_[0]{FORMAT_OBJECT} }
+
1;
__END__
=head2 add_reference
+=head2 format_object
+
=head2 get
=head2 get_all_references
# places in the file. This provides a way of keeping track of already-allocated
# formats and making new formats based on old ones.
-{
- my %_Formats;
-
- sub _assign { $_Formats{$_[0]} = $_[1]; $_Formats{$_[1]} = $_[0] }
-# my $key = shift;
-# my $format = shift;
-# $_Formats{$key} = $format;
-# $_Formats{$format} = $key;
-# }
-
- sub _retrieve_key { $_Formats{ $_[0] } }
-# my $format = shift;
-# return $_Formats{$format};
-# }
-
- *_retrieve_format = \&_retrieve_key;
-# sub _retrieve_format {
-# my $key = shift;
-# return $_Formats{$key};
-# }
-}
+sub new { bless {}, shift }
+
+sub _assign { $_[0]{$_[1]} = $_[2]; $_[0]{$_[2]} = $_[1] }
+# my $self = shift;
+# my ($key, $format) = @_;
+# $self->{$key} = $format;
+# $self->{$format} = $key;
+#}
+
+sub _retrieve_key { $_[0]{ $_[1] } }
+# my $self = shift;
+# my ($format) = @_;
+# return $self->{$format};
+#}
+
+*_retrieve_format = \&_retrieve_key;
+#sub _retrieve_format {
+# my $self = shift;
+# my ($key) = @_;
+# return $self->{$key};
+#}
{
my @_boolean_formats = qw(
$params{lc $_} = delete $params{$_} for keys %params;
my @parts = (
- (map { !! $params{$_} } @_boolean_formats),
+ (map { !!$params{$_} } @_boolean_formats),
(map { $params{$_} ? $params{$_} + 0 : '' } @_integer_formats),
(map { $params{$_} || '' } @_string_formats),
);
sub copy
{
- shift;
+ my $self = shift;
my ($context, $old_fmt, %properties) = @_;
# This is a key used for non-format book-keeping.
delete $properties{ ELEMENTS };
- defined(my $key = _retrieve_key($old_fmt))
+ defined(my $key = _retrieve_key($self, $old_fmt))
|| die "Internal Error: Cannot find key for format '$old_fmt'!\n";
my %params = _key_to_params($key);
my $new_key = _params_to_key(%params);
- my $format = _retrieve_format($new_key);
+ my $format = _retrieve_format($self, $new_key);
return $format if $format;
$format = $context->{XLS}->add_format(%params);
- _assign($new_key, $format);
+ _assign($self, $new_key, $format);
return $format;
}
}
sub blank_format
{
- shift;
+ my $self = shift;
my ($context) = @_;
my $blank_key = _params_to_key();
- my $format = _retrieve_format($blank_key);
+ my $format = _retrieve_format($self, $blank_key);
return $format if $format;
$format = $context->{XLS}->add_format;
- _assign($blank_key, $format);
+ _assign($self, $blank_key, $format);
return $format;
}
my @calls = mock::get_calls;
is( join( $/, @calls, '' ), <<__END_EXPECTED__, 'Calls match up' );
Spreadsheet::WriteExcelXML::new( 'filename' )
+Spreadsheet::WriteExcelXML::add_format( '' )
Spreadsheet::WriteExcelXML::close( '' )
__END_EXPECTED__
}
my @calls = mock::get_calls;
is( join( $/, @calls, '' ), <<__END_EXPECTED__, 'Calls match up' );
Spreadsheet::WriteExcel::new( 'filename' )
+Spreadsheet::WriteExcel::add_format( '' )
Spreadsheet::WriteExcel::close( '' )
__END_EXPECTED__
}
--- /dev/null
+BEGIN{ $^W = 0 }
+use strict;
+
+use Test::More tests => 4;
+
+use lib 't';
+use mock;
+mock::reset;
+
+my $CLASS = 'Excel::Template';
+use_ok( $CLASS );
+
+my $object = $CLASS->new(
+ file => \*DATA,
+);
+isa_ok( $object, $CLASS );
+
+ok( $object->write_file( 'filename' ), 'Successfuly wrote file' );
+
+my @calls = mock::get_calls;
+is( join( $/, @calls, '' ), <<__END_EXPECTED__, 'Calls match up' );
+Spreadsheet::WriteExcel::new( 'filename' )
+Spreadsheet::WriteExcel::add_format( '' )
+Spreadsheet::WriteExcel::add_worksheet( '' )
+Spreadsheet::WriteExcel::Worksheet::new( '' )
+Spreadsheet::WriteExcel::Worksheet::set_row( '0', '8' )
+Spreadsheet::WriteExcel::Worksheet::write( '0', '0', '', '1' )
+Spreadsheet::WriteExcel::Worksheet::set_row( '1', '10' )
+Spreadsheet::WriteExcel::Worksheet::write( '1', '0', '', '1' )
+Spreadsheet::WriteExcel::Worksheet::set_row( '2', '6' )
+Spreadsheet::WriteExcel::Worksheet::write( '2', '0', '', '1' )
+Spreadsheet::WriteExcel::Worksheet::set_row( '3', '16' )
+Spreadsheet::WriteExcel::Worksheet::write( '3', '0', '', '1' )
+Spreadsheet::WriteExcel::Worksheet::set_row( '4', '4' )
+Spreadsheet::WriteExcel::Worksheet::write( '4', '0', '', '1' )
+Spreadsheet::WriteExcel::Worksheet::set_row( '5', '8' )
+Spreadsheet::WriteExcel::Worksheet::write( '5', '0', '', '1' )
+Spreadsheet::WriteExcel::close( '' )
+__END_EXPECTED__
+
+__DATA__
+<workbook>
+ <worksheet height="8">
+ <row>
+ <cell />
+ </row>
+ <row height="+2">
+ <cell />
+ </row>
+ <row height="-2">
+ <cell />
+ </row>
+ <row height="*2">
+ <cell />
+ </row>
+ <row height="/2">
+ <cell />
+ </row>
+ <row height="/0">
+ <cell />
+ </row>
+ </worksheet>
+</workbook>
+
my ($self, $context) = @_;
my $old_format = $context->active_format;
- my $format = Excel::Template::Format->copy(
+ my $format = $context->format_object->copy(
$context, $old_format,
align => 'center', bold => 1,