Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add Supply:U support for csv(out => …)
  • Loading branch information
H.Merijn Brand - Tux committed Jan 13, 2016
1 parent 170ec9b commit 9fb32f0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
7 changes: 5 additions & 2 deletions lib/Text/CSV.pm
Expand Up @@ -1639,6 +1639,9 @@ class Text::CSV {
when Channel:U {
$out = Channel.new;
}
when Supply:U {
$out = Supplier::Preserving.new;
}
when Array:U | Hash:U | Capture:U |
Supplier:D | Callable:D | Channel:D {
# No specific action required here
Expand Down Expand Up @@ -1718,9 +1721,9 @@ class Text::CSV {
self.eol ($eol);

given $out {
when Supplier {
when Supplier::Preserving {
$out.done;
return $out;
return $out.Supply;
}
when Channel {
$out.close;
Expand Down
13 changes: 10 additions & 3 deletions lib/Text/CSV.pod
Expand Up @@ -1697,12 +1697,19 @@ Writes the data rows into the existing Channel.

=item Supplier:D

my $ch = Supplier.new;
$ch.Supply.tap (-> \row { @d.push: row; });
csv(in => $in, out => $ch, :!meta);
my $sup = Supplier.new;
$sup.Supply.tap (-> \row { @d.push: row; });
csv(in => $in, out => $sup, :!meta);

Writes the data rows into the Supplier.

=item Supply:U

my $sup = csv(in => $in, out => Supply, :!meta);
$ch.tap (-> \row { @d.push: row; });

Writes the data rows into a new Supply.

=back

=head3 encoding
Expand Down
9 changes: 9 additions & 0 deletions t/90_csv.t
Expand Up @@ -211,6 +211,15 @@ for in () -> $in {
is-deeply ([@d], $full-aoa, "csv => Supplier { s-in ($in) }");
}

$io-in.seek (0, SeekFromBeginning);
for in () -> $in {
ok (my $csv = Text::CSV.new, "new for Supply");
my @d;
my $ch = $csv.csv (in => $in, out => Supply, :!meta);
$ch.tap (-> \row { @d.push: row; });
is-deeply ([@d], $full-aoa, "csv => Supplier { s-in ($in) }");
}

# Additional attributes like headers and fragment

$io-in.seek (0, SeekFromBeginning);
Expand Down

0 comments on commit 9fb32f0

Please sign in to comment.