Text-CSV

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

    - Fixed a case where csv function is called as a method (GH#46)

2.01  2021-06-19
    - Imported tests/fixes from Text::CSV_XS 1.46
    - Updated XS_Version to 1.46, and if an older version
      of Text::CSV_XS is installed, make sure to update it
      (GH#49, mohawk2++)

2.00  2019-05-11
    - Imported tests/fixes from Text::CSV_XS 1.39
      - Fix strict on streaming EOF
    - Fixed to update (cached) eol_len correctly

1.99  2019-01-02
    - Fixed a number of tests to skip for older perls

1.98  2019-01-02
    - Imported tests/fixes from Text::CSV_XS 1.38
      - Added munge as alias for munge_column_names
      - Added support for key-value pair and combined keys

lib/Text/CSV.pm  view on Meta::CPAN

 csv (in => $_, out => \%hash, key => "id") for sort glob "foo-[0-9]*.csv";

 my @list; # List of arrays
 csv (in => $_, out => \@list)              for sort glob "foo-[0-9]*.csv";

 my @list; # List of hashes
 csv (in => $_, out => \@list, bom => 1)    for sort glob "foo-[0-9]*.csv";

=head4 Streaming

If B<both> C<in> and C<out> are files, file handles or globs,  streaming is
enforced by injecting an C<after_parse> callback  that immediately uses the
L<C<say ()>|/say> method of the same instance to output the result and then
rejects the record.

If a C<after_parse> was already passed as attribute,  that will be included
in the injected call. If C<on_in> was passed and C<after_parse> was not, it
will be used instead. If both were passed, C<on_in> is ignored.

The EOL of the first record of the C<in> source is consistently used as EOL
for all records in the C<out> destination.

lib/Text/CSV_PP.pm  view on Meta::CPAN

            $cboi = undef;
        }
        if ($cbai) {
            my $cb = $cbai;
            $cbai = sub { $cb->(@_); $_[0]->say($fho, $_[1]); 0 };
        }
        else {
            $cbai = sub { $_[0]->say($fho, $_[1]); 0 };
        }

        # Put all callbacks back in place for streaming behavior
        $attr{'callbacks'}{'after_parse'} = $cbai; $cbai = undef;
        $attr{'callbacks'}{'before_out'}  = $cbbo; $cbbo = undef;
        $attr{'callbacks'}{'on_in'}       = $cboi; $cboi = undef;
        $attr{'callbacks'}{'on_error'}    = $cboe; $cboe = undef;
        $out                              = undef;
        $sink                             = 1;
    }

    if ($out) {
        if (ref $out and ("ARRAY" eq ref $out or "HASH" eq ref $out)) {

lib/Text/CSV_PP.pm  view on Meta::CPAN

 csv (in => $_, out => \%hash, key => "id") for sort glob "foo-[0-9]*.csv";

 my @list; # List of arrays
 csv (in => $_, out => \@list)              for sort glob "foo-[0-9]*.csv";

 my @list; # List of hashes
 csv (in => $_, out => \@list, bom => 1)    for sort glob "foo-[0-9]*.csv";

=head4 Streaming

If B<both> C<in> and C<out> are files, file handles or globs,  streaming is
enforced by injecting an C<after_parse> callback  that immediately uses the
L<C<say ()>|/say> method of the same instance to output the result and then
rejects the record.

If a C<after_parse> was already passed as attribute,  that will be included
in the injected call. If C<on_in> was passed and C<after_parse> was not, it
will be used instead. If both were passed, C<on_in> is ignored.

The EOL of the first record of the C<in> source is consistently used as EOL
for all records in the C<out> destination.

t/92_stream.t  view on Meta::CPAN

	    callbacks => {
	      after_parse  => sub {
		warn ++$I, "\n";
		$co->print ($fho, $_[1]);
		},
	      },
	    );
	}
    close $tfno;
    chomp @W;
    is ("@W", "1 1 2 2 3 3", "Old-fashioned streaming");
    }

# Basic straight-forward streaming, no filters/modifiers
unlink $tfno if -e $tfno;
csv (in => $tfni, out => $tfno, quote_space => 0);
ok (-s $tfno, "FILE -> FILE");
is_deeply (csv (in => $tfno), $aoa, "Data is equal");

unlink $tfno if -e $tfno;
open my $fho, ">", $tfno;
csv (in => $tfni, out => $fho,  quote_space => 0);
close   $fho;
ok (-s $tfno, "FILE -> FH");

t/92_stream.t  view on Meta::CPAN

csv (
    in          => $tfni,
    out         => $tfno,
    quote_space => 0,
    after_parse => sub { $_[1][1] .= "X" },
    );
ok (-s $tfno, "With after_parse");
my @new = map { my @x = @$_; $x[1] .= "X"; \@x } @$aoa;
is_deeply (csv (in => $tfno), \@new, "Data is equal");

# Prove streaming behavior
my $io = "";
unlink $tfno if -e $tfno;
csv (
    in        => $tfni,
    out       => $tfno,
    on_in     => sub { $io .= "I" },
    callbacks => { before_print => sub { $io .= "O" }},
    );
ok (-s $tfno, "FILE -> FILE");
is_deeply (csv (in => $tfno), $aoa, "Data is equal");



( run in 0.271 second using v1.01-cache-2.11-cpan-4d50c553e7e )