File: 09poc06.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 (104 lines) | stat: -rw-r--r-- 2,177 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#! 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('<br/>', 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 = <DATA>; }
$ref =~ s/[\r\n]/\n/g;

is($out, $ref, "contents");

__DATA__
<table class="main">
<tr class="head">
<th align="left" class="h_id">ID</th>
<th align="left" class="h_name">Name</th>
<th align="left" class="h_address">Address</th>
</tr>
<tr class="r_normal">
<td align="left" class="c_id">1</td>
<td align="left" class="c_name">Rijksmuseum</td>
<td align="left" class="c_address">Museumplein<br/>Amsterdam<br/>1000 AA</td>
</tr>
<tr class="r_normal">
<td align="left" class="c_id">2</td>
<td align="left" class="c_name">Kabouterland</td>
<td align="left" class="c_address">Zuid&amp;einde<br/>Exloo<br/>7889 AA</td>
</tr>
</table>