- Fixed Makefile.PL so that it uses PM_FILTER instead of rolling its own
Rob Kinyon [Fri, 5 Nov 2004 18:33:24 +0000 (18:33 +0000)]
        - 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

32 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/Element/Backref.pm
lib/Excel/Template/Element/Cell.pm [moved from lib/Excel/Template/Element/Cell.pm_ with 91% similarity]
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 [moved from lib/Excel/Template/TextObject.pm_ with 100% similarity]
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/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..72be728 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,74 +1,83 @@
 Revision history for Perl distribution Excel::Template
 
+0.16 Fri Nov 05 16:15: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..00d7112 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,27 @@ 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/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..2c6a804
--- /dev/null
+++ b/META.yml
@@ -0,0 +1,16 @@
+# 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_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
+    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..fcdd1a4 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 tests for LOOP, SCOPE, CONDITIONAL, BACKREF, and RANGE
+- Add more stringent tests for what we already have
 - Anything else people suggest
-
index 1d7626e..e741d7d 100644 (file)
@@ -6,13 +6,12 @@ BEGIN {
     use Excel::Template::Base;
     use vars qw ($VERSION @ISA);
 
-    $VERSION  = '0.15';
+    $VERSION  = '0.16';
     @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 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
 
similarity index 91%
rename from lib/Excel/Template/Element/Cell.pm_
rename to lib/Excel/Template/Element/Cell.pm
index e09a4c2..9272e51 100755 (executable)
@@ -47,7 +47,9 @@ UNI_NO         $txt = '';
 sub render
 {
     my $self = shift;
-    my ($context) = @_;
+    my ($context, $method) = @_;
+
+    $method ||= 'write';
 
     my ($row, $col) = map { $context->get($self, $_) } qw(ROW COL);
 
@@ -57,7 +59,7 @@ sub render
         $context->add_reference( $ref, $row, $col );
     }
 
-    $context->active_worksheet->write(
+    $context->active_worksheet->$method(
         $row, $col,
         $self->get_text($context),
         $context->active_format,
@@ -107,6 +109,12 @@ 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.
@@ -139,11 +147,6 @@ entire parameter's value.
 
 Please see Spreadsheet::WriteExcel for what constitutes a legal formula.
 
-=head1 BACK-REFERENCES
-
-Currently, you can only use a hard-coded formula. The next release will add the
-capability to have a formula reference other nodes in the template dynamically.
-
 =head1 AUTHOR
 
 Rob Kinyon (rob.kinyon@gmail.com)
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..280b213 100644 (file)
@@ -52,7 +52,9 @@ BEGIN {
     FORMAT
     FORMULA
     IF
+    HIDDEN
     ITALIC
+    LOCKED
     OUTLINE
     LOOP
     BACKREF
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);
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/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__