| 1 | package HTML::Auto; | ||||||||||
| 2 | |||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 3 | ▶ | use Template; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 3 | ▶ | use HTML::Auto::Templates; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 3 | ▶ | use Data::Dumper; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 3 | require Exporter; | |||||||||
| 11 | 3 | our @ISA = qw(Exporter); | |||||||||
| 12 | 3 | our @EXPORT_OK = qw(matrix h v); | |||||||||
| 13 | |||||||||||
| 14 | =encoding utf-8 | ||||||||||
| 15 | |||||||||||
| 16 | =head1 NAME | ||||||||||
| 17 | |||||||||||
| 18 | HTML::Auto - automatic write HTML for common elements | ||||||||||
| 19 | |||||||||||
| 20 | =head1 VERSION | ||||||||||
| 21 | |||||||||||
| 22 | Version 0.07 | ||||||||||
| 23 | |||||||||||
| 24 | =cut | ||||||||||
| 25 | |||||||||||
| 26 | 3 | our $VERSION = '0.07'; | |||||||||
| 27 | |||||||||||
| 28 | |||||||||||
| 29 | =head1 SYNOPSIS | ||||||||||
| 30 | |||||||||||
| 31 | Simple example: | ||||||||||
| 32 | |||||||||||
| 33 | use HTML::Auto qw/matrix h v/; | ||||||||||
| 34 | |||||||||||
| 35 | my @cols = qw/c1 c2 c3 c4 c5/; | ||||||||||
| 36 | my @lines = qw/l1 l2 l3 l4 l5/; | ||||||||||
| 37 | my $data = | ||||||||||
| 38 | [ [1,2,3,4,5], | ||||||||||
| 39 | [6,7,8,9,0], | ||||||||||
| 40 | [1,1,1,1,1], | ||||||||||
| 41 | [2,2,2,2,2], | ||||||||||
| 42 | [3,3,3,3,3] ]; | ||||||||||
| 43 | |||||||||||
| 44 | my $m = matrix(\@cols,\@lines,$data); | ||||||||||
| 45 | |||||||||||
| 46 | print v( | ||||||||||
| 47 | h($m,$m,$m), | ||||||||||
| 48 | h($m,$m), | ||||||||||
| 49 | ); | ||||||||||
| 50 | |||||||||||
| 51 | Using attributes: | ||||||||||
| 52 | |||||||||||
| 53 | use HTML::Auto qw/matrix h v/; | ||||||||||
| 54 | |||||||||||
| 55 | my @cols = qw/c1 c2/; | ||||||||||
| 56 | my @lines = qw/l1 l2/; | ||||||||||
| 57 | my $data = | ||||||||||
| 58 | [ | ||||||||||
| 59 | [ | ||||||||||
| 60 | {v => 1, a => { style => 'background: green'}}, | ||||||||||
| 61 | 2 | ||||||||||
| 62 | ], | ||||||||||
| 63 | [ | ||||||||||
| 64 | {v => 3, a => {class => 'foo'}}, | ||||||||||
| 65 | {v => 4, a => {style => 'color: red'}} | ||||||||||
| 66 | ] | ||||||||||
| 67 | ]; | ||||||||||
| 68 | |||||||||||
| 69 | my $m = matrix(\@cols,\@lines,$data); | ||||||||||
| 70 | |||||||||||
| 71 | print v( | ||||||||||
| 72 | h($m) | ||||||||||
| 73 | ); | ||||||||||
| 74 | |||||||||||
| 75 | With mouse-over span: | ||||||||||
| 76 | |||||||||||
| 77 | use HTML::Auto qw/matrix h v/; | ||||||||||
| 78 | |||||||||||
| 79 | my @cols = qw/c1 c2/; | ||||||||||
| 80 | my @lines = qw/l1 l2/; | ||||||||||
| 81 | my $data = | ||||||||||
| 82 | [[1,2], | ||||||||||
| 83 | [3, | ||||||||||
| 84 | { v=> 4, | ||||||||||
| 85 | more_info => "This is a pop-up!" | ||||||||||
| 86 | }] | ||||||||||
| 87 | ]; | ||||||||||
| 88 | |||||||||||
| 89 | |||||||||||
| 90 | my $m = matrix(\@cols,\@lines,$data); | ||||||||||
| 91 | |||||||||||
| 92 | print v( | ||||||||||
| 93 | h($m) | ||||||||||
| 94 | ); | ||||||||||
| 95 | |||||||||||
| 96 | Passing additional CSS: | ||||||||||
| 97 | |||||||||||
| 98 | use HTML::Auto qw/matrix h v/; | ||||||||||
| 99 | |||||||||||
| 100 | my @cols = qw/c1 c2/; | ||||||||||
| 101 | my @lines = qw/l1 l2/; | ||||||||||
| 102 | my $data = | ||||||||||
| 103 | [ | ||||||||||
| 104 | [ | ||||||||||
| 105 | {v => 1, a => { class => 'warn'}}, | ||||||||||
| 106 | 2 | ||||||||||
| 107 | ], | ||||||||||
| 108 | [3,4] | ||||||||||
| 109 | ]; | ||||||||||
| 110 | |||||||||||
| 111 | my $options = { css => '.warn { background-color: yellow !important; }' }; | ||||||||||
| 112 | |||||||||||
| 113 | my $m = matrix(\@cols,\@lines,$data,$options); | ||||||||||
| 114 | |||||||||||
| 115 | print v( | ||||||||||
| 116 | h($m) | ||||||||||
| 117 | ); | ||||||||||
| 118 | |||||||||||
| 119 | |||||||||||
| 120 | |||||||||||
| 121 | =head1 FUNCTIONS | ||||||||||
| 122 | |||||||||||
| 123 | =head2 matrix | ||||||||||
| 124 | |||||||||||
| 125 | Build a matrix. Some options are available to pass to the matrix function: | ||||||||||
| 126 | |||||||||||
| 127 | =over 6 | ||||||||||
| 128 | |||||||||||
| 129 | =item C<diagonal> | ||||||||||
| 130 | |||||||||||
| 131 | Highlight the diagonal of the matrix. | ||||||||||
| 132 | |||||||||||
| 133 | my $m = matrix(\@cols,\@lines,$data, {diagonal => 1}); | ||||||||||
| 134 | |||||||||||
| 135 | =item C<format> | ||||||||||
| 136 | |||||||||||
| 137 | Pass a string to be used by the C<format> filter in the TT2 template. | ||||||||||
| 138 | |||||||||||
| 139 | my $m = matrix(\@cols,\@lines,$data, {format => '%.6f'}); | ||||||||||
| 140 | |||||||||||
| 141 | =item C<ucfirst> | ||||||||||
| 142 | |||||||||||
| 143 | Option to uppercase first letter in columns and lines labels. | ||||||||||
| 144 | |||||||||||
| 145 | my $m = matrix(\@cols,\@lines,$data, {ucfirst => 1}); | ||||||||||
| 146 | |||||||||||
| 147 | =back | ||||||||||
| 148 | |||||||||||
| 149 | =cut | ||||||||||
| 150 | |||||||||||
| 151 | sub matrix { | ||||||||||
| 152 | 3 | ▶ | my ($cols,$lines,$data,$options) = @_; | ||||||||
|
Subroutine
matrix: called CC=10 SCAR=23.5
Pod
documented
| |||||||||||
| 153 | |||||||||||
| 154 | 3 | ▶ | if ($options->{ucfirst}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 155 | 0 | foreach (@$cols) { | |||||||||
| 156 | 0 | $_ = ucfirst($_); | |||||||||
| 157 | } | ||||||||||
| 158 | 0 | foreach (@$lines) { | |||||||||
| 159 | 0 | $_ = ucfirst($_); | |||||||||
| 160 | } | ||||||||||
| 161 | } | ||||||||||
| 162 | |||||||||||
| 163 | 3 | my $vals = []; | |||||||||
| 164 | 3 | my $attrs = []; | |||||||||
| 165 | 3 | my $more = []; | |||||||||
| 166 | |||||||||||
| 167 | 3 | foreach my $row (@$data){ | |||||||||
| 168 | 6 | my $vrow = []; | |||||||||
| 169 | 6 | my $arow = []; | |||||||||
| 170 | 6 | my $mrow = []; | |||||||||
| 171 | 6 | foreach(@$row){ | |||||||||
| 172 | 12 | ▶ | if (ref($_)){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 173 | 1 | push @$vrow, $_->{v}; | |||||||||
| 174 | 1 | push @$arow, $_->{a}; | |||||||||
| 175 | 1 | push @$mrow, $_->{more_info}; | |||||||||
| 176 | } | ||||||||||
| 177 | else { | ||||||||||
| 178 | 11 | push @$vrow, $_; | |||||||||
| 179 | 11 | push @$arow, undef; | |||||||||
| 180 | 11 | push @$mrow, undef; | |||||||||
| 181 | } | ||||||||||
| 182 | } | ||||||||||
| 183 | 6 | push @$vals, $vrow; | |||||||||
| 184 | 6 | push @$attrs, $arow; | |||||||||
| 185 | 6 | push @$more, $mrow; | |||||||||
| 186 | } | ||||||||||
| 187 | |||||||||||
| 188 | 3 | my $vars = { | |||||||||
| 189 | cols => $cols, | ||||||||||
| 190 | lines => $lines, | ||||||||||
| 191 | vals => $vals, | ||||||||||
| 192 | attrs => $attrs, | ||||||||||
| 193 | more => $more, | ||||||||||
| 194 | }; | ||||||||||
| 195 | $vars->{css} = $options->{css} | ||||||||||
| 196 | 3 | ▶ | if $options->{css}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 197 | $vars->{myformat} = $options->{format} | ||||||||||
| 198 | 3 | ▶ | if $options->{format}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 199 | $vars->{diagonal} = $options->{diagonal} | ||||||||||
| 200 | 3 | ▶ | if $options->{diagonal}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 201 | |||||||||||
| 202 | 3 | my $template_name = 'matrix'; | |||||||||
| 203 | 3 | __process($template_name, $vars); | |||||||||
| 204 | } | ||||||||||
| 205 | |||||||||||
| 206 | =head2 h | ||||||||||
| 207 | |||||||||||
| 208 | A function to allow horizontal composition. | ||||||||||
| 209 | |||||||||||
| 210 | =cut | ||||||||||
| 211 | |||||||||||
| 212 | sub h { | ||||||||||
| 213 | 1 | ▶ | my (@list) = @_; | ||||||||
|
Subroutine
h: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 214 | |||||||||||
| 215 | 1 | my $vars = { | |||||||||
| 216 | list => [@list], | ||||||||||
| 217 | }; | ||||||||||
| 218 | 1 | my $template_name = 'h'; | |||||||||
| 219 | |||||||||||
| 220 | 1 | __process($template_name, $vars); | |||||||||
| 221 | } | ||||||||||
| 222 | |||||||||||
| 223 | =head2 v | ||||||||||
| 224 | |||||||||||
| 225 | A function to allow vertical composition. | ||||||||||
| 226 | |||||||||||
| 227 | =cut | ||||||||||
| 228 | |||||||||||
| 229 | sub v { | ||||||||||
| 230 | 1 | ▶ | my (@list) = @_; | ||||||||
|
Subroutine
v: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 231 | |||||||||||
| 232 | 1 | my $vars = { | |||||||||
| 233 | list => [@list], | ||||||||||
| 234 | }; | ||||||||||
| 235 | 1 | my $template_name = 'v'; | |||||||||
| 236 | |||||||||||
| 237 | 1 | __process($template_name, $vars); | |||||||||
| 238 | } | ||||||||||
| 239 | |||||||||||
| 240 | sub __process { | ||||||||||
| 241 | 5 | ▶ | my ($template_name,$vars) = @_; | ||||||||
|
Subroutine
__process: called CC=1 SCAR=0.0
| |||||||||||
| 242 | |||||||||||
| 243 | # build html from template | ||||||||||
| 244 | 5 | my $template_config = { | |||||||||
| 245 | INCLUDE_PATH => [ 'templates' ], | ||||||||||
| 246 | }; | ||||||||||
| 247 | 5 | my $template = Template->new({ | |||||||||
| 248 | LOAD_TEMPLATES => [ HTML::Auto::Templates->new($template_config) ], | ||||||||||
| 249 | }); | ||||||||||
| 250 | 5 | my $html; | |||||||||
| 251 | 5 | $template->process($template_name, $vars, \$html); | |||||||||
| 252 | |||||||||||
| 253 | 5 | $html; | |||||||||
| 254 | } | ||||||||||
| 255 | |||||||||||
| 256 | =head1 AUTHOR | ||||||||||
| 257 | |||||||||||
| 258 | Nuno Carvalho, C<< <smash at cpan.org> >> | ||||||||||
| 259 | André Santos, C<< <andrefs at cpan.org> >> | ||||||||||
| 260 | |||||||||||
| 261 | =head1 BUGS | ||||||||||
| 262 | |||||||||||
| 263 | Please report any bugs or feature requests to C<bug-html-auto at rt.cpan.org>, or through | ||||||||||
| 264 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=HTML-Auto>. I will be notified, and then you'll | ||||||||||
| 265 | automatically be notified of progress on your bug as I make changes. | ||||||||||
| 266 | |||||||||||
| 267 | |||||||||||
| 268 | |||||||||||
| 269 | |||||||||||
| 270 | =head1 SUPPORT | ||||||||||
| 271 | |||||||||||
| 272 | You can find documentation for this module with the perldoc command. | ||||||||||
| 273 | |||||||||||
| 274 | perldoc HTML::Auto | ||||||||||
| 275 | |||||||||||
| 276 | |||||||||||
| 277 | You can also look for information at: | ||||||||||
| 278 | |||||||||||
| 279 | =over 4 | ||||||||||
| 280 | |||||||||||
| 281 | =item * RT: CPAN's request tracker | ||||||||||
| 282 | |||||||||||
| 283 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=HTML-Auto> | ||||||||||
| 284 | |||||||||||
| 285 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||
| 286 | |||||||||||
| 287 | L<http://annocpan.org/dist/HTML-Auto> | ||||||||||
| 288 | |||||||||||
| 289 | =item * CPAN Ratings | ||||||||||
| 290 | |||||||||||
| 291 | L<http://cpanratings.perl.org/d/HTML-Auto> | ||||||||||
| 292 | |||||||||||
| 293 | =item * Search CPAN | ||||||||||
| 294 | |||||||||||
| 295 | L<http://search.cpan.org/dist/HTML-Auto/> | ||||||||||
| 296 | |||||||||||
| 297 | =back | ||||||||||
| 298 | |||||||||||
| 299 | |||||||||||
| 300 | =head1 ACKNOWLEDGEMENTS | ||||||||||
| 301 | |||||||||||
| 302 | |||||||||||
| 303 | =head1 LICENSE AND COPYRIGHT | ||||||||||
| 304 | |||||||||||
| 305 | Copyright 2012 Project Natura. | ||||||||||
| 306 | |||||||||||
| 307 | This program is free software; you can redistribute it and/or modify it | ||||||||||
| 308 | under the terms of either: the GNU General Public License as published | ||||||||||
| 309 | by the Free Software Foundation; or the Artistic License. | ||||||||||
| 310 | |||||||||||
| 311 | See http://dev.perl.org/licenses/ for more information. | ||||||||||
| 312 | |||||||||||
| 313 | |||||||||||
| 314 | =cut | ||||||||||
| 315 | |||||||||||
| 316 | 3 | 1; # End of HTML::Auto | |||||||||