Skip to content

Commit

Permalink
Import of HMBRAND/Text-CSV_XS-0.52 from CPAN.
Browse files Browse the repository at this point in the history
gitpan-cpan-distribution: Text-CSV_XS
gitpan-cpan-version:      0.52
gitpan-cpan-path:         HMBRAND/Text-CSV_XS-0.52.tgz
gitpan-cpan-author:       HMBRAND
gitpan-cpan-maturity:     released
  • Loading branch information
H.Merijn Brand authored and Gitpan committed Oct 22, 2014
1 parent fa70105 commit 958372e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 18 deletions.
34 changes: 21 additions & 13 deletions CSV_XS.pm
Expand Up @@ -30,7 +30,7 @@ use DynaLoader ();
use Carp;

use vars qw( $VERSION @ISA );
$VERSION = "0.51";
$VERSION = "0.52";
@ISA = qw( DynaLoader );

sub PV { 0 }
Expand Down Expand Up @@ -416,15 +416,15 @@ sub column_names
if (@keys == 1 && ref $keys[0] eq "ARRAY") {
@keys = @{$keys[0]};
}
elsif (join "", map { defined $_ ? ref $_ : "UNDEF" } @keys) {
elsif (join "", map { defined $_ ? ref $_ : "" } @keys) {
croak ($self->SetDiag (3001));
}

$self->{_is_bound} && @keys != $self->{_is_bound} and
$self->{_BOUND_COLUMNS} && @keys != @{$self->{_BOUND_COLUMNS}} and
croak ($self->SetDiag (3003));

$self->{_COLUMN_NAMES} = [ @keys ];
@keys;
$self->{_COLUMN_NAMES} = [ map { defined $_ ? $_ : "\cAUNDEF\cA" } @keys ];
@{$self->{_COLUMN_NAMES}};
} # column_names

sub bind_columns
Expand All @@ -445,7 +445,7 @@ sub bind_columns
$self->_set_attr_N ("_is_bound", scalar @refs);
$self->{_BOUND_COLUMNS} = [ @refs ];
@refs;
} # column_names
} # bind_columns

sub getline_hr
{
Expand Down Expand Up @@ -990,6 +990,16 @@ single array_ref, so you can pass C<getline ()>
$csv->column_names ($csv->getline ($io));
C<column_names ()> does B<no> checking on duplicates at all, which might
lead to unwanted results. Undefined entries will be replaced with the
string C<"\cAUNDEF\cA">, so
$csv->column_names (undef, "", "name", "name");
$hr = $csv->getline_hr ($io);
Will set C<$hr->{"\cAUNDEF\cA"}> to the 1st field, C<$hr->{""}> to the
2nd field, and C<$hr->{name}> to the 4th field, discarding the 2rd field.
C<column_names ()> croaks on invalid arguments.
=head2 bind_columns
Expand Down Expand Up @@ -1250,14 +1260,12 @@ internal failure, like failing to store a hash value.
=item More Errors & Warnings
At current, it is hard to tell where or why an error occured (if
at all). New extensions ought to be clear and concise in reporting
what error occurred where and why, and possibly also tell a remedy
to the problem. error_diag is a (very) good start, but there is more
work to be done here.
New extensions ought to be clear and concise in reporting what error
occurred where and why, and possibly also tell a remedy to the problem.
error_diag is a (very) good start, but there is more work to be done here.
Basic calls should croak or warn on illegal parameters. Errors
should be documented.
Basic calls should croak or warn on illegal parameters. Errors should be
documented.
=item eol
Expand Down
5 changes: 5 additions & 0 deletions ChangeLog
@@ -1,3 +1,8 @@
2008-06-28 0.52 - H.Merijn Brand <h.m.brand@xs4all.nl>

* Using undef for hash keys is a bad plan
* Fix, tests, and documentation for column_names ()

2008-06-17 0.51 - H.Merijn Brand <h.m.brand@xs4all.nl>

* Allow UTF8 even without binary => 1
Expand Down
4 changes: 2 additions & 2 deletions META.yml
@@ -1,6 +1,6 @@
--- #YAML:1.0
name: Text-CSV_XS
version: 0.51
version: 0.52
abstract: Comma-Separated Values manipulation routines
license: perl
author:
Expand All @@ -10,7 +10,7 @@ distribution_type: module
provides:
Text::CSV_XS:
file: CSV_XS.pm
version: 0.51
version: 0.52
requires:
perl: 5.005
DynaLoader: 0
Expand Down
19 changes: 16 additions & 3 deletions t/75_hashref.t
Expand Up @@ -4,7 +4,7 @@ use strict;
$^W = 1;

#use Test::More "no_plan";
use Test::More tests => 62;
use Test::More tests => 68;

BEGIN {
use_ok "Text::CSV_XS", ();
Expand Down Expand Up @@ -93,8 +93,8 @@ my $foo;
ok ($csv->bind_columns (@bcr, \$foo), "bind too many columns");
($code, $name, $price, $desc, $foo) = (101 .. 105);
ok ($csv->getline (*FH), "fetch less than expected");
is_deeply ( [ $code, $name, $price, $desc, $foo ],
[ 2, "Drinks", "82.78", "Drinks", 105 ], "unfetched not reset");
is_deeply ([ $code, $name, $price, $desc, $foo ],
[ 2, "Drinks", "82.78", "Drinks", 105 ], "unfetched not reset");

my @foo = (0) x 0x012345;
ok ($csv->bind_columns (\(@foo)), "bind a lot of columns");
Expand All @@ -109,4 +109,17 @@ is ($csv->error_diag () + 0, 3006, "cannot read all fields");

close FH;

open FH, "<_test.csv";

is ($csv->column_names (undef), undef, "reset column headers");
is ($csv->bind_columns (undef), undef, "reset bound columns");
is_deeply ([ $csv->column_names (undef, "", "name", "name") ],
[ "\cAUNDEF\cA", "", "name", "name" ], "undefined column header");
ok ($hr = $csv->getline_hr (*FH), "getline_hr ()");
is (ref $hr, "HASH", "returned a hashref");
is_deeply ($hr, { "\cAUNDEF\cA" => "code", "" => "name", "name" => "description" },
"Discarded 3rd field");

close FH;

unlink "_test.csv";

0 comments on commit 958372e

Please sign in to comment.