Tagged v0.17 v0.17
Rob Kinyon [Sat, 6 Nov 2004 04:40:46 +0000 (04:40 +0000)]
46 files changed:
Changes
MANIFEST
MANIFEST.SKIP [new file with mode: 0644]
META.yml [new file with mode: 0644]
Makefile.PL
Todo
lib/Excel/Template.pm
lib/Excel/Template/Container/Conditional.pm
lib/Excel/Template/Container/Hidden.pm
lib/Excel/Template/Container/Locked.pm
lib/Excel/Template/Container/Worksheet.pm
lib/Excel/Template/Element/Backref.pm
lib/Excel/Template/Element/Cell.pm [new file with mode: 0755]
lib/Excel/Template/Element/Formula.pm
lib/Excel/Template/Element/Range.pm
lib/Excel/Template/Factory.pm
lib/Excel/Template/Format.pm
lib/Excel/Template/TextObject.pm [new file with mode: 0755]
t/001_load.t
t/002.xml [new file with mode: 0644]
t/002_workbook.t [new file with mode: 0644]
t/003.xml [new file with mode: 0644]
t/003_worksheet.t [new file with mode: 0644]
t/004.xml [new file with mode: 0644]
t/004_cell.t [new file with mode: 0644]
t/005.xml [new file with mode: 0644]
t/005_formats.t [new file with mode: 0644]
t/006.xml [new file with mode: 0644]
t/006_variables.t [new file with mode: 0644]
t/007.xml [new file with mode: 0644]
t/007_cell_formats.t [new file with mode: 0644]
t/008.xml [new file with mode: 0644]
t/008_formula.t [new file with mode: 0644]
t/009.xml [new file with mode: 0644]
t/009_loop.t [new file with mode: 0644]
t/010.xml [new file with mode: 0644]
t/010_scope.t [new file with mode: 0644]
t/011.xml [new file with mode: 0644]
t/011_conditional.t [new file with mode: 0644]
t/012.xml [new file with mode: 0644]
t/012_backref.t [new file with mode: 0644]
t/013.xml [new file with mode: 0644]
t/013_range.t [new file with mode: 0644]
t/Spreadsheet/WriteExcel.pm [new file with mode: 0644]
t/Spreadsheet/WriteExcel/Worksheet.pm [new file with mode: 0644]
t/mock.pm [new file with mode: 0644]

diff --git a/Changes b/Changes
index 05e7456..19ad758 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,74 +1,89 @@
 Revision history for Perl distribution Excel::Template
 
+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
+    - Added MANIFEST.SKIP to skip /.svn/ and 'vi' .swp files during distcheck
+    - Finally have a semi-real testing suite!
+        - Added minimal Spreadsheet::WriteExcel mockobject
+    - Fixed several bugs in formats found by building tests
+      - HIDDEN node now actually works
+      - LOCKED node now actually works
+
 0.15 Thu Nov 04 16:15:00 2004
-        - Fixed bugs that were:
-          - preventing a worksheet from using a variable name in a loop
-          - allowing two worksheets to have the same name
-          - preventing a worksheet from being called '0' or '0.0'
-        - Added back-references. This allows for one cell to refer to another
-          cell in an Excel-aware way, especially in formulas.
-        - Added the following nodes:
-          - BACKREF
-          - RANGE
+    - Fixed bugs that were:
+        - preventing a worksheet from using a variable name in a loop
+        - allowing two worksheets to have the same name
+        - preventing a worksheet from being called '0' or '0.0'
+    - Added back-references. This allows for one cell to refer to another
+      cell in an Excel-aware way, especially in formulas.
+    - Added the following nodes:
+        - BACKREF
+        - RANGE
 
 0.14 Thu Nov 04 13:30:00 2004
-        - Added new format support for (nearly) all formats supported by
-          Spreadsheet::WriteExcel
-        - Fixed email address everywhere
+    - Added new format support for (nearly) all formats supported by
+      Spreadsheet::WriteExcel
+    - Fixed email address everywhere
 
 0.13 Thu Oct 29 07:30:00 2004
-        - Fixed email address and added GoogleGroup
+    - Fixed email address and added GoogleGroup
 
 0.12 Thu Apr 08 07:30:00 2004
-        - Fixed bug regarding empty arrays as loop variables
+    - Fixed bug regarding empty arrays as loop variables
 
 0.11 Wed Mar 17 16:00:00 2004
-        - Fixed bug introduced in 0.10 (Loops were not case-insensitive)
+    - Fixed bug introduced in 0.10 (Loops were not case-insensitive)
 
 0.10 Wed Mar 17 16:00:00 2004
-        - Parameters are now case-insensitive
+    - Parameters are now case-insensitive
 
 0.09 Mon Feb 02 16:00:00 2004
-        - Fixed bug with multiple worksheets
+    - Fixed bug with multiple worksheets
 
 0.08 Fri Jan 30 14:00:00 2004
-        - Added Base to the params for XML::Parser to allow for entity includes
+    - Added Base to the params for XML::Parser to allow for entity includes
 
 0.07 Fri Jan 23 08:30:00 2004
-        - Fixed the MANIFEST to account for missing files
+    - Fixed the MANIFEST to account for missing files
 
 0.06 Mon Jan 20 11:00:00 2004
-        - Added formulas (no back-references yet)
-        - Improved POD a little
+    - Added formulas (no back-references yet)
+    - Improved POD a little
 
 0.05 Wed Jan 16 12:30:00 2004
-        - Fixed a bug in formats
+    - Fixed a bug in formats
 
 0.04 Wed Jan 16 12:00:00 2004
-        - Added BIG_FILES as an option, which will use
-          Spreadsheet::WriteExcel::Big as the renderer (yet unimplemented)
-        - Changed the output() method to use a tied IO::Scalar (which is
-          now a requirement.
-        - Firmed up the infrastructure in Excel::Template::Format
-        - Added the following tags
-            - FORMAT
-            - HIDDEN
-            - LOCKED
-            - OUTLINE
-            - SHADOW
-            - STRIKEOUT
+    - Added BIG_FILES as an option, which will use
+      Spreadsheet::WriteExcel::Big as the renderer (yet unimplemented)
+    - Changed the output() method to use a tied IO::Scalar (which is
+      now a requirement.
+    - Firmed up the infrastructure in Excel::Template::Format
+    - Added the following tags
+          - FORMAT
+          - HIDDEN
+          - LOCKED
+          - OUTLINE
+          - SHADOW
+          - STRIKEOUT
 
 0.03 Wed Dec 03 20:30:00 2003
-        - Added XML::Parser as a required pre-requisite module
-        - Added Italic format
-        - Removed $VERSION from Excel::Template::Base (Unneeded)
-        - No documentation or testing changes
+    - Added XML::Parser as a required pre-requisite module
+    - Added Italic format
+    - Removed $VERSION from Excel::Template::Base (Unneeded)
+    - No documentation or testing changes
 
 0.02 Sun Nov 30 17:00:00 2003
-        - documentation improvements
-        - No actual functional changes
+    - documentation improvements
+    - No actual functional changes
 
 0.01 Tue Nov 18 14:23:42 2003
-        - original version; created by ExtUtils::ModuleMaker 0.32
-
-
+    - original version; created by ExtUtils::ModuleMaker 0.32
index 88d5c49..aa2dcad 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -1,4 +1,5 @@
 MANIFEST
+MANIFEST.SKIP
 LICENSE
 README
 Todo
@@ -11,7 +12,7 @@ lib/Excel/Template/Element.pm
 lib/Excel/Template/Factory.pm
 lib/Excel/Template/Format.pm
 lib/Excel/Template/Iterator.pm
-lib/Excel/Template/TextObject.pm_
+lib/Excel/Template/TextObject.pm
 lib/Excel/Template/Container/Bold.pm
 lib/Excel/Template/Container/Conditional.pm
 lib/Excel/Template/Container/Format.pm
@@ -27,10 +28,37 @@ lib/Excel/Template/Container/Shadow.pm
 lib/Excel/Template/Container/Workbook.pm
 lib/Excel/Template/Container/Worksheet.pm
 lib/Excel/Template/Element/Backref.pm
-lib/Excel/Template/Element/Cell.pm_
+lib/Excel/Template/Element/Cell.pm
 lib/Excel/Template/Element/Formula.pm
 lib/Excel/Template/Element/Range.pm
 lib/Excel/Template/Element/Var.pm
 t/001_load.t
+t/002_workbook.t
+t/002.xml
+t/003_worksheet.t
+t/003.xml
+t/004_cell.t
+t/004.xml
+t/005_formats.t
+t/005.xml
+t/006_variables.t
+t/006.xml
+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
 Makefile.PL
 META.yml                                 Module meta-data (added by MakeMaker)
diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP
new file mode 100644 (file)
index 0000000..6a5b467
--- /dev/null
@@ -0,0 +1,18 @@
+\bRCS\b
+\bCVS\b
+,v$
+\B\.svn\b
+
+# Makemaker generated files and dirs.
+^MANIFEST\.
+^Makefile$
+^pm_to_blib$
+^blib/
+^MakeMaker-\d
+
+# Temp, old and emacs backup files.
+~$
+\.old$
+^#.*#$
+^\.#
+.swp$
diff --git a/META.yml b/META.yml
new file mode 100644 (file)
index 0000000..171bb03
--- /dev/null
+++ b/META.yml
@@ -0,0 +1,15 @@
+# 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.17
+version_from: lib/Excel/Template.pm
+installdirs:  site
+requires:
+    File::Basename:                0.01
+    IO::Scalar:                    0.01
+    Spreadsheet::WriteExcel:       0.42
+    Test::Simple:                  0.44
+    XML::Parser:                   0.01
+
+distribution_type: module
+generated_by: ExtUtils::MakeMaker version 6.17
index a7aefc3..27fe9f8 100644 (file)
@@ -2,33 +2,35 @@ use ExtUtils::MakeMaker;
 # See lib/ExtUtils/MakeMaker.pm for details of how to influence
 # the contents of the Makefile that is written.
 
-use File::Spec;
+use strict;
 
 my $prereqs = {
     'Test::Simple'            => 0.44,
+    'Spreadsheet::WriteExcel' => 0.42,
     'XML::Parser'             => 0.01,
-    'IO::File'                => 0.01,
     'IO::Scalar'              => 0.01,
     'File::Basename'          => 0.01,
-    'Spreadsheet::WriteExcel' => 0.42,
 };
 
-# The assumption is the 5.8.0 and greater doesn't need Unicode::String.
+# The assumption is Perl 5.8.0 and greater doesn't need Unicode::String.
+
+my $use_unicode = 0;
 if ($] < 5.008)
 {
     print "Do you want Unicode support? ";
     my $answer = <STDIN>;
     my $need_unicode = $answer =~ /^[Yy]/;
 
-    my $use_unicode = 0;
     if ($need_unicode)
     {
-            $prereqs{'Unicode::String'} = '0.01';
+            $prereqs->{'Unicode::String'} = '0.01';
             $use_unicode = 1;
     }
 }
 
-use_unicode($use_unicode);
+my $pm_filter = $use_unicode
+    ? 'perl -p -e "s!UNI_YES ! !g;s!UNI_NO  !\\#!g"'
+    : 'perl -p -e "s!UNI_NO  ! !g;s!UNI_YES !\\#!g"';
 
 WriteMakefile(
     NAME         => 'Excel::Template',
@@ -36,49 +38,5 @@ WriteMakefile(
     AUTHOR       => 'Rob Kinyon (rob.kinyon@gmail.com)',
     ABSTRACT     => 'Excel::Template',
     PREREQ_PM    => $prereqs,
+    PM_FILTER    => $pm_filter,
 );
-
-sub use_unicode
-{
-    my $using_unicode = shift;
-
-    my @filenames = map {
-        File::Spec->catfile(
-            qw( lib Excel Template ),
-            @{$_},
-        )
-    } ( [ qw( Element Cell.pm_ ) ], [ qw( TextObject.pm_ ) ] );
-
-    foreach my $filename (@filenames)
-    {
-        open(IN_FILE, $filename)
-            or die "Cannot open '$filename' for reading: $!\n";
-        my @lines = <IN_FILE>;
-        close(IN_FILE);
-
-        if ($using_unicode)
-        {
-            for (@lines)
-            {
-                s/^UNI_YES / /;
-                s/^UNI_NO  /#/;
-            }
-        }
-        else
-        {
-            for (@lines)
-            {
-                s/^UNI_YES /#/;
-                s/^UNI_NO  / /;
-            }
-        }
-
-        $filename =~ s/_$//;
-        open(OUT_FILE, ">$filename")
-            or die "Cannot open '$filename' for writing: $!\n";
-        print OUT_FILE @lines;
-        close(OUT_FILE);
-    }
-
-    return 1;
-}
diff --git a/Todo b/Todo
index 297e3fd..f6b0f26 100644 (file)
--- a/Todo
+++ b/Todo
@@ -1,9 +1,6 @@
-TODO list for Perl module Excel::Template
+TODO list for Perl distribution Excel::Template
 
-- Add more formatting options, such as italic
-- Add fonts
-- Add numeric/string formats
-- Figure out how to add support for formulas, especially in <LOOP>s
 - Figure out if and how to add support for charts
+- Add more stringent tests
+- Add colspan (COL), rowspan (ROW), width (CELL), and height (ROW)
 - Anything else people suggest
-
index 1d7626e..ec6d764 100644 (file)
@@ -6,13 +6,12 @@ BEGIN {
     use Excel::Template::Base;
     use vars qw ($VERSION @ISA);
 
-    $VERSION  = '0.15';
+    $VERSION  = '0.17';
     @ISA      = qw( Excel::Template::Base );
 }
 
 use File::Basename;
 use XML::Parser;
-use IO::File;
 use IO::Scalar;
 
 sub new
@@ -67,7 +66,7 @@ sub param
     $params{uc $_} = delete $params{$_} for keys %params;
     @{$self->{PARAM_MAP}}{keys %params} = @params{keys %params};
 
-    return 1;
+    return !!1;
 }
 
 sub write_file
@@ -82,7 +81,7 @@ sub write_file
 
     $xls->close;
 
-    return 1;
+    return !!1;
 }
 
 sub output
@@ -97,13 +96,6 @@ sub output
     return $output;
 }
 
-sub parse
-{
-    my $self = shift;
-
-    $self->parse_xml(@_);
-}
-
 sub parse_xml
 {
     my $self = shift;
@@ -169,16 +161,17 @@ sub parse_xml
     );
 
     {
-        my $fh = IO::File->new($fname)
+        open( INFILE, "<$fname" )
             || die "Cannot open '$fname' for reading: $!\n";
 
-        $parser->parse(do { local $/ = undef; <$fh> });
+        $parser->parse(do { local $/ = undef; <INFILE> });
 
-        $fh->close;
+        close INFILE;
     }
 
-    return 1;
+    return !!1;
 }
+*parse = \&parse_xml;
 
 sub _prepare_output
 {
@@ -194,7 +187,7 @@ sub _prepare_output
 
     $_->render($context) for @{$self->{WORKBOOKS}};
 
-    return 1;
+    return !!1;
 }
 
 sub register { shift; Excel::Template::Factory::register(@_) }
index 89cf668..cf4fcb2 100644 (file)
@@ -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;
index 9b18489..351548c 100644 (file)
@@ -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
index 4ad52d9..c7e1aad 100644 (file)
@@ -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
index 6a1edaf..b91dc15 100644 (file)
@@ -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
index fe82f1b..d622503 100755 (executable)
@@ -37,7 +37,7 @@ return the location of the entire range of cells to name this reference see RANG
 
 =head1 NODE NAME
 
-REF
+BACKREF
 
 =head1 INHERITANCE
 
diff --git a/lib/Excel/Template/Element/Cell.pm b/lib/Excel/Template/Element/Cell.pm
new file mode 100755 (executable)
index 0000000..9272e51
--- /dev/null
@@ -0,0 +1,158 @@
+package Excel::Template::Element::Cell;
+
+use strict;
+
+BEGIN {
+    use vars qw(@ISA);
+    @ISA = qw(Excel::Template::Element);
+
+    use Excel::Template::Element;
+}
+
+sub new
+{
+    my $class = shift;
+    my $self = $class->SUPER::new(@_);
+                                                                                
+    $self->{TXTOBJ} = Excel::Template::Factory->create('TEXTOBJECT');
+                                                                                
+    return $self;
+}
+
+sub get_text
+{
+    my $self = shift;
+    my ($context) = @_;
+                                                                                
+    my $txt = $context->get($self, 'TEXT');
+    if (defined $txt)
+    {
+        my $txt_obj = Excel::Template::Factory->create('TEXTOBJECT');
+        push @{$txt_obj->{STACK}}, $txt;
+        $txt = $txt_obj->resolve($context);
+    }
+    elsif ($self->{TXTOBJ})
+    {
+        $txt = $self->{TXTOBJ}->resolve($context)
+    }
+    else
+    {
+UNI_YES        $txt = Unicode::String::utf8('');
+UNI_NO         $txt = '';
+    }
+                                                                                
+    return $txt;
+}
+
+sub render
+{
+    my $self = shift;
+    my ($context, $method) = @_;
+
+    $method ||= 'write';
+
+    my ($row, $col) = map { $context->get($self, $_) } qw(ROW COL);
+
+    my $ref = uc $context->get( $self, 'REF' );
+    if (defined $ref && length $ref)
+    {
+        $context->add_reference( $ref, $row, $col );
+    }
+
+    $context->active_worksheet->$method(
+        $row, $col,
+        $self->get_text($context),
+        $context->active_format,
+    );
+
+    return 1;
+}
+
+sub deltas
+{
+    return {
+        COL => +1,
+    };
+}
+
+1;
+__END__
+
+=head1 NAME
+
+Excel::Template::Element::Cell - Excel::Template::Element::Cell
+
+=head1 PURPOSE
+
+To actually write stuff to the worksheet
+
+=head1 NODE NAME
+
+CELL
+
+=head1 INHERITANCE
+
+Excel::Template::Element
+
+=head1 ATTRIBUTES
+
+=over 4
+
+=item * TEXT
+
+This is the text to write to the cell. This can either be text or a parameter
+with a dollar-sign in front of the parameter name.
+
+=item * COL
+
+Optionally, you can specify which column you want this cell to be in. It can be
+either a number (zero-based) or an offset. See Excel::Template for more info on
+offset-based numbering.
+
+=item * REF
+
+Adds the current cell to the a list of cells that can be backreferenced.
+This is useful when the current cell needs to be referenced by a
+formula. See BACKREF and RANGE.
+
+=back 4
+
+There will be more parameters added, as features are added.
+
+=head1 CHILDREN
+
+Excel::Template::Element::Formula
+
+=head1 EFFECTS
+
+This will consume one column on the current row. 
+
+=head1 DEPENDENCIES
+
+None
+
+=head1 USAGE
+
+  <cell text="Some Text Here"/>
+  <cell>Some other text here</cell>
+
+  <cell text="$Param2"/>
+  <cell>Some <var name="Param"> text here</cell>
+
+In the above example, four cells are written out. The first two have text hard-
+coded. The second two have variables. The third and fourth items have another
+thing that should be noted. If you have text where you want a variable in the
+middle, you have to use the latter form. Variables within parameters are the
+entire parameter's value.
+
+Please see Spreadsheet::WriteExcel for what constitutes a legal formula.
+
+=head1 AUTHOR
+
+Rob Kinyon (rob.kinyon@gmail.com)
+
+=head1 SEE ALSO
+
+ROW, VAR, FORMULA
+
+=cut
index 3de93b0..0edb621 100644 (file)
@@ -9,30 +9,13 @@ BEGIN {
     use Excel::Template::Element::Cell;
 }
 
-sub get_text
-{
-    my $self = shift;
-    my ($context) = @_;
-
-    my $text = $self->SUPER::get_text($context);
-
-# At this point, we must do back-reference dereferencing
-
-    return $text;
-}
-
-sub render
-{
-    my $self = shift;
-    my ($context) = @_;
-
-    $context->active_worksheet->write_formula(
-        (map { $context->get($self, $_) } qw(ROW COL)),
-        $self->get_text($context),
-    );
-
-    return 1;
-}
+sub render { $_[0]->SUPER::render( $_[1], 'write_formula' ) }
+#{
+#    my $self = shift;
+#    my ($context) = @_;
+#
+#    return $self->SUPER::render( $context, 'write_formula' );
+#}
 
 1;
 __END__
@@ -55,22 +38,8 @@ Excel::Template::Element::Cell
 
 =head1 ATTRIBUTES
 
-=over 4
-
-=item * TEXT
-
-This is the formula to write to the cell. This can either be text or a parameter
-with a dollar-sign in front of the parameter name.
-
-=item * COL
-
-Optionally, you can specify which column you want this cell to be in. It can be
-either a number (zero-based) or an offset. See Excel::Template for more info on
-offset-based numbering.
-
-=back 4
-
-There will be more parameters added, as features are added.
+All attributes a CELL can have, a FORMULA can have, including the ability to be
+referenced using the 'ref' attribute.
 
 =head1 CHILDREN
 
@@ -104,6 +73,6 @@ Rob Kinyon (rob.kinyon@gmail.com)
 
 =head1 SEE ALSO
 
-ROW, VAR, CELL
+CELL
 
 =cut
index c880654..7a9db99 100755 (executable)
@@ -50,12 +50,12 @@ Excel::Template::Element::Range
 
 =head1 PURPOSE
 
-Returns a range of cell locations (i.e. B2:C2) that contains all calls using this
-reference. To return the location of the last cell, use REF.
+Returns a range of cell locations (i.e. B2:C2) that contains all calls using
+this reference. To return the location of the last cell, use BACKREF.
 
 =head1 NODE NAME
 
-REF
+RANGE
 
 =head1 INHERITANCE
 
@@ -102,6 +102,6 @@ Rob Kinyon (rkinyon@columbus.rr.com)
 
 =head1 SEE ALSO
 
-CELL, REF
+CELL, BACKREF
 
 =cut
index 7a0a6a4..c532b67 100644 (file)
@@ -52,12 +52,15 @@ BEGIN {
     FORMAT
     FORMULA
     IF
+    HIDDEN
     ITALIC
+    LOCKED
     OUTLINE
     LOOP
     BACKREF
     RANGE
     ROW
+    SCOPE
     SHADOW
     STRIKEOUT
     VAR
index 77c0056..5beff92 100644 (file)
@@ -76,7 +76,7 @@ use strict;
             for grep { $boolean_parts[$_] } 0 .. $#_boolean_formats;
 
         $params{ $_integer_formats[$_] } = $integer_parts[$_]
-            for grep { length $integer_parts[$_] } 0 .. $#_integer_formats;
+            for grep { defined $integer_parts[$_] } 0 .. $#_integer_formats;
 
         $params{ $_string_formats[$_] } = $string_parts[$_]
             for grep { $string_parts[$_] } 0 .. $#_string_formats;
@@ -89,6 +89,9 @@ use strict;
         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))
             || die "Internal Error: Cannot find key for format '$old_fmt'!\n";
 
@@ -111,6 +114,8 @@ use strict;
                     next PROPERTY;
                 }
             }
+
+            warn "Property '$prop' is unrecognized\n";
         }
 
         my $new_key = _params_to_key(%params);
diff --git a/lib/Excel/Template/TextObject.pm b/lib/Excel/Template/TextObject.pm
new file mode 100755 (executable)
index 0000000..8fa6b47
--- /dev/null
@@ -0,0 +1,79 @@
+package Excel::Template::TextObject;
+
+use strict;
+
+BEGIN {
+    use vars qw(@ISA);
+    @ISA = qw(Excel::Template::Base);
+
+    use Excel::Template::Base;
+
+UNI_YES     use Unicode::String;
+}
+
+# This is a helper object. It is not instantiated by the user,
+# nor does it represent an XML object. Rather, certain elements,
+# such as <textbox>, can use this object to do text with variable
+# substitutions.
+
+sub new
+{
+    my $class = shift;
+    my $self = $class->SUPER::new(@_);
+
+    $self->{STACK} = [] unless UNIVERSAL::isa($self->{STACK}, 'ARRAY');
+
+    return $self;
+}
+
+sub resolve
+{
+    my $self = shift;
+    my ($context) = @_;
+
+UNI_YES    my $t = Unicode::String::utf8('');
+UNI_NO    my $t = '';
+
+    for my $tok (@{$self->{STACK}})
+    {
+        my $val = $tok;
+        $val = $val->resolve($context)
+            if Excel::Template::Factory::is_embedded( $val );
+
+UNI_YES        $t .= Unicode::String::utf8("$val");
+UNI_NO        $t .= $val;
+    }
+
+    return $t;
+}
+
+1;
+__END__
+
+=head1 NAME
+
+Excel::Template::TextObject
+
+=head1 PURPOSE
+
+=head1 NODE NAME
+
+=head1 INHERITANCE
+
+=head1 ATTRIBUTES
+
+=head1 CHILDREN
+
+=head1 AFFECTS
+
+=head1 DEPENDENCIES
+
+=head1 USAGE
+
+=head1 AUTHOR
+
+Rob Kinyon (rob.kinyon@gmail.com)
+
+=head1 SEE ALSO
+
+=cut
index 86fd2f1..08a9954 100644 (file)
@@ -1,12 +1,14 @@
-# -*- perl -*-
-
-# t/001_load.t - check module loading and create testing directory
+use strict;
+use warnings;
+$|++;
 
 use Test::More tests => 2;
 
-BEGIN { use_ok( 'Excel::Template' ); }
+my $CLASS = 'Excel::Template';
+
+use_ok( $CLASS );
 
-my $object = Excel::Template->new ();
-isa_ok ($object, 'Excel::Template');
+my $object = $CLASS->new ();
+isa_ok( $object, $CLASS );
 
 
diff --git a/t/002.xml b/t/002.xml
new file mode 100644 (file)
index 0000000..1f2269b
--- /dev/null
+++ b/t/002.xml
@@ -0,0 +1 @@
+<workbook />
diff --git a/t/002_workbook.t b/t/002_workbook.t
new file mode 100644 (file)
index 0000000..07730b8
--- /dev/null
@@ -0,0 +1,26 @@
+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/002.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::close( '' )
+__END_EXPECTED__
diff --git a/t/003.xml b/t/003.xml
new file mode 100644 (file)
index 0000000..881d6cf
--- /dev/null
+++ b/t/003.xml
@@ -0,0 +1,5 @@
+<workbook>
+  <worksheet />
+  <worksheet name="foo"/>
+  <worksheet name="foo"/>
+</workbook>
diff --git a/t/003_worksheet.t b/t/003_worksheet.t
new file mode 100644 (file)
index 0000000..685c588
--- /dev/null
@@ -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/003.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( '' )
+Spreadsheet::WriteExcel::Worksheet::new( '' )
+Spreadsheet::WriteExcel::add_worksheet( 'foo' )
+Spreadsheet::WriteExcel::Worksheet::new( '' )
+Spreadsheet::WriteExcel::add_worksheet( '' )
+Spreadsheet::WriteExcel::Worksheet::new( '' )
+Spreadsheet::WriteExcel::close( '' )
+__END_EXPECTED__
diff --git a/t/004.xml b/t/004.xml
new file mode 100644 (file)
index 0000000..bd01d93
--- /dev/null
+++ b/t/004.xml
@@ -0,0 +1,7 @@
+<workbook>
+  <worksheet name="cell">
+    <cell>Test1</cell>
+    <cell text="Test2" />
+    <cell />
+  </worksheet>
+</workbook>
diff --git a/t/004_cell.t b/t/004_cell.t
new file mode 100644 (file)
index 0000000..4f9a403
--- /dev/null
@@ -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/004.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( 'cell' )
+Spreadsheet::WriteExcel::Worksheet::new( '' )
+Spreadsheet::WriteExcel::Worksheet::write( '0', '0', 'Test1', '1' )
+Spreadsheet::WriteExcel::Worksheet::write( '0', '1', 'Test2', '1' )
+Spreadsheet::WriteExcel::Worksheet::write( '0', '2', '', '1' )
+Spreadsheet::WriteExcel::close( '' )
+__END_EXPECTED__
diff --git a/t/005.xml b/t/005.xml
new file mode 100644 (file)
index 0000000..c8111da
--- /dev/null
+++ b/t/005.xml
@@ -0,0 +1,38 @@
+<workbook>
+  <bold />
+  <hidden />
+  <italic />
+  <locked />
+  <shadow />
+  <strikeout />
+
+  <format font_outline="1" />
+  <format shrink="1" />
+  <format text_wrap="1" />
+  <format text_justlast="1" />
+  <format size="3" />
+  <format num_format="3" />
+  <format underline="3" />
+  <format rotation="3" />
+  <format indent="3" />
+  <format pattern="3" />
+  <format border="3" />
+  <format bottom="3" />
+  <format top="3" />
+  <format left="3" />
+  <format right="3" />
+  <format font="3" />
+  <format color="3" />
+  <format align="3" />
+  <format valign="3" />
+  <format bg_color="3" />
+  <format fg_color="3" />
+  <format border_color="3" />
+  <format bottom_color="3" />
+  <format top_color="3" />
+  <format left_color="3" />
+  <format right_color="3" />
+
+
+  <bold><italic><hidden /></italic></bold>
+</workbook>
diff --git a/t/005_formats.t b/t/005_formats.t
new file mode 100644 (file)
index 0000000..134b978
--- /dev/null
@@ -0,0 +1,60 @@
+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/005.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_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_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' )
+Spreadsheet::WriteExcel::add_format( 'size', '3' )
+Spreadsheet::WriteExcel::add_format( 'num_format', '3' )
+Spreadsheet::WriteExcel::add_format( 'underline', '3' )
+Spreadsheet::WriteExcel::add_format( 'rotation', '3' )
+Spreadsheet::WriteExcel::add_format( 'indent', '3' )
+Spreadsheet::WriteExcel::add_format( 'pattern', '3' )
+Spreadsheet::WriteExcel::add_format( 'border', '3' )
+Spreadsheet::WriteExcel::add_format( 'bottom', '3' )
+Spreadsheet::WriteExcel::add_format( 'top', '3' )
+Spreadsheet::WriteExcel::add_format( 'left', '3' )
+Spreadsheet::WriteExcel::add_format( 'right', '3' )
+Spreadsheet::WriteExcel::add_format( 'font', '3' )
+Spreadsheet::WriteExcel::add_format( 'color', '3' )
+Spreadsheet::WriteExcel::add_format( 'align', '3' )
+Spreadsheet::WriteExcel::add_format( 'valign', '3' )
+Spreadsheet::WriteExcel::add_format( 'bg_color', '3' )
+Spreadsheet::WriteExcel::add_format( 'fg_color', '3' )
+Spreadsheet::WriteExcel::add_format( 'border_color', '3' )
+Spreadsheet::WriteExcel::add_format( 'bottom_color', '3' )
+Spreadsheet::WriteExcel::add_format( 'top_color', '3' )
+Spreadsheet::WriteExcel::add_format( 'left_color', '3' )
+Spreadsheet::WriteExcel::add_format( 'right_color', '3' )
+Spreadsheet::WriteExcel::add_format( 'bold', '1', 'italic', '1' )
+Spreadsheet::WriteExcel::add_format( 'bold', '1', 'hidden', '1', 'italic', '1' )
+Spreadsheet::WriteExcel::close( '' )
+__END_EXPECTED__
diff --git a/t/006.xml b/t/006.xml
new file mode 100644 (file)
index 0000000..75037a5
--- /dev/null
+++ b/t/006.xml
@@ -0,0 +1,7 @@
+<workbook>
+  <worksheet name="cell">
+    <cell><var name="test1" /></cell>
+    <cell text="$test2" />
+    <cell>PRE <var name="test1" /> POST</cell>
+  </worksheet>
+</workbook>
diff --git a/t/006_variables.t b/t/006_variables.t
new file mode 100644 (file)
index 0000000..d6c14c8
--- /dev/null
@@ -0,0 +1,39 @@
+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/006.xml',
+);
+isa_ok( $object, $CLASS );
+
+ok(
+    $object->param( 
+        test1 => 'test1',
+        test2 => 'test2',
+    ),
+    '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( 'cell' )
+Spreadsheet::WriteExcel::Worksheet::new( '' )
+Spreadsheet::WriteExcel::Worksheet::write( '0', '0', 'test1', '1' )
+Spreadsheet::WriteExcel::Worksheet::write( '0', '1', 'test2', '1' )
+Spreadsheet::WriteExcel::Worksheet::write( '0', '2', 'PRE test1 POST', '1' )
+Spreadsheet::WriteExcel::close( '' )
+__END_EXPECTED__
diff --git a/t/007.xml b/t/007.xml
new file mode 100644 (file)
index 0000000..2900a4a
--- /dev/null
+++ b/t/007.xml
@@ -0,0 +1,11 @@
+<workbook>
+  <worksheet name="cell">
+    <cell />
+    <bold>
+      <cell />
+      <italic>
+        <cell />
+      </italic>
+    </bold>
+  </worksheet>
+</workbook>
diff --git a/t/007_cell_formats.t b/t/007_cell_formats.t
new file mode 100644 (file)
index 0000000..ef5e683
--- /dev/null
@@ -0,0 +1,33 @@
+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/007.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( 'cell' )
+Spreadsheet::WriteExcel::Worksheet::new( '' )
+Spreadsheet::WriteExcel::Worksheet::write( '0', '0', '', '1' )
+Spreadsheet::WriteExcel::add_format( 'bold', '1' )
+Spreadsheet::WriteExcel::Worksheet::write( '0', '1', '', '2' )
+Spreadsheet::WriteExcel::add_format( 'bold', '1', 'italic', '1' )
+Spreadsheet::WriteExcel::Worksheet::write( '0', '2', '', '3' )
+Spreadsheet::WriteExcel::close( '' )
+__END_EXPECTED__
diff --git a/t/008.xml b/t/008.xml
new file mode 100644 (file)
index 0000000..d481cc4
--- /dev/null
+++ b/t/008.xml
@@ -0,0 +1,7 @@
+<workbook>
+  <worksheet name="formula">
+    <formula>Test1</formula>
+    <formula text="Test2" />
+    <formula />
+  </worksheet>
+</workbook>
diff --git a/t/008_formula.t b/t/008_formula.t
new file mode 100644 (file)
index 0000000..2bf75fd
--- /dev/null
@@ -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/008.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( 'formula' )
+Spreadsheet::WriteExcel::Worksheet::new( '' )
+Spreadsheet::WriteExcel::Worksheet::write_formula( '0', '0', 'Test1', '1' )
+Spreadsheet::WriteExcel::Worksheet::write_formula( '0', '1', 'Test2', '1' )
+Spreadsheet::WriteExcel::Worksheet::write_formula( '0', '2', '', '1' )
+Spreadsheet::WriteExcel::close( '' )
+__END_EXPECTED__
diff --git a/t/009.xml b/t/009.xml
new file mode 100644 (file)
index 0000000..e36b384
--- /dev/null
+++ b/t/009.xml
@@ -0,0 +1,24 @@
+<workbook>
+  <worksheet name="loops">
+    <loop name="loopy">
+      <row>
+        <cell text="$value" />
+        <cell text="text" />
+      </row>
+    </loop>
+
+    <loop name="outer">
+      <row>
+        <cell text="$iter" />
+        <loop name="inner">
+          <cell text="$value" />
+        </loop>
+      </row>
+    </loop>
+
+  </worksheet>
+
+  <loop name="worksheets">
+    <worksheet name="$value" />
+  </loop>
+</workbook>
diff --git a/t/009_loop.t b/t/009_loop.t
new file mode 100644 (file)
index 0000000..2f8f6dd
--- /dev/null
@@ -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 (file)
index 0000000..24a6f72
--- /dev/null
+++ b/t/010.xml
@@ -0,0 +1,8 @@
+<workbook>
+  <worksheet name="scope">
+    <scope text="1">
+      <cell />
+      <cell />
+    </scope>
+  </worksheet>
+</workbook>
diff --git a/t/010_scope.t b/t/010_scope.t
new file mode 100644 (file)
index 0000000..ac1aaea
--- /dev/null
@@ -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 (file)
index 0000000..fea37f7
--- /dev/null
+++ b/t/011.xml
@@ -0,0 +1,20 @@
+<workbook>
+  <worksheet name="conditional">
+    <loop name="loopy">
+      <row>
+        <if name="int">
+          <cell text="bool" />
+        </if>
+        <if name="int" is="FALSE">
+          <cell text="not bool" />
+        </if>
+        <if name="int" op="==" value="0">
+          <cell text="int" />
+        </if>
+        <if name="char" op="eq" value="y">
+          <cell text="char" />
+        </if>
+      </row>
+    </loop>
+  </worksheet>
+</workbook>
diff --git a/t/011_conditional.t b/t/011_conditional.t
new file mode 100644 (file)
index 0000000..45bcb72
--- /dev/null
@@ -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 (file)
index 0000000..8ed109c
--- /dev/null
+++ b/t/012.xml
@@ -0,0 +1,7 @@
+<workbook>
+  <worksheet name="backref">
+    <cell ref="foo" text="not me" />
+    <cell ref="foo" text="me" />
+    <cell>=<backref ref="foo"/></cell>
+  </worksheet>
+</workbook>
diff --git a/t/012_backref.t b/t/012_backref.t
new file mode 100644 (file)
index 0000000..25301ec
--- /dev/null
@@ -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 (file)
index 0000000..4862743
--- /dev/null
+++ b/t/013.xml
@@ -0,0 +1,8 @@
+<workbook>
+  <worksheet name="backref">
+    <cell ref="foo" text="1" />
+    <cell ref="foo" text="2" />
+    <cell ref="foo" text="3" />
+    <cell>=SUM(<range ref="foo"/>)</cell>
+  </worksheet>
+</workbook>
diff --git a/t/013_range.t b/t/013_range.t
new file mode 100644 (file)
index 0000000..c865c63
--- /dev/null
@@ -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__
diff --git a/t/Spreadsheet/WriteExcel.pm b/t/Spreadsheet/WriteExcel.pm
new file mode 100644 (file)
index 0000000..1682f2c
--- /dev/null
@@ -0,0 +1,50 @@
+package Spreadsheet::WriteExcel;
+
+use strict;
+
+use mock;
+use Spreadsheet::WriteExcel::Worksheet;
+
+sub new {
+    my $self = bless {
+    }, shift;
+
+    {
+        local $" = "', '";
+        push @mock::calls, __PACKAGE__ . "::new( '@_' )";
+    }
+
+    return $self;
+}
+
+sub close {
+    shift;
+    {
+        local $" = "', '";
+        push @mock::calls, __PACKAGE__ . "::close( '@_' )";
+    }
+}
+
+sub add_worksheet {
+    shift;
+    {
+        local $" = "', '";
+        push @mock::calls, __PACKAGE__ . "::add_worksheet( '@_' )";
+    }
+    return Spreadsheet::WriteExcel::Worksheet->new;
+}
+
+my $format_num = 1;
+sub add_format {
+    shift;
+    my %x = @_;
+    my @x = map { $_ => $x{$_} } sort keys %x;
+    {
+        local $" = "', '";
+        push @mock::calls, __PACKAGE__ . "::add_format( '@x' )";
+    }
+    return $format_num++;
+}
+
+1;
+__END__
diff --git a/t/Spreadsheet/WriteExcel/Worksheet.pm b/t/Spreadsheet/WriteExcel/Worksheet.pm
new file mode 100644 (file)
index 0000000..16f3be1
--- /dev/null
@@ -0,0 +1,38 @@
+package Spreadsheet::WriteExcel::Worksheet;
+
+use strict;
+
+use mock;
+
+sub new {
+    my $self = bless {
+    }, shift;
+
+    {
+        local $" = "', '";
+        push @mock::calls, __PACKAGE__ . "::new( '@_' )";
+    }
+
+    return $self;
+}
+
+sub write_formula {
+    my $self = shift;
+
+    {
+        local $" = "', '";
+        push @mock::calls, __PACKAGE__ . "::write_formula( '@_' )";
+    }
+}
+
+sub write {
+    my $self = shift;
+
+    {
+        local $" = "', '";
+        push @mock::calls, __PACKAGE__ . "::write( '@_' )";
+    }
+}
+
+1;
+__END__
diff --git a/t/mock.pm b/t/mock.pm
new file mode 100644 (file)
index 0000000..3edd711
--- /dev/null
+++ b/t/mock.pm
@@ -0,0 +1,14 @@
+package mock;
+
+use strict;
+
+use vars qw/ @calls /;
+
+@calls = ();
+
+sub reset { @calls = (); }
+sub get_calls { @calls }
+
+
+1;
+__END__