From: Rob Kinyon Date: Sat, 6 Nov 2004 04:39:25 +0000 (+0000) Subject: 0.17 Sat Nov 05 23:30:00 2004 X-Git-Tag: v0.19~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=dba6a68e5b49439f6b649f3b2dd3baa888de09cb;p=p5sagit%2FExcel-Template.git 0.17 Sat Nov 05 23:30:00 2004 - Added worksheet protection - Fixed several bugs found by adding more tests - SCOPE node actually works - CONDITIONAL / IF now handles string values correctly --- diff --git a/Changes b/Changes index 72be728..19ad758 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,12 @@ Revision history for Perl distribution Excel::Template -0.16 Fri Nov 05 16:15:00 2004 +0.17 Sat Nov 05 23:30:00 2004 + - Added worksheet protection + - Fixed several bugs found by adding more tests + - SCOPE node actually works + - CONDITIONAL / IF now handles string values correctly + +0.16 Fri Nov 05 13:30:00 2004 - Fixed Makefile.PL so that it uses PM_FILTER instead of rolling its own - This means that the Unicode handling is cleaner from a source perspective diff --git a/MANIFEST b/MANIFEST index 00d7112..aa2dcad 100644 --- a/MANIFEST +++ b/MANIFEST @@ -47,6 +47,16 @@ t/007_cell_formats.t t/007.xml t/008_formula.t t/008.xml +t/009_loop.t +t/009.xml +t/010_scope.t +t/010.xml +t/011_conditional.t +t/011.xml +t/012_backref.t +t/012.xml +t/013_range.t +t/013.xml t/mock.pm t/Spreadsheet/WriteExcel.pm t/Spreadsheet/WriteExcel/Worksheet.pm diff --git a/META.yml b/META.yml index 2c6a804..171bb03 100644 --- a/META.yml +++ b/META.yml @@ -1,12 +1,11 @@ # 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.15 +version: 0.17 version_from: lib/Excel/Template.pm installdirs: site requires: File::Basename: 0.01 - IO::File: 0.01 IO::Scalar: 0.01 Spreadsheet::WriteExcel: 0.42 Test::Simple: 0.44 diff --git a/Todo b/Todo index fcdd1a4..f6b0f26 100644 --- a/Todo +++ b/Todo @@ -1,6 +1,6 @@ TODO list for Perl distribution Excel::Template - Figure out if and how to add support for charts -- Add tests for LOOP, SCOPE, CONDITIONAL, BACKREF, and RANGE -- Add more stringent tests for what we already have +- Add more stringent tests +- Add colspan (COL), rowspan (ROW), width (CELL), and height (ROW) - Anything else people suggest diff --git a/lib/Excel/Template.pm b/lib/Excel/Template.pm index e741d7d..ec6d764 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.16'; + $VERSION = '0.17'; @ISA = qw( Excel::Template::Base ); } diff --git a/lib/Excel/Template/Container/Conditional.pm b/lib/Excel/Template/Container/Conditional.pm index 89cf668..cf4fcb2 100644 --- a/lib/Excel/Template/Container/Conditional.pm +++ b/lib/Excel/Template/Container/Conditional.pm @@ -37,10 +37,6 @@ sub conditional_passes ? $isOp{$op} : '=='; - # Force numerical context on both values; - $value *= 1; - $val *= 1; - my $res; for ($op) { @@ -60,22 +56,22 @@ sub conditional_passes die "Unknown operator in conditional resolve", $/; } - return 0 unless $res; + return $res && 1; } - elsif (my $is = uc $context->get($self, 'IS')) + + my $istrue = $val && 1; + + my $is = uc $context->get($self, 'IS') || 'TRUE'; + if ($is eq 'TRUE') { - my $istrue = $val && 1; - if ($is eq 'TRUE') - { - return 0 unless $istrue; - } - else - { - warn "Conditional 'is' value was [$is], defaulting to 'FALSE'" . $/ - if $is ne 'FALSE'; + return 0 unless $istrue; + } + else + { + warn "Conditional 'is' value was [$is], defaulting to 'FALSE'" . $/ + if $is ne 'FALSE'; - return 0 if $istrue; - } + return 0 if $istrue; } return 1; diff --git a/lib/Excel/Template/Container/Hidden.pm b/lib/Excel/Template/Container/Hidden.pm index 9b18489..351548c 100644 --- a/lib/Excel/Template/Container/Hidden.pm +++ b/lib/Excel/Template/Container/Hidden.pm @@ -52,7 +52,8 @@ None =head1 DEPENDENCIES -None +You must have protected the worksheet containing any cells that are affected by +this format. Otherwise, this node will have no effect. =head1 USAGE @@ -70,6 +71,6 @@ Rob Kinyon (rob.kinyon@gmail.com) =head1 SEE ALSO -FORMAT +WORKSHEET, FORMAT =cut diff --git a/lib/Excel/Template/Container/Locked.pm b/lib/Excel/Template/Container/Locked.pm index 4ad52d9..c7e1aad 100644 --- a/lib/Excel/Template/Container/Locked.pm +++ b/lib/Excel/Template/Container/Locked.pm @@ -52,7 +52,8 @@ None =head1 DEPENDENCIES -None +You must have protected the worksheet containing any cells that are affected by +this format. Otherwise, this node will have no effect. =head1 USAGE @@ -70,6 +71,6 @@ Rob Kinyon (rob.kinyon@gmail.com) =head1 SEE ALSO -FORMAT +WORKSHEET, FORMAT =cut diff --git a/lib/Excel/Template/Container/Worksheet.pm b/lib/Excel/Template/Container/Worksheet.pm index 6a1edaf..b91dc15 100644 --- a/lib/Excel/Template/Container/Worksheet.pm +++ b/lib/Excel/Template/Container/Worksheet.pm @@ -16,6 +16,12 @@ sub render $context->new_worksheet( $self ); + my $password = $context->get( $self, 'PROTECT' ); + if (defined $password) + { + $context->active_worksheet->protect( $password ); + } + return $self->SUPER::render($context); } @@ -46,6 +52,13 @@ Excel::Template::Container This is the name of the worksheet to be added. +=item * PROTECT + +If the attribute exists, it will mark the worksheet as being protected. Whatever +value is set will be used as the password. + +This activates the HIDDEN and LOCKED nodes. + =back 4 =head1 CHILDREN diff --git a/lib/Excel/Template/Factory.pm b/lib/Excel/Template/Factory.pm index 280b213..c532b67 100644 --- a/lib/Excel/Template/Factory.pm +++ b/lib/Excel/Template/Factory.pm @@ -60,6 +60,7 @@ BEGIN { BACKREF RANGE ROW + SCOPE SHADOW STRIKEOUT VAR diff --git a/t/009.xml b/t/009.xml new file mode 100644 index 0000000..e36b384 --- /dev/null +++ b/t/009.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/t/009_loop.t b/t/009_loop.t new file mode 100644 index 0000000..2f8f6dd --- /dev/null +++ b/t/009_loop.t @@ -0,0 +1,66 @@ +use strict; +use warnings; +$|++; + +use Test::More tests => 5; + +use lib 't'; +use mock; +mock->reset; + +my $CLASS = 'Excel::Template'; +use_ok( $CLASS ); + +my $object = $CLASS->new( + filename => 't/009.xml', +); +isa_ok( $object, $CLASS ); + +ok( + $object->param( + loopy => [ + { value => 1 }, + { value => 2 }, + { value => 3 }, + ], + outer => [ + { iter => 'a', inner => [ { value => 1 }, { value => 2 } ] }, + { iter => 'b', inner => [ { value => 3 }, { value => 4 } ] }, + ], + worksheets => [ + { value => 1 }, + { value => 2 }, + { value => 3 }, + ], + ), + 'Parameters set', +); + +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( 'loops' ) +Spreadsheet::WriteExcel::Worksheet::new( '' ) +Spreadsheet::WriteExcel::Worksheet::write( '0', '0', '1', '1' ) +Spreadsheet::WriteExcel::Worksheet::write( '0', '1', 'text', '1' ) +Spreadsheet::WriteExcel::Worksheet::write( '1', '0', '2', '1' ) +Spreadsheet::WriteExcel::Worksheet::write( '1', '1', 'text', '1' ) +Spreadsheet::WriteExcel::Worksheet::write( '2', '0', '3', '1' ) +Spreadsheet::WriteExcel::Worksheet::write( '2', '1', 'text', '1' ) +Spreadsheet::WriteExcel::Worksheet::write( '3', '0', 'a', '1' ) +Spreadsheet::WriteExcel::Worksheet::write( '3', '1', '1', '1' ) +Spreadsheet::WriteExcel::Worksheet::write( '3', '2', '2', '1' ) +Spreadsheet::WriteExcel::Worksheet::write( '4', '0', 'b', '1' ) +Spreadsheet::WriteExcel::Worksheet::write( '4', '1', '3', '1' ) +Spreadsheet::WriteExcel::Worksheet::write( '4', '2', '4', '1' ) +Spreadsheet::WriteExcel::add_worksheet( '1' ) +Spreadsheet::WriteExcel::Worksheet::new( '' ) +Spreadsheet::WriteExcel::add_worksheet( '2' ) +Spreadsheet::WriteExcel::Worksheet::new( '' ) +Spreadsheet::WriteExcel::add_worksheet( '3' ) +Spreadsheet::WriteExcel::Worksheet::new( '' ) +Spreadsheet::WriteExcel::close( '' ) +__END_EXPECTED__ diff --git a/t/010.xml b/t/010.xml new file mode 100644 index 0000000..24a6f72 --- /dev/null +++ b/t/010.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/t/010_scope.t b/t/010_scope.t new file mode 100644 index 0000000..ac1aaea --- /dev/null +++ b/t/010_scope.t @@ -0,0 +1,30 @@ +use strict; +use warnings; +$|++; + +use Test::More tests => 4; + +use lib 't'; +use mock; +mock->reset; + +my $CLASS = 'Excel::Template'; +use_ok( $CLASS ); + +my $object = $CLASS->new( + filename => 't/010.xml', +); +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( 'scope' ) +Spreadsheet::WriteExcel::Worksheet::new( '' ) +Spreadsheet::WriteExcel::Worksheet::write( '0', '0', '1', '1' ) +Spreadsheet::WriteExcel::Worksheet::write( '0', '1', '1', '1' ) +Spreadsheet::WriteExcel::close( '' ) +__END_EXPECTED__ diff --git a/t/011.xml b/t/011.xml new file mode 100644 index 0000000..fea37f7 --- /dev/null +++ b/t/011.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/t/011_conditional.t b/t/011_conditional.t new file mode 100644 index 0000000..45bcb72 --- /dev/null +++ b/t/011_conditional.t @@ -0,0 +1,48 @@ +use strict; +use warnings; +$|++; + +use Test::More tests => 5; + +use lib 't'; +use mock; +mock->reset; + +my $CLASS = 'Excel::Template'; +use_ok( $CLASS ); + +my $object = $CLASS->new( + filename => 't/011.xml', +); +isa_ok( $object, $CLASS ); + +ok( + $object->param( + loopy => [ + { int => 0, char => 'n' }, + { int => 0, char => 'y' }, + { int => 1, char => 'n' }, + { int => 1, char => 'y' }, + ], + ), + 'Parameters set', +); + +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( 'conditional' ) +Spreadsheet::WriteExcel::Worksheet::new( '' ) +Spreadsheet::WriteExcel::Worksheet::write( '0', '0', 'not bool', '1' ) +Spreadsheet::WriteExcel::Worksheet::write( '0', '1', 'int', '1' ) +Spreadsheet::WriteExcel::Worksheet::write( '1', '0', 'not bool', '1' ) +Spreadsheet::WriteExcel::Worksheet::write( '1', '1', 'int', '1' ) +Spreadsheet::WriteExcel::Worksheet::write( '1', '2', 'char', '1' ) +Spreadsheet::WriteExcel::Worksheet::write( '2', '0', 'bool', '1' ) +Spreadsheet::WriteExcel::Worksheet::write( '3', '0', 'bool', '1' ) +Spreadsheet::WriteExcel::Worksheet::write( '3', '1', 'char', '1' ) +Spreadsheet::WriteExcel::close( '' ) +__END_EXPECTED__ diff --git a/t/012.xml b/t/012.xml new file mode 100644 index 0000000..8ed109c --- /dev/null +++ b/t/012.xml @@ -0,0 +1,7 @@ + + + + + = + + diff --git a/t/012_backref.t b/t/012_backref.t new file mode 100644 index 0000000..25301ec --- /dev/null +++ b/t/012_backref.t @@ -0,0 +1,31 @@ +use strict; +use warnings; +$|++; + +use Test::More tests => 4; + +use lib 't'; +use mock; +mock->reset; + +my $CLASS = 'Excel::Template'; +use_ok( $CLASS ); + +my $object = $CLASS->new( + filename => 't/012.xml', +); +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( 'backref' ) +Spreadsheet::WriteExcel::Worksheet::new( '' ) +Spreadsheet::WriteExcel::Worksheet::write( '0', '0', 'not me', '1' ) +Spreadsheet::WriteExcel::Worksheet::write( '0', '1', 'me', '1' ) +Spreadsheet::WriteExcel::Worksheet::write( '0', '2', '=B1', '1' ) +Spreadsheet::WriteExcel::close( '' ) +__END_EXPECTED__ diff --git a/t/013.xml b/t/013.xml new file mode 100644 index 0000000..4862743 --- /dev/null +++ b/t/013.xml @@ -0,0 +1,8 @@ + + + + + + =SUM() + + diff --git a/t/013_range.t b/t/013_range.t new file mode 100644 index 0000000..c865c63 --- /dev/null +++ b/t/013_range.t @@ -0,0 +1,32 @@ +use strict; +use warnings; +$|++; + +use Test::More tests => 4; + +use lib 't'; +use mock; +mock->reset; + +my $CLASS = 'Excel::Template'; +use_ok( $CLASS ); + +my $object = $CLASS->new( + filename => 't/013.xml', +); +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( 'backref' ) +Spreadsheet::WriteExcel::Worksheet::new( '' ) +Spreadsheet::WriteExcel::Worksheet::write( '0', '0', '1', '1' ) +Spreadsheet::WriteExcel::Worksheet::write( '0', '1', '2', '1' ) +Spreadsheet::WriteExcel::Worksheet::write( '0', '2', '3', '1' ) +Spreadsheet::WriteExcel::Worksheet::write( '0', '3', '=SUM(A1:C1)', '1' ) +Spreadsheet::WriteExcel::close( '' ) +__END_EXPECTED__