/usr/share/perl5/Spreadsheet/Wright/CSV.pm is in libspreadsheet-wright-perl 0.105-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | package Spreadsheet::Wright::CSV;
use 5.010;
use strict;
use warnings;
no warnings qw( uninitialized numeric );
BEGIN {
$Spreadsheet::Wright::CSV::VERSION = '0.105';
$Spreadsheet::Wright::CSV::AUTHORITY = 'cpan:TOBYINK';
}
use Carp;
use Encode;
use Text::CSV;
use parent qw(Spreadsheet::Wright);
sub new
{
my ($class, %args) = @_;
my $self = bless {}, $class;
$self->{'_FILENAME'} = $args{'file'} // $args{'filename'}
or croak "Need filename";
$args{'csv_options'}{'eol'} //= "\r\n";
$args{'csv_options'}{'sep_char'} //= ",";
$self->{'_CSV_OPTIONS'} = $args{'csv_options'};
return $self;
}
sub _prepare
{
my $self = shift;
$self->{'_CSV_OBJ'} //=Text::CSV->new($self->{'_CSV_OPTIONS'});
return $self;
}
sub close
{
my $self=shift;
return if $self->{'_CLOSED'};
$self->{'_FH'}->close if $self->{'_FH'};
$self->{'_CLOSED'}=1;
return $self;
}
sub _add_prepared_row
{
my $self = shift;
my @texts;
foreach (@_)
{
my $content = $_->{'content'};
$content = sprintf($content, $_->{'sprintf'})
if $_->{'sprintf'};
# Hide non-ASCII characters from Unicode-unaware Text::CSV.
$content =~ s/([^\x20-\x7e]|[\r\&\n\t])/sprintf('&#%d;', ord($1))/esg;
push @texts, $content;
}
my $string;
$self->{'_CSV_OBJ'}->combine(@texts)
or croak "csv_combine failed at ".$self->{'_CSV_OBJ'}->error_input();
$string = $self->{'_CSV_OBJ'}->string();
# Restore non-ASCII characters.
$string =~ s/&#(\d+);/chr($1)/esg;
$string = Encode::decode('utf8',$string) unless Encode::is_utf8($string);
$string = Encode::encode(($self->{'_ENCODING'}//'utf8'), $string);
# Output to file.
$self->{'_FH'}->print($string);
return $self;
}
1;
|