| 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(type => "text", stylist => \&my_stylist); |
| 10 |
|
| 11 |
$rep->set_layout |
| 12 |
([ { name => "acct", title => "Acct", width => 6, truncate => 1 }, |
| 13 |
{ name => "desc", title => "Report", width => 40, align => "|" }, |
| 14 |
{ name => "deb", title => "Debet", width => 10, align => "<" }, |
| 15 |
{ name => "crd", title => "Credit", width => 10, align => ">" }, |
| 16 |
]); |
| 17 |
|
| 18 |
my $out = ""; |
| 19 |
$rep->set_output(\$out); |
| 20 |
$rep->set_fields([qw(desc crd deb acct)]); |
| 21 |
$rep->start; |
| 22 |
$rep->add({ acct => "one two", desc => "two", deb => "three", crd => "four", _style => "normal" }); |
| 23 |
$rep->add({ acct => "one", desc => "two", deb => "three", crd => "four", _style => "normal" }); |
| 24 |
$rep->add({ acct => "one", desc => "two", deb => "three", crd => "four", _style => "normal" }); |
| 25 |
$rep->add({ acct => "one", desc => "two", deb => "three", crd => "four", _style => "total" }); |
| 26 |
$rep->finish; |
| 27 |
$rep->close; |
| 28 |
|
| 29 |
my $ref; { undef $/; $ref = <DATA>; } |
| 30 |
$ref =~ s/[\r\n]/\n/g; |
| 31 |
|
| 32 |
is($out, $ref); |
| 33 |
|
| 34 |
sub my_stylist { |
| 35 |
my ($rep, $row, $col) = @_; |
| 36 |
|
| 37 |
unless ( $col ) { |
| 38 |
return { line_after => 1 } if $row eq "total"; |
| 39 |
return; |
| 40 |
} |
| 41 |
return { line_after => 1 } if $col eq "deb"; |
| 42 |
return; |
| 43 |
} |
| 44 |
|
| 45 |
__DATA__ |
| 46 |
Report Credit Debet Acct |
| 47 |
------------------------------------------------------------------------ |
| 48 |
two four three one tw |
| 49 |
---------- |
| 50 |
two four three one |
| 51 |
---------- |
| 52 |
two four three one |
| 53 |
---------- |
| 54 |
two four three one |
| 55 |
---------- |
| 56 |
------------------------------------------------------------------------ |