Checkin of landscape/portrait feature
Rob Kinyon [Tue, 1 Aug 2006 02:16:44 +0000 (02:16 +0000)]
Changes
lib/Excel/Template.pm
lib/Excel/Template/Container/Worksheet.pm
t/026_landscape.t [new file with mode: 0644]
t/Spreadsheet/WriteExcel/Worksheet.pm

diff --git a/Changes b/Changes
index 74edf3a..f3eaaab 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,8 @@
 Revision history for Perl distribution Excel::Template
 
+0.28 Fri Jul 31 22:00:00 2005
+    - Added landscape and portrait orientations for worksheets
+
 0.27 Tue Jul 25 10:00:00 2006
     - Fixed how widths are whitelisted to allow '.' for fractions
 
index 2706c4e..26a0d0e 100644 (file)
@@ -6,7 +6,7 @@ BEGIN {
     use Excel::Template::Base;
     use vars qw ($VERSION @ISA);
 
-    $VERSION  = '0.27';
+    $VERSION  = '0.28';
     @ISA      = qw( Excel::Template::Base );
 }
 
@@ -477,38 +477,38 @@ Excel::Template is also part of the CPAN Kwalitee initiative, being one of the t
   ---------------------------- ------ ------ ------ ------ ------ ------ ------
   File                           stmt   bran   cond    sub    pod   time  total
   ---------------------------- ------ ------ ------ ------ ------ ------ ------
-  blib/lib/Excel/Template.pm     93.8   60.0   58.8  100.0  100.0   15.8   83.3
-  ...ib/Excel/Template/Base.pm   94.4   50.0    n/a  100.0    0.0    6.7   80.0
-  ...cel/Template/Container.pm  100.0   50.0   33.3  100.0    0.0    5.7   83.3
+  blib/lib/Excel/Template.pm     93.8   60.0   58.8  100.0  100.0   31.8   83.3
+  ...ib/Excel/Template/Base.pm   94.4   50.0    n/a  100.0    0.0    4.4   80.0
+  ...cel/Template/Container.pm  100.0   50.0   33.3  100.0    0.0    2.0   83.3
   ...emplate/Container/Bold.pm  100.0    n/a    n/a  100.0    0.0    0.1   95.0
-  .../Container/Conditional.pm   95.9   90.0   66.7  100.0    0.0    2.0   91.0
-  ...plate/Container/Format.pm  100.0    n/a    n/a  100.0    0.0    0.8   96.8
-  ...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
-  ...ainer/KeepLeadingZeros.pm  100.0  100.0    n/a  100.0    0.0    0.1   96.3
+  .../Container/Conditional.pm   95.9   90.0   66.7  100.0    0.0    0.3   91.0
+  ...plate/Container/Format.pm  100.0    n/a    n/a  100.0    0.0    1.5   96.8
+  ...plate/Container/Hidden.pm  100.0    n/a    n/a  100.0    0.0    0.0   95.0
+  ...plate/Container/Italic.pm  100.0    n/a    n/a  100.0    0.0    0.0   95.0
+  ...ainer/KeepLeadingZeros.pm  100.0  100.0    n/a  100.0    0.0    0.0   96.3
   ...plate/Container/Locked.pm  100.0    n/a    n/a  100.0    0.0    0.0   95.0
-  ...emplate/Container/Loop.pm   96.8   50.0   50.0  100.0    0.0    0.5   82.7
-  ...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    0.0    0.3   90.6
+  ...emplate/Container/Loop.pm   96.8   50.0   50.0  100.0    0.0    0.1   82.7
+  ...late/Container/Outline.pm  100.0    n/a    n/a  100.0    0.0    0.0   95.0
+  ...Template/Container/Row.pm  100.0   75.0    n/a  100.0    0.0    0.1   90.6
   ...mplate/Container/Scope.pm  100.0    n/a    n/a  100.0    n/a    0.0  100.0
   ...plate/Container/Shadow.pm  100.0    n/a    n/a  100.0    0.0    0.0   95.0
   ...te/Container/Strikeout.pm  100.0    n/a    n/a  100.0    0.0    0.0   95.0
-  ...ate/Container/Workbook.pm  100.0    n/a    n/a  100.0    n/a    0.6  100.0
-  ...te/Container/Worksheet.pm   94.7   75.0    n/a  100.0    0.0    0.9   87.1
-  ...Excel/Template/Context.pm   98.0   80.0   75.0  100.0   73.3   31.4   90.7
-  ...Excel/Template/Element.pm  100.0    n/a    n/a  100.0    n/a    0.4  100.0
+  ...ate/Container/Workbook.pm  100.0    n/a    n/a  100.0    n/a    7.0  100.0
+  ...te/Container/Worksheet.pm   95.5   87.5  100.0  100.0    0.0    1.1   90.2
+  ...Excel/Template/Context.pm   98.0   80.0   75.0  100.0   73.3   17.0   90.7
+  ...Excel/Template/Element.pm  100.0    n/a    n/a  100.0    n/a    0.1  100.0
   ...mplate/Element/Backref.pm  100.0   50.0   33.3  100.0    0.0    0.1   87.1
-  .../Template/Element/Cell.pm   97.9   75.0   80.0  100.0    0.0    3.9   88.6
-  ...mplate/Element/Formula.pm  100.0    n/a    n/a  100.0    0.0    0.1   94.1
+  .../Template/Element/Cell.pm   97.9   75.0   80.0  100.0    0.0    5.6   88.6
+  ...mplate/Element/Formula.pm  100.0    n/a    n/a  100.0    0.0    0.0   94.1
   ...te/Element/FreezePanes.pm  100.0    n/a    n/a  100.0    0.0    0.0   95.5
-  ...Template/Element/Image.pm  100.0  100.0    n/a  100.0    0.0    0.1   94.3
+  ...Template/Element/Image.pm  100.0  100.0    n/a  100.0    0.0    0.0   94.3
   ...Template/Element/Range.pm  100.0   66.7    n/a  100.0    0.0    0.1   88.9
   ...l/Template/Element/Var.pm  100.0    n/a    n/a  100.0    0.0    0.0   94.1
-  ...Excel/Template/Factory.pm  100.0   73.1   66.7  100.0  100.0   16.3   91.4
-  .../Excel/Template/Format.pm   98.4   75.0   33.3  100.0   66.7    9.1   90.5
-  ...xcel/Template/Iterator.pm   98.6   80.0   70.6  100.0   50.0    2.0   88.8
-  ...el/Template/TextObject.pm   92.9   62.5   33.3  100.0    0.0    2.8   80.9
-  Total                          97.8   74.3   63.5  100.0   35.7  100.0   89.4
+  ...Excel/Template/Factory.pm  100.0   73.1   66.7  100.0  100.0   22.3   91.4
+  .../Excel/Template/Format.pm   98.4   75.0   33.3  100.0   66.7    2.6   90.5
+  ...xcel/Template/Iterator.pm   98.6   80.0   70.6  100.0   50.0    0.3   88.8
+  ...el/Template/TextObject.pm   92.9   62.5   33.3  100.0    0.0    3.3   80.9
+  Total                          97.8   74.7   64.6  100.0   35.7  100.0   89.4
   ---------------------------- ------ ------ ------ ------ ------ ------ ------
 
 =head1 COPYRIGHT
index 378915b..6997f85 100644 (file)
@@ -27,6 +27,13 @@ sub render
     $worksheet->keep_leading_zeros( 1 )
         if $context->mark( 'keep_leading_zeros' );
 
+    if ( $context->get( $self, 'LANDSCAPE' ) && !$self->{PORTRAIT} ) {
+        $worksheet->set_landscape;
+    }
+    elsif ( $context->get( $self, 'PORTRAIT' ) ) {
+        $worksheet->set_portrait;
+    }
+
     return $self->SUPER::render($context);
 }
 
@@ -68,6 +75,32 @@ This activates the HIDDEN and LOCKED nodes.
 
 This will change the behavior of the worksheet to preserve leading zeros.
 
+=item * LANDSCAPE
+
+This will set the worksheet's orientation to landscape.
+
+=item * PORTRAIT
+
+This will set the worksheet's orientation to portrait.
+
+While this is the default, it's useful to override the default at times. For
+example, in the following situation:
+
+  <workbook landscape="1">
+    <worksheet>
+      ...
+    </worksheet
+    <worksheet portrait="1">
+      ...
+    </worksheet
+    <worksheet>
+      ...
+    </worksheet
+  </workbook>
+
+In that example, the first and third worksheets will be landscape (inheriting
+it from the workbook node), but the second worksheet will be portrait.
+
 =back
 
 =head1 CHILDREN
diff --git a/t/026_landscape.t b/t/026_landscape.t
new file mode 100644 (file)
index 0000000..783e97a
--- /dev/null
@@ -0,0 +1,42 @@
+use strict;
+
+use Test::More tests => 4;
+
+use lib 't';
+use mock;
+mock::reset;
+
+my $CLASS = 'Excel::Template';
+use_ok( $CLASS );
+
+my $object = $CLASS->new(
+    file => \*DATA,
+);
+isa_ok( $object, $CLASS );
+
+ok( $object->write_file( 'filename' ), 'Something returned' );
+
+my @calls = mock::get_calls;
+is( join( $/, @calls, '' ), <<__END_EXPECTED__, 'Calls match up' );
+Spreadsheet::WriteExcel::new( 'filename' )
+Spreadsheet::WriteExcel::add_format( '' )
+Spreadsheet::WriteExcel::add_worksheet( 'landscape' )
+Spreadsheet::WriteExcel::Worksheet::new( '' )
+Spreadsheet::WriteExcel::Worksheet::set_landscape( '' )
+Spreadsheet::WriteExcel::add_worksheet( 'landscape2' )
+Spreadsheet::WriteExcel::Worksheet::new( '' )
+Spreadsheet::WriteExcel::Worksheet::set_landscape( '' )
+Spreadsheet::WriteExcel::add_worksheet( 'portrait' )
+Spreadsheet::WriteExcel::Worksheet::new( '' )
+Spreadsheet::WriteExcel::Worksheet::set_portrait( '' )
+Spreadsheet::WriteExcel::close( '' )
+__END_EXPECTED__
+
+__DATA__
+<workbook>
+  <worksheet name="landscape" landscape="1" />
+  <scope landscape="1">
+    <worksheet name="landscape2" />
+    <worksheet name="portrait" portrait="1" />
+  </scope>
+</workbook>
index a3e6d16..5c779b4 100644 (file)
@@ -16,103 +16,19 @@ sub new {
     return $self;
 }
 
-sub write_string {
-    my $self = shift;
-
-    {
-        local $" = "', '";
-        push @mock::calls, __PACKAGE__ . "::write_string( '@_' )";
-    }
-}
-
-sub write_number {
-    my $self = shift;
-
-    {
-        local $" = "', '";
-        push @mock::calls, __PACKAGE__ . "::write_number( '@_' )";
-    }
-}
-
-sub write_blank {
-    my $self = shift;
-
-    {
-        local $" = "', '";
-        push @mock::calls, __PACKAGE__ . "::write_blank( '@_' )";
-    }
-}
-
-sub write_url {
-    my $self = shift;
-
-    {
-        local $" = "', '";
-        push @mock::calls, __PACKAGE__ . "::write_url( '@_' )";
-    }
-}
-
-sub write_formula {
-    my $self = shift;
-
-    {
-        local $" = "', '";
-        push @mock::calls, __PACKAGE__ . "::write_formula( '@_' )";
-    }
-}
-
-sub write {
-    my $self = shift;
-
-    {
-        local $" = "', '";
-        push @mock::calls, __PACKAGE__ . "::write( '@_' )";
-    }
-}
-
-sub set_row {
-    my $self = shift;
-
-    {
-        local $" = "', '";
-        push @mock::calls, __PACKAGE__ . "::set_row( '@_' )";
-    }
-}
-
-sub set_column {
-    my $self = shift;
-
-    {
-        local $" = "', '";
-        push @mock::calls, __PACKAGE__ . "::set_column( '@_' )";
-    }
-}
-
-sub keep_leading_zeros {
-    my $self = shift;
-
-    {
-        local $" = "', '";
-        push @mock::calls, __PACKAGE__ . "::keep_leading_zeros( '@_' )";
-    }
-}
-
-sub insert_bitmap {
-    my $self = shift;
-
-    {
-        local $" = "', '";
-        push @mock::calls, __PACKAGE__ . "::insert_bitmap( '@_' )";
-    }
-}
-
-sub freeze_panes {
-    my $self = shift;
-
-    {
-        local $" = "', '";
-        push @mock::calls, __PACKAGE__ . "::freeze_panes( '@_' )";
-    }
+my @funcs = qw(
+    write_string write_number write_blank write_url write_formula write
+    set_row set_column keep_leading_zeros insert_bitmap freeze_panes
+    set_landscape set_portrait
+);
+
+foreach my $func ( @funcs ) {
+    no strict 'refs';
+    *$func = sub {
+        my $self = shift;
+        local $" = "', '";
+        push @mock::calls, __PACKAGE__ . "::${func}( '@_' )";
+    };
 }
 
 1;