File: 09poc05.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 (186 lines) | stat: -rw-r--r-- 4,834 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#! perl

use strict;
use warnings;
use Test::More tests => 4;

package POC::Report;

use base qw(Data::Report);

package POC::Report::Html;

use base qw(Data::Report::Plugin::Html);

sub start {
    my $self = shift;
    $self->_argcheck(3);
    $self->{_title1} = shift;
    $self->{_title2} = shift;
    $self->{_title3} = shift;
    $self->SUPER::start;
}

sub _top_heading {
    my $self = shift;
    $self->_print("<html>\n",
		  "<head>\n",
		  "<title>", $self->_html($self->{_title1}), "</title>\n",
		  '<link rel="stylesheet" href="css/', $self->get_style, '.css">', "\n",
		  "</head>\n",
		  "<body>\n",
          "<form method=\"post\" action=\"#\">\n",
		  "<p class=\"title\">", $self->_html($self->{_title1}), "</p>\n",
		  "<p class=\"subtitle\">", $self->_html($self->{_title2}), "<br>\n",
		  $self->_html($self->{_title3}), "</p>\n");
}

sub _std_stylist {
    my ($rep, $row, $col) = @_;

    # No style mods.
    return;
}

sub finish {
    my $self = shift;
    $self->_argcheck(0);
    $self->SUPER::finish;
    $self->_print("</form>\n</body>\n</html>\n");
}

package main;

my $rep = POC::Report::->create(type => "html", stylist => \&my_stylist);
isa_ok($rep, 'POC::Report::Html');

$rep->set_layout(
    [
        {
            name     => "check",
            title    => "Check",
            width    => 5,
            align    => "|",
        },
        { name => "acct", title => "Acct",   width => 6 },
        { name => "desc", title => "Report", width => 40, align => "|" },
        { name => "deb",  title => "Debet",  width => 10, align => "<" },
        { name => "crd",  title => "Credit", width => 10, align => ">" },
    ]
);

my $out = "";
$rep->set_output(\$out);
$rep->start(qw(Title_One Title_Two Title_Three_Left&Right));

is($rep->get_stylist, \&main::my_stylist, "CB: stylist");
is($rep->get_topheading, \&POC::Report::Html::_top_heading, "CB: heading");

$rep->add(
    {
        check  => "<input type=\"checkbox\" name=\"checks\" value=\"first\">",
        acct   => "one",
        desc   => "two",
        deb    => "three",
        crd    => "four",
        _style => "normal"
    }
);
$rep->add(
    {
        check  => "<input type=\"checkbox\" name=\"checks\" value=\"second\">",
        acct   => "one",
        desc   => "two",
        deb    => "three",
        crd    => "four",
        _style => "normal"
    }
);
$rep->add(
    {
        check  => "<input type=\"checkbox\" name=\"checks\" value=\"third\">",
        acct   => "one",
        desc   => "two",
        deb    => "three",
        crd    => "four",
        _style => "normal"
    }
);
$rep->add(
    {
        check  => "<input type=\"checkbox\" name=\"checks\" value=\"total\">",
        acct   => "one",
        desc   => "two",
        deb    => "three",
        crd    => "four",
        _style => "total"
    }
);
$rep->finish;
$rep->close;

my $ref; { undef $/; $ref = <DATA>; }
$ref =~ s/[\r\n]/\n/g;

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

sub my_stylist {
    my ($rep, $row, $col) = @_;

    # Enable raw HTML contents for the 'check' column.
    return { raw_html => 1 }
      if $col && $col eq "check";
    return;
}

__DATA__
<html>
<head>
<title>Title_One</title>
<link rel="stylesheet" href="css/default.css">
</head>
<body>
<form method="post" action="#">
<p class="title">Title_One</p>
<p class="subtitle">Title_Two<br>
Title_Three_Left&amp;Right</p>
<table class="main">
<tr class="head">
<th align="center" class="h_check">Check</th>
<th align="left" class="h_acct">Acct</th>
<th align="center" class="h_desc">Report</th>
<th align="left" class="h_deb">Debet</th>
<th align="right" class="h_crd">Credit</th>
</tr>
<tr class="r_normal">
<td align="center" class="c_check"><input type="checkbox" name="checks" value="first"></td>
<td align="left" class="c_acct">one</td>
<td align="center" class="c_desc">two</td>
<td align="left" class="c_deb">three</td>
<td align="right" class="c_crd">four</td>
</tr>
<tr class="r_normal">
<td align="center" class="c_check"><input type="checkbox" name="checks" value="second"></td>
<td align="left" class="c_acct">one</td>
<td align="center" class="c_desc">two</td>
<td align="left" class="c_deb">three</td>
<td align="right" class="c_crd">four</td>
</tr>
<tr class="r_normal">
<td align="center" class="c_check"><input type="checkbox" name="checks" value="third"></td>
<td align="left" class="c_acct">one</td>
<td align="center" class="c_desc">two</td>
<td align="left" class="c_deb">three</td>
<td align="right" class="c_crd">four</td>
</tr>
<tr class="r_total">
<td align="center" class="c_check"><input type="checkbox" name="checks" value="total"></td>
<td align="left" class="c_acct">one</td>
<td align="center" class="c_desc">two</td>
<td align="left" class="c_deb">three</td>
<td align="right" class="c_crd">four</td>
</tr>
</table>
</form>
</body>
</html>