| 1 |
#! perl |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
use Test::More qw(no_plan); |
| 6 |
|
| 7 |
package POC::Report; |
| 8 |
|
| 9 |
use base qw(Data::Report); |
| 10 |
|
| 11 |
package POC::Report::Text; |
| 12 |
|
| 13 |
use base qw(Data::Report::Plugin::Text); |
| 14 |
|
| 15 |
sub _std_heading { |
| 16 |
my $self = shift; |
| 17 |
$self->_print("Title line 1\n"); |
| 18 |
$self->_print("Title line 2\n"); |
| 19 |
$self->_print("\n"); |
| 20 |
$self->SUPER::_std_heading; |
| 21 |
} |
| 22 |
|
| 23 |
sub _std_stylist { |
| 24 |
my ($rep, $row, $col) = @_; |
| 25 |
|
| 26 |
if ( $col ) { |
| 27 |
return { line_after => "=" } |
| 28 |
if $row eq "special" && $col =~ /^(deb|crd)$/; |
| 29 |
} |
| 30 |
else { |
| 31 |
return { line_after => 1 } if $row eq "total"; |
| 32 |
} |
| 33 |
return; |
| 34 |
} |
| 35 |
|
| 36 |
package main; |
| 37 |
|
| 38 |
my $rep = POC::Report::->create(type => "text"); |
| 39 |
isa_ok($rep, 'POC::Report::Text'); |
| 40 |
|
| 41 |
$rep->set_layout |
| 42 |
([ { name => "acct", title => "Acct", width => 6 }, |
| 43 |
{ name => "desc", title => "Report", width => 40, align => "|" }, |
| 44 |
{ name => "deb", title => "Debet", width => 10, align => "<" }, |
| 45 |
{ name => "crd", title => "Credit", width => 10, align => ">" }, |
| 46 |
]); |
| 47 |
|
| 48 |
my $out = ""; |
| 49 |
$rep->set_output(\$out); |
| 50 |
$rep->start; |
| 51 |
|
| 52 |
is($rep->get_stylist, \&POC::Report::Text::_std_stylist, "CB: stylist"); |
| 53 |
is($rep->get_heading, \&POC::Report::Text::_std_heading, "CB: heading"); |
| 54 |
|
| 55 |
$rep->add({ acct => "one", desc => "two", deb => "three", crd => "four", _style => "normal" }); |
| 56 |
$rep->add({ acct => "one", desc => "two", deb => "three", crd => "four", _style => "normal" }); |
| 57 |
$rep->add({ acct => "one", desc => "two", deb => "three", crd => "four", _style => "special"}); |
| 58 |
$rep->add({ acct => "one", desc => "two", deb => "three", crd => "four", _style => "total" }); |
| 59 |
$rep->finish; |
| 60 |
$rep->close; |
| 61 |
|
| 62 |
is($rep->{lines}, $= - 11, "linecount"); |
| 63 |
|
| 64 |
my $ref; { undef $/; $ref = <DATA>; } |
| 65 |
$ref =~ s/[\r\n]/\n/g; |
| 66 |
|
| 67 |
is($out, $ref, "contents"); |
| 68 |
|
| 69 |
__DATA__ |
| 70 |
Title line 1 |
| 71 |
Title line 2 |
| 72 |
|
| 73 |
Acct Report Debet Credit |
| 74 |
------------------------------------------------------------------------ |
| 75 |
one two three four |
| 76 |
one two three four |
| 77 |
one two three four |
| 78 |
========== ========== |
| 79 |
one two three four |
| 80 |
------------------------------------------------------------------------ |