#! perl use strict; use warnings; use Test::More tests => 2; package POC::Report; use base qw(Data::Report); package POC::Report::Html; use base qw(Data::Report::Plugin::Html); sub _std_stylist { my ($rep, $row, $col) = @_; return unless $col; return { raw_html => 1 } if $col eq "address"; return { ignore => 1 } if $col =~ /^city|zip$/; return; } sub add { my ($self, $data) = @_; $data->{address} = join('
', map { $self->_html($_) } @$data{qw(address city zip)}); $self->SUPER::add($data); } package main; my $rep = POC::Report::->create(type => "html"); isa_ok($rep, 'POC::Report::Html'); $rep->set_layout( [ { name => "id", title => "ID", width => 4 }, { name => "name", title => "Name", width => 20 }, { name => "address", title => "Address", width => 40 }, { name => "city", title => "City", width => 20 }, { name => "zip", title => "Zip", width => 10 }, ] ); my $out = ""; $rep->set_output(\$out); $rep->start(); $rep->add( { id => 1, name => "Rijksmuseum", address => "Museumplein", city => "Amsterdam", zip => "1000 AA", _style => "normal" } ); $rep->add( { id => 2, name => "Kabouterland", address => "Zuid&einde", city => "Exloo", zip => "7889 AA", _style => "normal" } ); $rep->finish; $rep->close; my $ref; { undef $/; $ref = ; } $ref =~ s/[\r\n]/\n/g; is($out, $ref, "contents"); __DATA__
ID Name Address
1 Rijksmuseum Museumplein
Amsterdam
1000 AA
2 Kabouterland Zuid&einde
Exloo
7889 AA