File: 03csv06.t

package info (click to toggle)
libdata-report-perl 1.001-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 220 kB
  • sloc: perl: 1,972; makefile: 2
file content (44 lines) | stat: -rw-r--r-- 1,254 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#! perl

use strict;
use warnings;
use Test::More qw(no_plan);

use Data::Report;

my $rep = Data::Report::->create
  (type => "csv",
   layout => [ { name => "acct", title => "Acct",   width => 6  },
	       { name => "desc", title => "Report", width => 40, align => "|" },
	       { name => "deb",  title => "Debet",  width => 10, align => "<" },
	       { name => "crd",  title => "Credit", width => 10, align => ">" },
	     ],
  );

my $out = "";
$rep->set_stylist(sub {
    my ($self, $row, $col) = @_;
    return { ignore => 1 } if $row && $row eq "total" && !$col;
    return { ignore => 1 } if $col eq "deb";
    return;
});
$rep->set_output(\$out);
$rep->set_separator(":") if $rep->get_type eq "csv";
$rep->start;
$rep->add({ acct => 1234, desc => "two", deb => "three", crd => "four" });
$rep->add({ acct => 1235, desc => "two", deb => "three", crd => "four" });
$rep->add({ acct => 1236, desc => "two", deb => "three", crd => "four" });
$rep->add({ desc => "total", deb => "three", crd => "four", _style => "total" });
$rep->finish;
$rep->close;

my $ref; { undef $/; $ref = <DATA> }
$ref =~ s/[\r\n]/\n/g;
$out =~ s/[\r\n]/\n/g;
is($out, $ref);

__DATA__
"Acct":"Report":"Credit"
"1234":"two":"four"
"1235":"two":"four"
"1236":"two":"four"