| 1 |
#! perl |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
use Test::More tests => 4; |
| 6 |
|
| 7 |
package POC::Report; |
| 8 |
|
| 9 |
use base qw(Data::Report); |
| 10 |
|
| 11 |
package POC::Report::Html; |
| 12 |
|
| 13 |
use base qw(Data::Report::Plugin::Html); |
| 14 |
|
| 15 |
sub start { |
| 16 |
my $self = shift; |
| 17 |
$self->_argcheck(3); |
| 18 |
$self->{_title1} = shift; |
| 19 |
$self->{_title2} = shift; |
| 20 |
$self->{_title3} = shift; |
| 21 |
$self->SUPER::start; |
| 22 |
} |
| 23 |
|
| 24 |
sub _std_heading { |
| 25 |
my $self = shift; |
| 26 |
$self->_print("<html>\n", |
| 27 |
"<head>\n", |
| 28 |
"<title>", $self->_html($self->{_title1}), "</title>\n", |
| 29 |
'<link rel="stylesheet" href="css/', $self->get_style, '.css">', "\n", |
| 30 |
"</head>\n", |
| 31 |
"<body>\n", |
| 32 |
"<p class=\"title\">", $self->_html($self->{_title1}), "</p>\n", |
| 33 |
"<p class=\"subtitle\">", $self->_html($self->{_title2}), "<br>\n", |
| 34 |
$self->_html($self->{_title3}), "</p>\n"); |
| 35 |
$self->SUPER::_std_heading; |
| 36 |
} |
| 37 |
|
| 38 |
sub _std_stylist { |
| 39 |
my ($rep, $row, $col) = @_; |
| 40 |
|
| 41 |
return { line_after => 1 } |
| 42 |
if $row eq "total" && !$col; |
| 43 |
return; |
| 44 |
} |
| 45 |
|
| 46 |
sub finish { |
| 47 |
my $self = shift; |
| 48 |
$self->_argcheck(0); |
| 49 |
$self->SUPER::finish; |
| 50 |
$self->_print("</body>\n</html>\n"); |
| 51 |
} |
| 52 |
|
| 53 |
package main; |
| 54 |
|
| 55 |
my $rep = POC::Report::->create(type => "html"); |
| 56 |
isa_ok($rep, 'POC::Report::Html'); |
| 57 |
|
| 58 |
$rep->set_layout |
| 59 |
([ { name => "acct", title => "Acct", width => 6 }, |
| 60 |
{ name => "desc", title => "Report", width => 40, align => "|" }, |
| 61 |
{ name => "deb", title => "Debet", width => 10, align => "<" }, |
| 62 |
{ name => "crd", title => "Credit", width => 10, align => ">" }, |
| 63 |
]); |
| 64 |
|
| 65 |
my $out = ""; |
| 66 |
$rep->set_output(\$out); |
| 67 |
$rep->start(qw(Title_One Title_Two Title_Three_Left&Right)); |
| 68 |
|
| 69 |
is($rep->get_stylist, \&POC::Report::Html::_std_stylist, "CB: stylist"); |
| 70 |
is($rep->get_heading, \&POC::Report::Html::_std_heading, "CB: heading"); |
| 71 |
|
| 72 |
$rep->add({ acct => "one", desc => "two", deb => "three", crd => "four", _style => "normal" }); |
| 73 |
$rep->add({ acct => "one", desc => "two", deb => "three", crd => "four", _style => "normal" }); |
| 74 |
$rep->add({ acct => "one", desc => "two", deb => "three", crd => "four", _style => "normal" }); |
| 75 |
$rep->add({ acct => "one", desc => "two", deb => "three", crd => "four", _style => "total" }); |
| 76 |
$rep->finish; |
| 77 |
$rep->close; |
| 78 |
|
| 79 |
my $ref; { undef $/; $ref = <DATA>; } |
| 80 |
$ref =~ s/[\r\n]/\n/g; |
| 81 |
|
| 82 |
is($out, $ref, "contents"); |
| 83 |
|
| 84 |
__DATA__ |
| 85 |
<html> |
| 86 |
<head> |
| 87 |
<title>Title_One</title> |
| 88 |
<link rel="stylesheet" href="css/default.css"> |
| 89 |
</head> |
| 90 |
<body> |
| 91 |
<p class="title">Title_One</p> |
| 92 |
<p class="subtitle">Title_Two<br> |
| 93 |
Title_Three_Left&Right</p> |
| 94 |
<table class="main"> |
| 95 |
<tr class="head"> |
| 96 |
<th align="left" class="h_acct">Acct</th> |
| 97 |
<th align="center" class="h_desc">Report</th> |
| 98 |
<th align="left" class="h_deb">Debet</th> |
| 99 |
<th align="right" class="h_crd">Credit</th> |
| 100 |
</tr> |
| 101 |
<tr class="r_normal"> |
| 102 |
<td align="left" class="c_acct">one</td> |
| 103 |
<td align="center" class="c_desc">two</td> |
| 104 |
<td align="left" class="c_deb">three</td> |
| 105 |
<td align="right" class="c_crd">four</td> |
| 106 |
</tr> |
| 107 |
<tr class="r_normal"> |
| 108 |
<td align="left" class="c_acct">one</td> |
| 109 |
<td align="center" class="c_desc">two</td> |
| 110 |
<td align="left" class="c_deb">three</td> |
| 111 |
<td align="right" class="c_crd">four</td> |
| 112 |
</tr> |
| 113 |
<tr class="r_normal"> |
| 114 |
<td align="left" class="c_acct">one</td> |
| 115 |
<td align="center" class="c_desc">two</td> |
| 116 |
<td align="left" class="c_deb">three</td> |
| 117 |
<td align="right" class="c_crd">four</td> |
| 118 |
</tr> |
| 119 |
<tr class="r_total"> |
| 120 |
<td align="left" class="c_acct">one</td> |
| 121 |
<td align="center" class="c_desc">two</td> |
| 122 |
<td align="left" class="c_deb">three</td> |
| 123 |
<td align="right" class="c_crd">four</td> |
| 124 |
</tr> |
| 125 |
</table> |
| 126 |
</body> |
| 127 |
</html> |