From: Rob Kinyon Date: Fri, 25 Feb 2005 18:42:26 +0000 (+0000) Subject: Improved tests and documentation. Fixed a few bugs in register() X-Git-Tag: v0.23~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e976988f30574c0c21cfa29fc5d080827e003fb6;p=p5sagit%2FExcel-Template.git Improved tests and documentation. Fixed a few bugs in register() --- diff --git a/Changes b/Changes index f13f7fb..1d93408 100644 --- a/Changes +++ b/Changes @@ -1,10 +1,17 @@ Revision history for Perl distribution Excel::Template -0.22 Thu Feb 25 15:00:00 2005 +0.23 Fri Feb 25 15:00:00 2005 + - Improved code coverage with more and better tests + - Fixed POD bug with Devel::Cover results + - Fixed bugs found in Factory::register while writing tests + - Base class wasn't loaded when class was registered. + - If registered class didn't exist, wouldn't die until parse() + +0.22 Thu Feb 24 15:00:00 2005 - new() now accepts either FILE or FILENAME - parse() now accepts a filehandle or a filename -0.21 Wed Feb 24 14:00:00 2005 +0.21 Thu Feb 24 12:00:00 2005 - Fixed documentation bug in BACKREF (Thanks to Paul Williams) - Added code to Makefile.PL to skip .swp files in the Makefile - Added RENDERER option to new() diff --git a/MANIFEST b/MANIFEST index 9c1c70d..98df01a 100644 --- a/MANIFEST +++ b/MANIFEST @@ -64,9 +64,12 @@ t/015.xml t/016_renderers.t t/016.xml t/017_filehandle.t +t/018_register.t +t/019_output.t t/pod.t t/pod_coverage.t t/mock.pm +t/Register_018.pm t/Spreadsheet/WriteExcel.pm t/Spreadsheet/WriteExcelXML.pm t/Spreadsheet/WriteExcel/Worksheet.pm diff --git a/META.yml b/META.yml index 1afa0e6..ce185d2 100644 --- a/META.yml +++ b/META.yml @@ -1,7 +1,7 @@ # 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.22 +version: 0.23 version_from: lib/Excel/Template.pm installdirs: site requires: diff --git a/lib/Excel/Template.pm b/lib/Excel/Template.pm index 81602c5..cf484ef 100644 --- a/lib/Excel/Template.pm +++ b/lib/Excel/Template.pm @@ -6,7 +6,7 @@ BEGIN { use Excel::Template::Base; use vars qw ($VERSION @ISA); - $VERSION = '0.22'; + $VERSION = '0.23'; @ISA = qw( Excel::Template::Base ); } @@ -226,13 +226,12 @@ sub _prepare_output UNICODE => $self->{UNICODE}, ); -# print "@{$self->{WORKBOOKS}}\n"; $_->render($context) for @{$self->{WORKBOOKS}}; return ~~1; } -sub register { shift; Excel::Template::Factory::register(@_) } +sub register { shift; Excel::Template::Factory->register(@_) } 1; __END__ @@ -250,14 +249,17 @@ For example, test.xml: - - + + Now, create a small program to use it: #!/usr/bin/perl -w + + use strict; + use Excel::Template; # Create the Excel template @@ -273,8 +275,7 @@ Now, create a small program to use it: $template->write_file('test.xls'); -If everything worked, then you should have a spreadsheet in your work directory -that looks something like: +If everything worked, then you should have a spreadsheet called text.xls in your working directory that looks something like: A B C +----------------+----------------+---------------- @@ -286,19 +287,11 @@ that looks something like: =head1 DESCRIPTION -This is a module used for templating Excel files. Its genesis came from the -need to use the same datastructure as HTML::Template, but provide Excel files -instead. The existing modules don't do the trick, as they require replication -of logic that's already been done within HTML::Template. +This is a module used for templating Excel files. Its genesis came from the need to use the same datastructure as L, but provide Excel files instead. The existing modules don't do the trick, as they require replication of logic that's already been done within L. =head1 MOTIVATION -I do a lot of Perl/CGI for reporting purposes. In nearly every place I've been, -I've been asked for HTML, PDF, and Excel. HTML::Template provides the first, and -PDF::Template does the second pretty well. But, generating Excel was the -sticking point. I already had the data structure for the other templating -modules, but I just didn't have an easy mechanism to get that data structure -into an XLS file. +I do a lot of Perl/CGI for reporting purposes. In nearly every place I've been, I've been asked for HTML, PDF, and Excel. L provides the first, and L does the second pretty well. But, generating Excel was the sticking point. I already had the data structure for the other templating modules, but I just didn't have an easy mechanism to get that data structure into an XLS file. =head1 USAGE @@ -320,21 +313,21 @@ If you want to use the __DATA__ section, you can do so by passing =item * RENDERER -The default rendering engine is Spreadsheet::WriteExcel. You may, if you choose, change that to another choice. The legal values are: +The default rendering engine is L. You may, if you choose, change that to another choice. The legal values are: =over 4 =item * Excel::Template->RENDER_NML -This is the default of Spreadsheet::WriteExcel. +This is the default of L. =item * Excel::Template->RENDER_BIG -This attempts to load Spreadsheet::WriteExcel::Big. +This attempts to load L. =item * Excel::Template->RENDER_XML -This attempts to load Spreadsheet::WriteExcelXML. +This attempts to load L. =back @@ -342,12 +335,9 @@ This attempts to load Spreadsheet::WriteExcelXML. This will use L to represent strings instead of Perl's internal string handling. You must already have L installed on your system. -The USE_UNICODE parameter will be ignored if you are using Perl 5.8 or higher as -Perl's internal string handling is unicode-aware. +The USE_UNICODE parameter will be ignored if you are using Perl 5.8 or higher as Perl's internal string handling is unicode-aware. -NOTE: Certain older versions of L and mod_perl clash for some -reason. Upgrading to the latest version of L should fix the -problem. +NOTE: Certain older versions of L and mod_perl clash for some reason. Upgrading to the latest version of L should fix the problem. =back @@ -369,18 +359,15 @@ This method is exactly like L's param() method. This method actually parses the template file. It can either be called separately or through the new() call. It will die() if it runs into a situation it cannot handle. -If a filename is passed in (vs. a filehandle), the directory name will be passed in to XML::Parser as the I parameter. This will allow for XML directives to work as expected. +If a filename is passed in (vs. a filehandle), the directory name will be passed in to L as the I parameter. This will allow for XML directives to work as expected. =head2 write_file() -Create the Excel file and write it to the specified filename, if possible. (This -is when the actual merging of the template and the parameters occurs.) +Create the Excel file and write it to the specified filename, if possible. (This is when the actual merging of the template and the parameters occurs.) =head2 output() -It will act just like HTML::Template's output() method, returning the resultant -file as a stream, usually for output to the web. (This is when the actual -merging of the template and the parameters occurs.) +It will act just like L's output() method, returning the resultant file as a stream, usually for output to the web. (This is when the actual merging of the template and the parameters occurs.) =head2 register() @@ -388,18 +375,15 @@ This allows you to register a class as handling a node. q.v. L -This is the node representing the workbook. It is the parent for all other -nodes. +This is the node representing the workbook. It is the parent for all other nodes. =item * L @@ -407,8 +391,7 @@ This is the node representing a given worksheet. =item * L -This node represents a conditional expression. Its children may or may not be -rendered. It behaves just like L's TMPL_IF. +This node represents a conditional expression. Its children may or may not be rendered. It behaves just like L's TMPL_IF. =item * L @@ -420,10 +403,7 @@ This node represents a row of data. This is the A in A1. =item * L -This node varies the format for its children. All formatting options supported -in L are supported here. There are also a number of -formatting shortcuts, such as L and -L. +This node varies the format for its children. All formatting options supported in L are supported here. There are also a number of formatting shortcuts, such as L and L. =item * L @@ -454,8 +434,7 @@ None, that I know of. =head1 SUPPORT -This is production quality software, used in several production web -applications. +This is production quality software, used in several production web applications. =head1 AUTHOR @@ -477,54 +456,52 @@ There is a mailing list at http://groups.google.com/group/ExcelTemplate or excel =head1 TEST COVERAGE -I used Devel::Cover to test the coverage of my tests. Every release, I intend to improve these numbers. +I used L to test the coverage of my tests. Every release, I intend to improve these numbers. 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 branch cond sub pod time total ----------------------------- ------ ------ ------ ------ ------ ------ ------ -blib/lib/Excel/Template.pm 90.4 62.5 58.8 90.5 100.0 30.2 82.0 -...ib/Excel/Template/Base.pm 83.3 50.0 66.7 75.0 88.9 8.2 80.0 -...cel/Template/Container.pm 46.3 20.0 33.3 58.3 85.7 4.6 47.7 -...emplate/Container/Bold.pm 100.0 n/a n/a 100.0 0.0 0.5 95.0 -.../Container/Conditional.pm 58.5 52.3 66.7 75.0 66.7 0.8 58.4 -...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.2 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 55.6 40.0 50.0 77.8 75.0 0.5 56.6 -...late/Container/Outline.pm 71.4 n/a n/a 80.0 0.0 0.0 70.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.1 50.0 n/a 100.0 0.0 0.9 88.0 -...Excel/Template/Context.pm 83.1 53.4 54.2 95.0 92.9 19.1 75.2 -...Excel/Template/Element.pm 100.0 n/a n/a 100.0 n/a 0.4 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.6 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 57.1 34.6 n/a 88.9 100.0 14.3 55.2 -.../Excel/Template/Format.pm 98.3 81.2 33.3 100.0 100.0 8.9 93.2 -...xcel/Template/Iterator.pm 85.2 70.6 70.6 84.6 87.5 1.9 80.4 -...el/Template/TextObject.pm 92.9 62.5 33.3 100.0 50.0 2.7 83.0 -Total 83.1 56.6 58.3 91.1 98.7 100.0 78.8 ----------------------------- ------ ------ ------ ------ ------ ------ ------ + ----------------------------------------------------------------------- + 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 + ----------------------------------------------------------------------- =head1 COPYRIGHT -This program is free software; you can redistribute -it and/or modify it under the same terms as Perl itself. +This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. -The full text of the license can be found in the -LICENSE file included with this module. +The full text of the license can be found in the LICENSE file included with this module. =head1 SEE ALSO -perl(1), HTML::Template, Spreadsheet::WriteExcel. +perl(1), L, L =cut diff --git a/lib/Excel/Template/Base.pm b/lib/Excel/Template/Base.pm index 9b93fb9..fe76002 100644 --- a/lib/Excel/Template/Base.pm +++ b/lib/Excel/Template/Base.pm @@ -27,7 +27,7 @@ sub new sub isa { Excel::Template::Factory::isa(@_) } sub is_embedded { Excel::Template::Factory::is_embedded(@_) } -sub calculate { ($_[1])->get(@_[0,2]) } +#sub calculate { ($_[1])->get(@_[0,2]) } #{ # my $self = shift; # my ($context, $attr) = @_; diff --git a/lib/Excel/Template/Container.pm b/lib/Excel/Template/Container.pm index df966d9..2b65d71 100644 --- a/lib/Excel/Template/Container.pm +++ b/lib/Excel/Template/Container.pm @@ -71,51 +71,51 @@ sub render { $_[0]->iterate_over_children($_[1]) } # return $self->iterate_over_children($context); #} -sub max_of -{ - my $self = shift; - my ($context, $attr) = @_; - - my $max = $context->get($self, $attr); - - ELEMENT: - foreach my $e (@{$self->{ELEMENTS}}) - { - $e->enter_scope($context); - - my $v = $e->isa('CONTAINER') - ? $e->max_of($context, $attr) - : $e->calculate($context, $attr); - - $max = $v if $max < $v; - - $e->exit_scope($context, 1); - } - - return $max; -} - -sub total_of -{ - my $self = shift; - my ($context, $attr) = @_; - - my $total = 0; - - ELEMENT: - foreach my $e (@{$self->{ELEMENTS}}) - { - $e->enter_scope($context); - - $total += $e->isa('CONTAINER') - ? $e->total_of($context, $attr) - : $e->calculate($context, $attr); - - $e->exit_scope($context, 1); - } - - return $total; -} +#sub max_of +#{ +# my $self = shift; +# my ($context, $attr) = @_; +# +# my $max = $context->get($self, $attr); +# +# ELEMENT: +# foreach my $e (@{$self->{ELEMENTS}}) +# { +# $e->enter_scope($context); +# +# my $v = $e->isa('CONTAINER') +# ? $e->max_of($context, $attr) +# : $e->calculate($context, $attr); +# +# $max = $v if $max < $v; +# +# $e->exit_scope($context, 1); +# } +# +# return $max; +#} +# +#sub total_of +#{ +# my $self = shift; +# my ($context, $attr) = @_; +# +# my $total = 0; +# +# ELEMENT: +# foreach my $e (@{$self->{ELEMENTS}}) +# { +# $e->enter_scope($context); +# +# $total += $e->isa('CONTAINER') +# ? $e->total_of($context, $attr) +# : $e->calculate($context, $attr); +# +# $e->exit_scope($context, 1); +# } +# +# return $total; +#} 1; __END__ diff --git a/lib/Excel/Template/Container/Conditional.pm b/lib/Excel/Template/Container/Conditional.pm index 45f9fb7..17a4da3 100644 --- a/lib/Excel/Template/Container/Conditional.pm +++ b/lib/Excel/Template/Container/Conditional.pm @@ -87,25 +87,25 @@ sub render return $self->iterate_over_children($context); } -sub max_of -{ - my $self = shift; - my ($context, $attr) = @_; - - return 0 unless $self->_conditional_passes($context); - - return $self->SUPER::max_of($context, $attr); -} - -sub total_of -{ - my $self = shift; - my ($context, $attr) = @_; - - return 0 unless $self->_conditional_passes($context); - - return $self->SUPER::total_of($context, $attr); -} +#sub max_of +#{ +# my $self = shift; +# my ($context, $attr) = @_; +# +# return 0 unless $self->_conditional_passes($context); +# +# return $self->SUPER::max_of($context, $attr); +#} +# +#sub total_of +#{ +# my $self = shift; +# my ($context, $attr) = @_; +# +# return 0 unless $self->_conditional_passes($context); +# +# return $self->SUPER::total_of($context, $attr); +#} 1; __END__ diff --git a/lib/Excel/Template/Container/Loop.pm b/lib/Excel/Template/Container/Loop.pm index 31cd63c..ad22f67 100644 --- a/lib/Excel/Template/Container/Loop.pm +++ b/lib/Excel/Template/Container/Loop.pm @@ -69,47 +69,47 @@ sub render return 1; } -sub total_of -{ - my $self = shift; - my ($context, $attr) = @_; - - my $iterator = $self->_make_iterator($context); - - my $total = 0; - - $iterator->enter_scope; - while ($iterator->can_continue) - { - $iterator->next; - $total += $self->SUPER::total_of($context, $attr); - } - $iterator->exit_scope; - - return $total; -} - -sub max_of -{ - my $self = shift; - my ($context, $attr) = @_; - - my $iterator = $self->_make_iterator($context); - - my $max = $context->get($self, $attr); - - $iterator->enter_scope; - while ($iterator->can_continue) - { - $iterator->next; - my $v = $self->SUPER::max_of($context, $attr); - - $max = $v if $max < $v; - } - $iterator->exit_scope; - - return $max; -} +#sub total_of +#{ +# my $self = shift; +# my ($context, $attr) = @_; +# +# my $iterator = $self->_make_iterator($context); +# +# my $total = 0; +# +# $iterator->enter_scope; +# while ($iterator->can_continue) +# { +# $iterator->next; +# $total += $self->SUPER::total_of($context, $attr); +# } +# $iterator->exit_scope; +# +# return $total; +#} +# +#sub max_of +#{ +# my $self = shift; +# my ($context, $attr) = @_; +# +# my $iterator = $self->_make_iterator($context); +# +# my $max = $context->get($self, $attr); +# +# $iterator->enter_scope; +# while ($iterator->can_continue) +# { +# $iterator->next; +# my $v = $self->SUPER::max_of($context, $attr); +# +# $max = $v if $max < $v; +# } +# $iterator->exit_scope; +# +# return $max; +#} 1; __END__ diff --git a/lib/Excel/Template/Context.pm b/lib/Excel/Template/Context.pm index d7218af..1f3fcf9 100644 --- a/lib/Excel/Template/Context.pm +++ b/lib/Excel/Template/Context.pm @@ -29,7 +29,8 @@ sub new $self->{ACTIVE_FORMAT} = Excel::Template::Format->blank_format($self); $self->{WORKSHEET_NAMES} = undef; - for (qw( STACK PARAM_MAP NAME_MAP )) + # Removed NAME_MAP until I figure out what the heck it's for + for (qw( STACK PARAM_MAP )) { next if defined $self->{$_} && UNIVERSAL::isa($self->{$_}, 'ARRAY'); $self->{$_} = []; @@ -75,14 +76,14 @@ sub param ); } -sub named_param -{ - my $self = shift; - $self->_find_param_in_map( - 'NAME_MAP', - @_, - ); -} +#sub named_param +#{ +# my $self = shift; +# $self->_find_param_in_map( +# 'NAME_MAP', +# @_, +# ); +#} sub resolve { diff --git a/lib/Excel/Template/Factory.pm b/lib/Excel/Template/Factory.pm index cdb465a..c2321f9 100644 --- a/lib/Excel/Template/Factory.pm +++ b/lib/Excel/Template/Factory.pm @@ -46,7 +46,7 @@ BEGIN { 'BASE' => 'Excel::Template::Base', ); -%isBuildable = map { $_ => 1 } qw( +%isBuildable = map { $_ => ~~1 } qw( BOLD CELL FORMAT @@ -68,71 +68,86 @@ BEGIN { WORKSHEET ); -sub register +sub _load_class { - my %params = @_; + my $self = shift; + my ($class) = @_; + (my $filename = $class) =~ s!::!/!g; + eval { + require "$filename.pm"; + }; if ($@) { + die "Cannot find or compile PM file for '$class' ($filename)\n"; + } + + return ~~1; +} + +{ my @param_names = qw(name class isa); - for (@param_names) + sub register { - unless ($params{$_}) + my $self = shift; + my %params = @_; + + for (@param_names) { - warn "$_ was not supplied to register()\n" if $^W; - return 0; + unless ($params{$_}) + { + warn "$_ was not supplied to register()\n" if $^W; + return; + } } - } - my $name = uc $params{name}; - if (exists $Manifest{$name}) - { - warn "$params{name} already exists in the manifest.\n" if $^W; - return 0; - } + my $name = uc $params{name}; + if (exists $Manifest{$name}) + { + warn "$params{name} already exists in the manifest.\n" if $^W; + return; + } - my $isa = uc $params{isa}; - unless (exists $Manifest{$isa}) - { - warn "$params{isa} does not exist in the manifest.\n" if $^W; - return 0; - } + my $isa = uc $params{isa}; + unless (exists $Manifest{$isa}) + { + warn "$params{isa} does not exist in the manifest.\n" if $^W; + return; + } - $Manifest{$name} = $params{class}; - $isBuildable{$name} = 1; + { + no strict 'refs'; + unshift @{"$params{class}::ISA"}, $Manifest{$isa}; + } - { - no strict 'refs'; - unshift @{"$params{class}::ISA"}, $Manifest{$isa}; - } + $self->_load_class( $Manifest{$isa} ); + $self->_load_class( $params{class} ); - return 1; + $Manifest{$name} = $params{class}; + $isBuildable{$name} = ~~1; + + return ~~1; + } } 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 { - 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 diff --git a/lib/Excel/Template/Iterator.pm b/lib/Excel/Template/Iterator.pm index 593bf59..c251b81 100644 --- a/lib/Excel/Template/Iterator.pm +++ b/lib/Excel/Template/Iterator.pm @@ -151,33 +151,45 @@ sub next return 1; } -sub back_up -{ - my $self = shift; - - return 0 if $self->{NO_PARAMS}; - - $self->exit_scope; - - $self->{INDEX}--; - - $self->_do_globals; - - $self->enter_scope; - - return 1; -} - -sub reset -{ - my $self = shift; - - return 0 if $self->{NO_PARAMS}; - - $self->{INDEX} = -1; - - return 1; -} +# This method doesn't seem to be used ... +# If it is reinstated, here's the POD for it +#=head2 back_up +# +#Go to the previous iteration of the loop +# +#sub back_up +#{ +# my $self = shift; +# +# return 0 if $self->{NO_PARAMS}; +# +# $self->exit_scope; +# +# $self->{INDEX}--; +# +# $self->_do_globals; +# +# $self->enter_scope; +# +# return 1; +#} + +# This method doesn't seem to be used ... +# If it is reinstated, here's the POD for it +#=head2 reset +# +#Resets the iterator +# +#sub reset +#{ +# my $self = shift; +# +# return 0 if $self->{NO_PARAMS}; +# +# $self->{INDEX} = -1; +# +# return 1; +#} 1; __END__ @@ -216,10 +228,6 @@ None =head1 METHODS -=head2 back_up - -Go to the previous iteration of the loop - =head2 can_continue Determines if the iterator can continue. @@ -234,10 +242,6 @@ Determines if the iterator for the loop has more parameters that it can consume Go to the next iteration of the loop -=head2 reset - -Resets the iterator - =head1 AUTHOR Rob Kinyon (rob.kinyon@gmail.com) diff --git a/t/005.xml b/t/005.xml index c8111da..f3be8f8 100644 --- a/t/005.xml +++ b/t/005.xml @@ -3,6 +3,7 @@ + diff --git a/t/005_formats.t b/t/005_formats.t index ae18d89..8e282f4 100644 --- a/t/005_formats.t +++ b/t/005_formats.t @@ -24,9 +24,9 @@ Spreadsheet::WriteExcel::add_format( 'bold', '1' ) Spreadsheet::WriteExcel::add_format( 'hidden', '1' ) Spreadsheet::WriteExcel::add_format( 'italic', '1' ) Spreadsheet::WriteExcel::add_format( 'locked', '1' ) +Spreadsheet::WriteExcel::add_format( 'font_outline', '1' ) Spreadsheet::WriteExcel::add_format( 'font_shadow', '1' ) Spreadsheet::WriteExcel::add_format( 'font_strikeout', '1' ) -Spreadsheet::WriteExcel::add_format( 'font_outline', '1' ) Spreadsheet::WriteExcel::add_format( 'shrink', '1' ) Spreadsheet::WriteExcel::add_format( 'text_wrap', '1' ) Spreadsheet::WriteExcel::add_format( 'text_justlast', '1' ) diff --git a/t/018_register.t b/t/018_register.t new file mode 100644 index 0000000..97f50b4 --- /dev/null +++ b/t/018_register.t @@ -0,0 +1,79 @@ +use strict; + +use Test::More tests => 15; + +use lib 't'; +use mock; +mock::reset; + +my $CLASS = 'Excel::Template'; +use_ok( $CLASS ); + +{ + local $^W=0; + ok( !$CLASS->register(), "Must pass in class, name, and isa" ); + ok( !$CLASS->register( class => 'Register_018' ), "Must pass in class, name, and isa" ); + ok( !$CLASS->register( name => 'header' ), "Must pass in class, name, and isa" ); + ok( !$CLASS->register( isa => 'cell' ), "Must pass in class, name, and isa" ); + ok( !$CLASS->register( class => 'Register_018', isa => 'cell' ), "Must pass in class, name, and isa" ); + ok( !$CLASS->register( class => 'Register_018', name => 'header' ), "Must pass in class, name, and isa" ); + ok( !$CLASS->register( name => 'header', isa => 'cell' ), "Must pass in class, name, and isa" ); + + eval { + $CLASS->register( + class => 'NOT::A::CLASS', + name => 'not_a_node', + isa => 'cell', + ); + }; + like( $@, qr/Cannot find or compile/, "Verify registering a non-existent class fails" ); + + ok( + !$CLASS->register( + class => 'NOT::A::CLASS', + name => 'cell', + isa => 'row', + ), "Cannot add a nodename we already have", + ); + + ok( + !$CLASS->register( + class => 'NOT::A::CLASS', + name => 'new_node', + isa => 'not_a_node', + ), "Cannot inherit from a nodename we don't have", + ); +} + +ok( + $CLASS->register( + class => 'Register_018', + name => 'header', + isa => 'cell', + ), "Register Register_018 class", +); + +my $object = $CLASS->new( + file => \*DATA, +); +isa_ok( $object, $CLASS ); + +ok( $object->write_file( 'filename' ), 'Something returned' ); + +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::add_format( 'align', 'center', 'bold', '1' ) +Spreadsheet::WriteExcel::Worksheet::write( '0', '0', 'test', '2' ) +Spreadsheet::WriteExcel::close( '' ) +__END_EXPECTED__ + +__DATA__ + + +
+ + diff --git a/t/019_output.t b/t/019_output.t new file mode 100644 index 0000000..6964daa --- /dev/null +++ b/t/019_output.t @@ -0,0 +1,28 @@ +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( + filename => \*DATA, +); +isa_ok( $object, $CLASS ); + +ok( my $output = $object->output( 'filename' ), "Something returned" ); + +my $val = <<__END_EXPECTED__; +Spreadsheet::WriteExcel::new\\( 'GLOB\\([^)]+\\)' \\) +Spreadsheet::WriteExcel::add_format\\( '' \\) +Spreadsheet::WriteExcel::close\\( '' \\) +__END_EXPECTED__ + +like( $output, qr/$val/, 'Calls match up' ); + +__DATA__ + diff --git a/t/Register_018.pm b/t/Register_018.pm new file mode 100644 index 0000000..241b95b --- /dev/null +++ b/t/Register_018.pm @@ -0,0 +1,27 @@ +package Register_018; + +use strict; + +sub render +{ + my ($self, $context) = @_; + + my $old_format = $context->active_format; + my $format = Excel::Template::Format->copy( + $context, $old_format, + + align => 'center', bold => 1, + ); + + $context->active_format($format); + + my $child_success = $self->SUPER::render($context); + + $context->active_format($old_format); + + return $child_success; + +} + +1; +__END__ diff --git a/t/Spreadsheet/WriteExcel.pm b/t/Spreadsheet/WriteExcel.pm index 31d8448..cab958d 100644 --- a/t/Spreadsheet/WriteExcel.pm +++ b/t/Spreadsheet/WriteExcel.pm @@ -14,6 +14,8 @@ sub new { push @mock::calls, ref($self) . "::new( '@_' )"; } + $self->{file} = shift; + return $self; } @@ -23,6 +25,11 @@ sub close { local $" = "', '"; push @mock::calls, ref($self) . "::close( '@_' )"; } + + if ( ref $self->{file} ) { + my $fh = $self->{file}; + print $fh join "\n", @mock::calls, ''; + } } sub add_worksheet { diff --git a/t/pod_coverage.t b/t/pod_coverage.t index 8352506..304cc64 100644 --- a/t/pod_coverage.t +++ b/t/pod_coverage.t @@ -10,10 +10,13 @@ plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage" if # These are methods that need naming work my @private_methods = qw( render new min max resolve deltas - begin_page end_page max_of total_of + begin_page end_page enter_scope exit_scope iterate_over_children ); +# These are method names that have been commented out, for now +# max_of total_of + my $private_regex = do { local $"='|'; qr/^(?:@private_methods)$/