| 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 _top_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 |
"<form method=\"post\" action=\"#\">\n", |
| 33 |
"<p class=\"title\">", $self->_html($self->{_title1}), "</p>\n", |
| 34 |
"<p class=\"subtitle\">", $self->_html($self->{_title2}), "<br>\n", |
| 35 |
$self->_html($self->{_title3}), "</p>\n"); |
| 36 |
} |
| 37 |
|
| 38 |
sub _std_stylist { |
| 39 |
my ($rep, $row, $col) = @_; |
| 40 |
|
| 41 |
# No style mods. |
| 42 |
return; |
| 43 |
} |
| 44 |
|
| 45 |
sub finish { |
| 46 |
my $self = shift; |
| 47 |
$self->_argcheck(0); |
| 48 |
$self->SUPER::finish; |
| 49 |
$self->_print("</form>\n</body>\n</html>\n"); |
| 50 |
} |
| 51 |
|
| 52 |
package main; |
| 53 |
|
| 54 |
my $rep = POC::Report::->create(type => "html", stylist => \&my_stylist); |
| 55 |
isa_ok($rep, 'POC::Report::Html'); |
| 56 |
|
| 57 |
$rep->set_layout( |
| 58 |
[ |
| 59 |
{ |
| 60 |
name => "check", |
| 61 |
title => "Check", |
| 62 |
width => 5, |
| 63 |
align => "|", |
| 64 |
}, |
| 65 |
{ name => "acct", title => "Acct", width => 6 }, |
| 66 |
{ name => "desc", title => "Report", width => 40, align => "|" }, |
| 67 |
{ name => "deb", title => "Debet", width => 10, align => "<" }, |
| 68 |
{ name => "crd", title => "Credit", width => 10, align => ">" }, |
| 69 |
] |
| 70 |
); |
| 71 |
|
| 72 |
my $out = ""; |
| 73 |
$rep->set_output(\$out); |
| 74 |
$rep->start(qw(Title_One Title_Two Title_Three_Left&Right)); |
| 75 |
|
| 76 |
is($rep->get_stylist, \&main::my_stylist, "CB: stylist"); |
| 77 |
is($rep->get_topheading, \&POC::Report::Html::_top_heading, "CB: heading"); |
| 78 |
|
| 79 |
$rep->add( |
| 80 |
{ |
| 81 |
check => "<input type=\"checkbox\" name=\"checks\" value=\"first\">", |
| 82 |
acct => "one", |
| 83 |
desc => "two", |
| 84 |
deb => "three", |
| 85 |
crd => "four", |
| 86 |
_style => "normal" |
| 87 |
} |
| 88 |
); |
| 89 |
$rep->add( |
| 90 |
{ |
| 91 |
check => "<input type=\"checkbox\" name=\"checks\" value=\"second\">", |
| 92 |
acct => "one", |
| 93 |
desc => "two", |
| 94 |
deb => "three", |
| 95 |
crd => "four", |
| 96 |
_style => "normal" |
| 97 |
} |
| 98 |
); |
| 99 |
$rep->add( |
| 100 |
{ |
| 101 |
check => "<input type=\"checkbox\" name=\"checks\" value=\"third\">", |
| 102 |
acct => "one", |
| 103 |
desc => "two", |
| 104 |
deb => "three", |
| 105 |
crd => "four", |
| 106 |
_style => "normal" |
| 107 |
} |
| 108 |
); |
| 109 |
$rep->add( |
| 110 |
{ |
| 111 |
check => "<input type=\"checkbox\" name=\"checks\" value=\"total\">", |
| 112 |
acct => "one", |
| 113 |
desc => "two", |
| 114 |
deb => "three", |
| 115 |
crd => "four", |
| 116 |
_style => "total" |
| 117 |
} |
| 118 |
); |
| 119 |
$rep->finish; |
| 120 |
$rep->close; |
| 121 |
|
| 122 |
my $ref; { undef $/; $ref = <DATA>; } |
| 123 |
$ref =~ s/[\r\n]/\n/g; |
| 124 |
|
| 125 |
is($out, $ref, "contents"); |
| 126 |
|
| 127 |
sub my_stylist { |
| 128 |
my ($rep, $row, $col) = @_; |
| 129 |
|
| 130 |
# Enable raw HTML contents for the 'check' column. |
| 131 |
return { raw_html => 1 } |
| 132 |
if $col && $col eq "check"; |
| 133 |
return; |
| 134 |
} |
| 135 |
|
| 136 |
__DATA__ |
| 137 |
<html> |
| 138 |
<head> |
| 139 |
<title>Title_One</title> |
| 140 |
<link rel="stylesheet" href="css/default.css"> |
| 141 |
</head> |
| 142 |
<body> |
| 143 |
<form method="post" action="#"> |
| 144 |
<p class="title">Title_One</p> |
| 145 |
<p class="subtitle">Title_Two<br> |
| 146 |
Title_Three_Left&Right</p> |
| 147 |
<table class="main"> |
| 148 |
<tr class="head"> |
| 149 |
<th align="center" class="h_check">Check</th> |
| 150 |
<th align="left" class="h_acct">Acct</th> |
| 151 |
<th align="center" class="h_desc">Report</th> |
| 152 |
<th align="left" class="h_deb">Debet</th> |
| 153 |
<th align="right" class="h_crd">Credit</th> |
| 154 |
</tr> |
| 155 |
<tr class="r_normal"> |
| 156 |
<td align="center" class="c_check"><input type="checkbox" name="checks" value="first"></td> |
| 157 |
<td align="left" class="c_acct">one</td> |
| 158 |
<td align="center" class="c_desc">two</td> |
| 159 |
<td align="left" class="c_deb">three</td> |
| 160 |
<td align="right" class="c_crd">four</td> |
| 161 |
</tr> |
| 162 |
<tr class="r_normal"> |
| 163 |
<td align="center" class="c_check"><input type="checkbox" name="checks" value="second"></td> |
| 164 |
<td align="left" class="c_acct">one</td> |
| 165 |
<td align="center" class="c_desc">two</td> |
| 166 |
<td align="left" class="c_deb">three</td> |
| 167 |
<td align="right" class="c_crd">four</td> |
| 168 |
</tr> |
| 169 |
<tr class="r_normal"> |
| 170 |
<td align="center" class="c_check"><input type="checkbox" name="checks" value="third"></td> |
| 171 |
<td align="left" class="c_acct">one</td> |
| 172 |
<td align="center" class="c_desc">two</td> |
| 173 |
<td align="left" class="c_deb">three</td> |
| 174 |
<td align="right" class="c_crd">four</td> |
| 175 |
</tr> |
| 176 |
<tr class="r_total"> |
| 177 |
<td align="center" class="c_check"><input type="checkbox" name="checks" value="total"></td> |
| 178 |
<td align="left" class="c_acct">one</td> |
| 179 |
<td align="center" class="c_desc">two</td> |
| 180 |
<td align="left" class="c_deb">three</td> |
| 181 |
<td align="right" class="c_crd">four</td> |
| 182 |
</tr> |
| 183 |
</table> |
| 184 |
</form> |
| 185 |
</body> |
| 186 |
</html> |