| 1 |
#! perl |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
use Test::More qw(no_plan); |
| 6 |
|
| 7 |
use Data::Report; |
| 8 |
|
| 9 |
my $rep = Data::Report::->create |
| 10 |
(type => "csv", |
| 11 |
layout => [ { name => "acct", title => "Acct", width => 6 }, |
| 12 |
{ name => "desc", title => "Report", width => 40, align => "|" }, |
| 13 |
{ name => "deb", title => "Debet", width => 10, align => "<" }, |
| 14 |
{ name => "crd", title => "Credit", width => 10, align => ">" }, |
| 15 |
], |
| 16 |
); |
| 17 |
|
| 18 |
my $out = ""; |
| 19 |
$rep->set_stylist(sub { |
| 20 |
my ($self, $row, $col) = @_; |
| 21 |
return { ignore => 1 } if $row && $row eq "total" && !$col; |
| 22 |
return; |
| 23 |
}); |
| 24 |
$rep->set_output(\$out); |
| 25 |
$rep->set_separator(":") if $rep->get_type eq "csv"; |
| 26 |
$rep->start; |
| 27 |
$rep->add({ acct => 1234, desc => "two", deb => "three", crd => "four" }); |
| 28 |
$rep->add({ acct => 1235, desc => "two", deb => "three", crd => "four" }); |
| 29 |
$rep->add({ acct => 1236, desc => "two", deb => "three", crd => "four" }); |
| 30 |
$rep->add({ desc => "total", deb => "three", crd => "four", _style => "total" }); |
| 31 |
$rep->finish; |
| 32 |
$rep->close; |
| 33 |
|
| 34 |
my $ref; { undef $/; $ref = <DATA> } |
| 35 |
$ref =~ s/[\r\n]/\n/g; |
| 36 |
$out =~ s/[\r\n]/\n/g; |
| 37 |
is($out, $ref); |
| 38 |
|
| 39 |
__DATA__ |
| 40 |
"Acct":"Report":"Debet":"Credit" |
| 41 |
"1234":"two":"three":"four" |
| 42 |
"1235":"two":"three":"four" |
| 43 |
"1236":"two":"three":"four" |