Revision history for Perl distribution Excel::Template
+0.20 Wed Jan 26 12:00:00 2004
+ - Removed PM_FILTER by adding an optional USE_UNICODE runtime parameter.
+ - Added a "type" attribute to CELL to allow printing by the write_*() family
+
0.19 Wed Dec 08 12:00:00 2004
- Fixed META.yml
- Added more values to the MANIFEST.SKIP
t/013.xml
t/014_heightwidth.t
t/014.xml
+t/015_cell_type.t
+t/015.xml
t/mock.pm
t/Spreadsheet/WriteExcel.pm
t/Spreadsheet/WriteExcel/Worksheet.pm
# 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.19
+version: 0.20
version_from: lib/Excel/Template.pm
installdirs: site
requires:
# 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 (y/N)? ";
- my $answer = <STDIN>;
-
- if ($answer =~ /^[Yy]/)
+ eval { require Unicode::String; };
+ if ($@)
{
- $prereqs->{'Unicode::String'} = '0.01';
- $use_unicode = 1;
+ print "Note: If you want to work with Unicode, you will need to install";
+ print "the optional module Unicode::String and set USE_UNICODE to true.";
}
}
-my $pm_filter = $use_unicode
- ? q{perl -pi.old -e "s!UNI_YES ! !g;s!UNI_NO !\\#!g"}
- : q{perl -pi.old -e "s!UNI_NO ! !g;s!UNI_YES !\\#!g"}
-;
-
WriteMakefile(
NAME => 'Excel::Template',
VERSION_FROM => 'lib/Excel/Template.pm', # finds $VERSION
AUTHOR => 'Rob Kinyon (rob.kinyon@gmail.com)',
ABSTRACT => 'Excel::Template',
PREREQ_PM => $prereqs,
- PM_FILTER => $pm_filter,
);
use Excel::Template::Base;
use vars qw ($VERSION @ISA);
- $VERSION = '0.19';
+ $VERSION = '0.20';
@ISA = qw( Excel::Template::Base );
}
join("\n\t", @renderer_classes) .
"\n";
+ $self->{USE_UNICODE} = ~~0
+ if $] >= 5.008;
+
return $self;
}
$params{uc $_} = delete $params{$_} for keys %params;
@{$self->{PARAM_MAP}}{keys %params} = @params{keys %params};
- return !!1;
+ return ~~1;
}
sub write_file
$xls->close;
- return !!1;
+ return ~~1;
}
sub output
XLS => $xls,
PARAM_MAP => [ $self->{PARAM_MAP} ],
+ UNICODE => $self->{UNICODE},
);
$_->render($context) for @{$self->{WORKBOOKS}};
new() accepts an optional BIG_FILE parameter. This will attempt to change the
renderer from L<Spreadsheet::WriteExcel> to L<Spreadsheet::WriteExcel::Big>. You
-must have L<Spreadsheet::WriteExcel::Big> installed on your system.
+must already have L<Spreadsheet::WriteExcel::Big> installed on your system.
+
+new() also accepts an optional USE_UNICODE parameter. This will use
+L<Unicode::String> to represent strings instead of Perl's internal string
+handling. You must already have L<Unicode::String> installed on your system.
+
+The USE_UNICODE parameter will be ignored if you are using Perl 5.8 or higher as
+Perl's internal string handling is unicode-aware.
NOTE: L<Spreadsheet::WriteExcel::Big> and mod_perl clash for some reason. This
is outside of my control.
# represent an XML object. Rather, every container will use this object to
# maintain the context for its children.
-my %isAbsolute = map { $_ => !!1 } qw(
+my %isAbsolute = map { $_ => ~~1 } qw(
ROW
COL
);
return $self;
}
+sub use_unicode { $_[0]->{UNICODE} && 1 }
+
sub _find_param_in_map
{
my $self = shift;
next unless exists $map->{$param};
$depth--, next if $depth;
- $found = !!1;
+ $found = ~~1;
$val = $map->{$param};
last;
}
$self->{$key} = $self->resolve($obj, $key);
}
- return !!1;
+ return ~~1;
}
sub exit_scope
pop @{$self->{STACK}};
- return !!1;
+ return ~~1;
}
sub get
push @{$self->{REFERENCES}{$ref}}, [ $row, $col ];
- return !!1;
+ return ~~1;
}
sub get_all_references
}
else
{
-UNI_YES $txt = Unicode::String::utf8('');
-UNI_NO $txt = '';
+ $txt = $context->use_unicode
+ ? Unicode::String::utf8('')
+ : '';
}
return $txt;
}
+my %legal_types = (
+ 'blank' => 'write_blank',
+ 'formula' => 'write_formula',
+ 'number' => 'write_number',
+ 'string' => 'write_string',
+ 'url' => 'write_url',
+);
+
sub render
{
my $self = shift;
my ($context, $method) = @_;
+ unless ( $method )
+ {
+ my $type = $context->get( $self, 'TYPE' );
+ if ( defined $type )
+ {
+ my $type = lc $type;
+
+ if ( exists $legal_types{ $type } )
+ {
+ $method = $legal_types{ $type };
+ }
+ else
+ {
+ warn "'$type' is not a legal cell type.\n"
+ if $^W;
+ }
+ }
+ }
+
$method ||= 'write';
my ($row, $col) = map { $context->get($self, $_) } qw(ROW COL);
Sets the width of the column the cell is in. The last setting for a given column
will win out.
-=back 4
+=item * TYPE
+
+This allows you to specify what write_*() method will be used. The default is to
+call write() and let S::WE make the right call. However, you may wish to
+override it. Excel::Template will not do any form of validation on what you
+provide. You are assumed to know what you're doing.
+
+The legal types are:
+
+=over 4
+
+=item * blank
+
+=item * formula
+
+=item * number
+
+=item * string
+
+=item * url
+
+=back
+
+q.v. L<Spreadsheet::WriteExcel> for more info.
-There will be more parameters added, as features are added.
+=back
=head1 CHILDREN
@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,
my $self = shift;
my ($context) = @_;
-UNI_YES my $t = Unicode::String::utf8('');
-UNI_NO my $t = '';
+ my $use_unicode = $context->use_unicode;
+
+ my $t;
+ if ($use_unicode)
+ {
+ require Unicode::String;
+ $t = Unicode::String::utf8('');
+ }
+ else
+ {
+ $t = '';
+ }
for my $tok (@{$self->{STACK}})
{
$val = $val->resolve($context)
if Excel::Template::Factory::is_embedded( $val );
-UNI_YES $t .= Unicode::String::utf8("$val");
-UNI_NO $t .= $val;
+ $t .= $use_unicode
+ ? Unicode::String::utf8("$val")
+ : $val;
}
return $t;
--- /dev/null
+<workbook>
+ <worksheet name="cell_type">
+ <cell type="string">String</cell>
+ <cell type="number">Number</cell>
+ <cell type="blank">Blank</cell>
+ <cell type="url">URL</cell>
+ <cell type="formula">Formula</cell>
+ </worksheet>
+</workbook>
--- /dev/null
+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(
+ filename => 't/015.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_type' )
+Spreadsheet::WriteExcel::Worksheet::new( '' )
+Spreadsheet::WriteExcel::Worksheet::write_string( '0', '0', 'String', '1' )
+Spreadsheet::WriteExcel::Worksheet::write_number( '0', '1', 'Number', '1' )
+Spreadsheet::WriteExcel::Worksheet::write_blank( '0', '2', 'Blank', '1' )
+Spreadsheet::WriteExcel::Worksheet::write_url( '0', '3', 'URL', '1' )
+Spreadsheet::WriteExcel::Worksheet::write_formula( '0', '4', 'Formula', '1' )
+Spreadsheet::WriteExcel::close( '' )
+__END_EXPECTED__
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;