| 1 |
#! perl |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
use Test::More tests => 2; |
| 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 _std_stylist { |
| 16 |
my ($rep, $row, $col) = @_; |
| 17 |
|
| 18 |
return unless $col; |
| 19 |
|
| 20 |
return { raw_html => 1 } |
| 21 |
if $col eq "address"; |
| 22 |
return { ignore => 1 } |
| 23 |
if $col =~ /^city|zip$/; |
| 24 |
|
| 25 |
return; |
| 26 |
} |
| 27 |
|
| 28 |
sub add { |
| 29 |
my ($self, $data) = @_; |
| 30 |
|
| 31 |
$data->{address} |
| 32 |
= join('<br/>', map { $self->_html($_) } @$data{qw(address city zip)}); |
| 33 |
|
| 34 |
$self->SUPER::add($data); |
| 35 |
} |
| 36 |
|
| 37 |
package main; |
| 38 |
|
| 39 |
my $rep = POC::Report::->create(type => "html"); |
| 40 |
isa_ok($rep, 'POC::Report::Html'); |
| 41 |
|
| 42 |
$rep->set_layout( |
| 43 |
[ |
| 44 |
{ name => "id", title => "ID", width => 4 }, |
| 45 |
{ name => "name", title => "Name", width => 20 }, |
| 46 |
{ name => "address", title => "Address", width => 40 }, |
| 47 |
{ name => "city", title => "City", width => 20 }, |
| 48 |
{ name => "zip", title => "Zip", width => 10 }, |
| 49 |
] |
| 50 |
); |
| 51 |
|
| 52 |
my $out = ""; |
| 53 |
$rep->set_output(\$out); |
| 54 |
$rep->start(); |
| 55 |
|
| 56 |
$rep->add( |
| 57 |
{ |
| 58 |
id => 1, |
| 59 |
name => "Rijksmuseum", |
| 60 |
address => "Museumplein", |
| 61 |
city => "Amsterdam", |
| 62 |
zip => "1000 AA", |
| 63 |
_style => "normal" |
| 64 |
} |
| 65 |
); |
| 66 |
|
| 67 |
$rep->add( |
| 68 |
{ |
| 69 |
id => 2, |
| 70 |
name => "Kabouterland", |
| 71 |
address => "Zuid&einde", |
| 72 |
city => "Exloo", |
| 73 |
zip => "7889 AA", |
| 74 |
_style => "normal" |
| 75 |
} |
| 76 |
); |
| 77 |
|
| 78 |
|
| 79 |
$rep->finish; |
| 80 |
$rep->close; |
| 81 |
|
| 82 |
my $ref; { undef $/; $ref = <DATA>; } |
| 83 |
$ref =~ s/[\r\n]/\n/g; |
| 84 |
|
| 85 |
is($out, $ref, "contents"); |
| 86 |
|
| 87 |
__DATA__ |
| 88 |
<table class="main"> |
| 89 |
<tr class="head"> |
| 90 |
<th align="left" class="h_id">ID</th> |
| 91 |
<th align="left" class="h_name">Name</th> |
| 92 |
<th align="left" class="h_address">Address</th> |
| 93 |
</tr> |
| 94 |
<tr class="r_normal"> |
| 95 |
<td align="left" class="c_id">1</td> |
| 96 |
<td align="left" class="c_name">Rijksmuseum</td> |
| 97 |
<td align="left" class="c_address">Museumplein<br/>Amsterdam<br/>1000 AA</td> |
| 98 |
</tr> |
| 99 |
<tr class="r_normal"> |
| 100 |
<td align="left" class="c_id">2</td> |
| 101 |
<td align="left" class="c_name">Kabouterland</td> |
| 102 |
<td align="left" class="c_address">Zuid&einde<br/>Exloo<br/>7889 AA</td> |
| 103 |
</tr> |
| 104 |
</table> |