1 |
package html; |
package html; |
2 |
|
|
3 |
|
use Data::Dump qw/dump/; |
4 |
|
|
5 |
sub table { |
sub table { |
6 |
my $cols = shift; |
my $cols = shift; |
7 |
|
my $th; |
8 |
|
|
9 |
|
if ( $cols < 0 ) { |
10 |
|
$cols = abs($cols); |
11 |
|
$th .= qq|<th>| . shift(@_) . qq|</td>| foreach ( 1 .. $cols ); |
12 |
|
$th .= qq|</tr>\n<tr>|; |
13 |
|
} |
14 |
|
|
15 |
my @td = map { "<td>$_</td>" } @_; |
my @td = map { "<td>$_</td>" } @_; |
16 |
my $html = qq{<table>\n<tr>}; |
my $html = qq{<table>\n<tr>$th}; |
17 |
|
my $row = 0; |
18 |
|
|
19 |
foreach ( 0 .. $#td ) { |
foreach ( 0 .. $#td ) { |
20 |
$html .= $td[$_]; |
$html .= $td[$_]; |
21 |
$html .= qq{</tr>\n<tr>} if $_ % $cols == 1; |
if ( ( $_ + 1 ) % $cols == 0 ) { |
22 |
|
$zebra = $row++ % 2 == 0 ? qq{ style="background: #eee"} : ''; |
23 |
|
$html .= qq{</tr>\n<tr$zebra>}; |
24 |
|
}; |
25 |
} |
} |
26 |
$html .= qq{</tr>\n</table>}; |
$html .= qq{</tr>\n</table>}; |
27 |
} |
} |
28 |
|
|
29 |
|
sub tabs { |
30 |
|
return unless @_; |
31 |
|
my $html = qq{<table border=1>\n<tr>}; |
32 |
|
foreach my $row ( @_ ) { |
33 |
|
$row =~ s{\t}{</td><td>}g; |
34 |
|
$html .= qq|<tr><td>$row</td><tr>\n|; |
35 |
|
} |
36 |
|
$html .= qq|</table>|; |
37 |
|
return $html; |
38 |
|
} |
39 |
|
|
40 |
|
|
41 |
|
sub tt { |
42 |
|
qq|<tt>| . join(' ', @_) . qq|</tt>| if @_; |
43 |
|
} |
44 |
|
|
45 |
|
sub select { |
46 |
|
my $name = shift; |
47 |
|
my $selected_option = shift; |
48 |
|
unshift @_, '' unless $selected_option; |
49 |
|
return join("\n" |
50 |
|
, qq|<select type=select name=$name>| |
51 |
|
, join("\n", map { my $selected = $_ eq $selected_option ? 'selected' : ''; qq|<option name=$_ $selected>$_</option>| } @_ ) |
52 |
|
, qq|</select>| |
53 |
|
, qq|</form>| |
54 |
|
); |
55 |
|
} |
56 |
|
|
57 |
|
sub pre { |
58 |
|
qq|<pre>| . join(' ', @_) . qq|</pre>| if @_; |
59 |
|
} |
60 |
|
|
61 |
|
sub pre_dump { |
62 |
|
my $data = shift; |
63 |
|
my $dump = dump( $data ); |
64 |
|
$dump =~ s{"([^"]+)"(\s*=>)}{$1 $2}gs; |
65 |
|
$dump =~ s{"([^"]*)"}{"<b>$1</b>"}gs; |
66 |
|
qq|<pre>$dump</pre>|; |
67 |
|
} |
68 |
|
|
69 |
warn "loaded"; |
warn "loaded"; |
70 |
|
|
71 |
1; |
1; |