r13918@rob-kinyons-powerbook58: rob | 2006-06-02 10:04:04 -0400
[p5sagit/Excel-Template.git] / lib / Excel / Template.pm
index cf484ef..571eac2 100644 (file)
@@ -6,7 +6,7 @@ BEGIN {
     use Excel::Template::Base;
     use vars qw ($VERSION @ISA);
 
-    $VERSION  = '0.23';
+    $VERSION  = '0.26';
     @ISA      = qw( Excel::Template::Base );
 }
 
@@ -86,7 +86,7 @@ sub param
     my $self = shift;
 
     # Allow an arbitrary number of hashrefs, so long as they're the first things    # into param(). Put each one onto the end, de-referenced.
-    push @_, %{shift @_} while UNIVERSAL::isa($_[0], 'HASH');
+    push @_, %{shift @_} while ref $_[0] eq 'HASH';
 
     (@_ % 2)
         && die __PACKAGE__, "->param() : Odd number of parameters to param()\n";
@@ -106,10 +106,15 @@ sub write_file
     my $xls = $self->{RENDERER}->new($filename)
         || die "Cannot create XLS in '$filename': $!\n";
 
-    $self->_prepare_output($xls);
+    eval {
+        $self->_prepare_output($xls);
+    };
+print $@ if $@;
 
     $xls->close;
 
+    return if $@;
+
     return ~~1;
 }
 
@@ -120,7 +125,8 @@ sub output
     my $output;
     tie *XLS, 'IO::Scalar', \$output;
 
-    $self->write_file(\*XLS);
+    $self->write_file(\*XLS)
+        or return;
 
     return $output;
 }
@@ -143,7 +149,7 @@ sub parse_xml
 
                 if ( $node->isa( 'WORKBOOK' ) )
                 {
-                    push @{$self->{WORKBOOKS}}, $node;
+                    $self->{WORKBOOK} = $node;
                 }
                 elsif ( $node->is_embedded )
                 {
@@ -196,26 +202,34 @@ sub parse_xml
  
         push @parms, Base => $dirname;
 
-        open( INFILE, "<$file" )
-            || die "Cannot open '$file' for reading: $!\n";
-
+        eval q{
+            open( INFILE, '<', $file )
+                || die "Cannot open '$file' for reading: $!\n";
+        }; if ( $@ ) {
+           if ( $@ =~ /Too many arguments for open/ ) {
+                open( INFILE, "< $file" )
+                    || die "Cannot open '$file' for reading: $!\n";
+            } else {
+                die $@;
+            }
+        }
     }
 
     my $parser = XML::Parser->new( @parms );
     $parser->parse(do { local $/ = undef; <INFILE> });
 
-    unless ( ref $file )
-    {
-        close INFILE;
-    }
+    close INFILE
+        unless ref $file;
 
     return ~~1;
 }
-*parse = \&parse_xml;
+*parse = *parse = \&parse_xml;
 
 sub _prepare_output
 {
     my $self = shift;
+    return unless $self->{WORKBOOK};
+
     my ($xls) = @_;
 
     my $context = Excel::Template::Factory->_create(
@@ -226,7 +240,7 @@ sub _prepare_output
         UNICODE   => $self->{UNICODE},
     );
 
-    $_->render($context) for @{$self->{WORKBOOKS}};
+    $self->{WORKBOOK}->render($context);
 
     return ~~1;
 }
@@ -399,7 +413,7 @@ This node represents a loop. It behaves just like L<HTML::Template>'s TMPL_LOOP.
 
 =item * L<ROW|Excel::Template::Container::Row>
 
-This node represents a row of data. This is the A in A1.
+This node represents a row of data. This is the 1 in A1. There is no COLUMN node, as of yet.
 
 =item * L<FORMAT|Excel::Template::Container::Format>
 
@@ -460,39 +474,40 @@ I used L<Devel::Cover> to test the coverage of my tests. Every release, I intend
 
 Excel::Template is also part of the CPAN Kwalitee initiative, being one of the top 100 non-core modules downloaded from CPAN. If you wish to help out, please feel free to contribute tests, patches, and/or suggestions.
 
-  -----------------------------------------------------------------------
-  File                           stmt brnch  cond   sub   pod  time total
-  -----------------------------------------------------------------------
-  blib/lib/Excel/Template.pm     96.0  62.5  58.8 100.0 100.0  25.2  86.2
-  ...ib/Excel/Template/Base.pm   87.0  50.0  66.7  81.8  87.5   8.7  83.0
-  ...cel/Template/Container.pm   71.4  50.0  33.3  70.0  80.0   4.9  68.4
-  ...emplate/Container/Bold.pm  100.0   n/a   n/a 100.0   0.0   0.7  95.0
-  .../Container/Conditional.pm   64.9  57.5  66.7 100.0   0.0   0.7  63.9
-  ...plate/Container/Format.pm  100.0   n/a   n/a 100.0   0.0   0.7  96.6
-  ...plate/Container/Hidden.pm  100.0   n/a   n/a 100.0   0.0   0.1  95.0
-  ...plate/Container/Italic.pm  100.0   n/a   n/a 100.0   0.0   0.1  95.0
-  ...plate/Container/Locked.pm  100.0   n/a   n/a 100.0   0.0   0.1  95.0
-  ...emplate/Container/Loop.pm   90.9  50.0  50.0 100.0  50.0   0.5  80.4
-  ...late/Container/Outline.pm  100.0   n/a   n/a 100.0   0.0   0.1  95.0
-  ...Template/Container/Row.pm  100.0  75.0   n/a 100.0  50.0   0.3  93.8
-  ...mplate/Container/Scope.pm  100.0   n/a   n/a 100.0   n/a   0.1 100.0
-  ...plate/Container/Shadow.pm  100.0   n/a   n/a 100.0   0.0   0.1  95.0
-  ...te/Container/Strikeout.pm  100.0   n/a   n/a 100.0   0.0   0.1  95.0
-  ...ate/Container/Workbook.pm  100.0   n/a   n/a 100.0   n/a   0.9 100.0
-  ...te/Container/Worksheet.pm   94.1  50.0   n/a 100.0   0.0   0.9  88.0
-  ...Excel/Template/Context.pm   84.3  53.4  54.2 100.0  92.3  19.5  76.0
-  ...Excel/Template/Element.pm  100.0   n/a   n/a 100.0   n/a   0.5 100.0
-  ...mplate/Element/Backref.pm  100.0  50.0  33.3 100.0   0.0   0.1  87.1
-  .../Template/Element/Cell.pm   95.8  65.0  80.0 100.0  66.7   3.8  86.9
-  ...mplate/Element/Formula.pm  100.0   n/a   n/a 100.0   0.0   0.3  94.1
-  ...Template/Element/Range.pm  100.0  66.7   n/a 100.0  66.7   0.2  93.3
-  ...l/Template/Element/Var.pm  100.0   n/a   n/a 100.0   0.0   0.1  94.1
-  ...Excel/Template/Factory.pm  100.0  73.1   n/a 100.0 100.0  16.3  92.6
-  .../Excel/Template/Format.pm   98.3  81.2  33.3 100.0 100.0  10.0  93.2
-  ...xcel/Template/Iterator.pm   98.6  80.0  70.6 100.0  83.3   1.9  90.3
-  ...el/Template/TextObject.pm   92.9  62.5  33.3 100.0  50.0   3.1  83.0
-  Total                          92.0  63.5  58.3  97.5  98.5 100.0  86.0
-  -----------------------------------------------------------------------
+  ---------------------------- ------ ------ ------ ------ ------ ------ ------
+  File                           stmt branch   cond    sub    pod   time  total
+  ---------------------------- ------ ------ ------ ------ ------ ------ ------
+  blib/lib/Excel/Template.pm     96.0   64.3   58.8  100.0  100.0   26.3   85.8
+  ...ib/Excel/Template/Base.pm   94.4   50.0    n/a  100.0   75.0    6.6   90.0
+  ...cel/Template/Container.pm  100.0   50.0   33.3  100.0   66.7    4.5   88.1
+  ...emplate/Container/Bold.pm  100.0    n/a    n/a  100.0    0.0    0.2   95.0
+  .../Container/Conditional.pm   95.9   90.0   66.7  100.0    0.0    1.7   91.0
+  ...plate/Container/Format.pm  100.0    n/a    n/a  100.0    0.0    0.6   96.6
+  ...plate/Container/Hidden.pm  100.0    n/a    n/a  100.0    0.0    0.2   95.0
+  ...plate/Container/Italic.pm  100.0    n/a    n/a  100.0    0.0    0.2   95.0
+  ...ainer/KeepLeadingZeros.pm  100.0  100.0    n/a  100.0    0.0    0.1   96.3
+  ...plate/Container/Locked.pm  100.0    n/a    n/a  100.0    0.0    0.1   95.0
+  ...emplate/Container/Loop.pm   96.8   50.0   50.0  100.0   50.0    0.4   84.6
+  ...late/Container/Outline.pm  100.0    n/a    n/a  100.0    0.0    0.1   95.0
+  ...Template/Container/Row.pm  100.0   75.0    n/a  100.0   50.0    0.3   93.8
+  ...mplate/Container/Scope.pm  100.0    n/a    n/a  100.0    n/a    0.1  100.0
+  ...plate/Container/Shadow.pm  100.0    n/a    n/a  100.0    0.0    0.1   95.0
+  ...te/Container/Strikeout.pm  100.0    n/a    n/a  100.0    0.0    0.1   95.0
+  ...ate/Container/Workbook.pm  100.0    n/a    n/a  100.0    n/a    1.0  100.0
+  ...te/Container/Worksheet.pm   94.7   75.0    n/a  100.0   50.0    1.0   90.3
+  ...Excel/Template/Context.pm   98.0   80.0   75.0  100.0   93.3   23.4   91.8
+  ...Excel/Template/Element.pm  100.0    n/a    n/a  100.0    n/a    0.3  100.0
+  ...mplate/Element/Backref.pm  100.0   50.0   33.3  100.0    0.0    0.2   87.1
+  .../Template/Element/Cell.pm   97.9   75.0   80.0  100.0   66.7    3.9   91.1
+  ...mplate/Element/Formula.pm  100.0    n/a    n/a  100.0    0.0    0.2   94.1
+  ...Template/Element/Range.pm  100.0   66.7    n/a  100.0   66.7    0.2   93.3
+  ...l/Template/Element/Var.pm  100.0    n/a    n/a  100.0    0.0    0.2   94.1
+  ...Excel/Template/Factory.pm  100.0   75.0    n/a  100.0  100.0   15.5   92.4
+  .../Excel/Template/Format.pm   98.4   75.0   33.3  100.0   66.7    8.1   91.2
+  ...xcel/Template/Iterator.pm   98.6   80.0   70.6  100.0   83.3    1.4   90.3
+  ...el/Template/TextObject.pm   92.9   62.5   33.3  100.0   50.0    3.2   83.0
+  Total                          98.0   75.2   63.4  100.0   98.5  100.0   92.2
+  ---------------------------- ------ ------ ------ ------ ------ ------ ------
 
 =head1 COPYRIGHT