| 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.06 | ||||||||||
| 23 | |||||||||||
| 24 | =cut | ||||||||||
| 25 | |||||||||||
| 26 | 3 | our $VERSION = '0.06'; | |||||||||
| 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 SUBROUTINES/METHODS | ||||||||||
| 122 | |||||||||||
| 123 | =head2 matrix | ||||||||||
| 124 | |||||||||||
| 125 | =cut | ||||||||||
| 126 | |||||||||||
| 127 | sub matrix { | ||||||||||
| 128 | 2 | ▶ | my ($cols,$lines,$data,$options) = @_; | ||||||||
|
Subroutine
matrix: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||
| 129 | |||||||||||
| 130 | # pre-process data | ||||||||||
| 131 | 2 | foreach (@$cols) { | |||||||||
| 132 | 4 | $_ = ucfirst($_); | |||||||||
| 133 | } | ||||||||||
| 134 | 2 | foreach (@$lines) { | |||||||||
| 135 | 4 | $_ = ucfirst($_); | |||||||||
| 136 | } | ||||||||||
| 137 | |||||||||||
| 138 | 2 | my $vals = []; | |||||||||
| 139 | 2 | my $attrs = []; | |||||||||
| 140 | 2 | my $more = []; | |||||||||
| 141 | |||||||||||
| 142 | 2 | foreach my $row (@$data){ | |||||||||
| 143 | 4 | my $vrow = []; | |||||||||
| 144 | 4 | my $arow = []; | |||||||||
| 145 | 4 | my $mrow = []; | |||||||||
| 146 | 4 | foreach(@$row){ | |||||||||
| 147 | 8 | ▶ | if (ref($_)){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 148 | 1 | push @$vrow, $_->{v}; | |||||||||
| 149 | 1 | push @$arow, $_->{a}; | |||||||||
| 150 | 1 | push @$mrow, $_->{more_info}; | |||||||||
| 151 | } | ||||||||||
| 152 | else { | ||||||||||
| 153 | 7 | push @$vrow, $_; | |||||||||
| 154 | 7 | push @$arow, undef; | |||||||||
| 155 | 7 | push @$mrow, undef; | |||||||||
| 156 | } | ||||||||||
| 157 | } | ||||||||||
| 158 | 4 | push @$vals, $vrow; | |||||||||
| 159 | 4 | push @$attrs, $arow; | |||||||||
| 160 | 4 | push @$more, $mrow; | |||||||||
| 161 | } | ||||||||||
| 162 | |||||||||||
| 163 | 2 | my $vars = { | |||||||||
| 164 | cols => $cols, | ||||||||||
| 165 | lines => $lines, | ||||||||||
| 166 | vals => $vals, | ||||||||||
| 167 | attrs => $attrs, | ||||||||||
| 168 | more => $more, | ||||||||||
| 169 | }; | ||||||||||
| 170 | $vars->{css} = $options->{css} | ||||||||||
| 171 | 2 | ▶ | if $options->{css}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 172 | 2 | my $template_name = 'matrix'; | |||||||||
| 173 | |||||||||||
| 174 | 2 | __process($template_name, $vars); | |||||||||
| 175 | } | ||||||||||
| 176 | |||||||||||
| 177 | =head2 h | ||||||||||
| 178 | |||||||||||
| 179 | A function to allow horizontal composition. | ||||||||||
| 180 | |||||||||||
| 181 | =cut | ||||||||||
| 182 | |||||||||||
| 183 | sub h { | ||||||||||
| 184 | 1 | ▶ | my (@list) = @_; | ||||||||
|
Subroutine
h: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 185 | |||||||||||
| 186 | 1 | my $vars = { | |||||||||
| 187 | list => [@list], | ||||||||||
| 188 | }; | ||||||||||
| 189 | 1 | my $template_name = 'h'; | |||||||||
| 190 | |||||||||||
| 191 | 1 | __process($template_name, $vars); | |||||||||
| 192 | } | ||||||||||
| 193 | |||||||||||
| 194 | =head2 v | ||||||||||
| 195 | |||||||||||
| 196 | A function to allow vertical composition. | ||||||||||
| 197 | |||||||||||
| 198 | =cut | ||||||||||
| 199 | |||||||||||
| 200 | sub v { | ||||||||||
| 201 | 1 | ▶ | my (@list) = @_; | ||||||||
|
Subroutine
v: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 202 | |||||||||||
| 203 | 1 | my $vars = { | |||||||||
| 204 | list => [@list], | ||||||||||
| 205 | }; | ||||||||||
| 206 | 1 | my $template_name = 'v'; | |||||||||
| 207 | |||||||||||
| 208 | 1 | __process($template_name, $vars); | |||||||||
| 209 | } | ||||||||||
| 210 | |||||||||||
| 211 | sub __process { | ||||||||||
| 212 | 4 | ▶ | my ($template_name,$vars) = @_; | ||||||||
|
Subroutine
__process: called CC=1 SCAR=0.0
| |||||||||||
| 213 | |||||||||||
| 214 | # build html from template | ||||||||||
| 215 | 4 | my $template_config = { | |||||||||
| 216 | INCLUDE_PATH => [ 'templates' ], | ||||||||||
| 217 | }; | ||||||||||
| 218 | 4 | my $template = Template->new({ | |||||||||
| 219 | LOAD_TEMPLATES => [ HTML::Auto::Templates->new($template_config) ], | ||||||||||
| 220 | }); | ||||||||||
| 221 | 4 | my $html; | |||||||||
| 222 | 4 | $template->process($template_name, $vars, \$html); | |||||||||
| 223 | |||||||||||
| 224 | 4 | $html; | |||||||||
| 225 | } | ||||||||||
| 226 | |||||||||||
| 227 | =head1 AUTHOR | ||||||||||
| 228 | |||||||||||
| 229 | Nuno Carvalho, C<< <smash at cpan.org> >> | ||||||||||
| 230 | André Santos, C<< <andrefs at cpan.org> >> | ||||||||||
| 231 | |||||||||||
| 232 | =head1 BUGS | ||||||||||
| 233 | |||||||||||
| 234 | Please report any bugs or feature requests to C<bug-html-auto at rt.cpan.org>, or through | ||||||||||
| 235 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=HTML-Auto>. I will be notified, and then you'll | ||||||||||
| 236 | automatically be notified of progress on your bug as I make changes. | ||||||||||
| 237 | |||||||||||
| 238 | |||||||||||
| 239 | |||||||||||
| 240 | |||||||||||
| 241 | =head1 SUPPORT | ||||||||||
| 242 | |||||||||||
| 243 | You can find documentation for this module with the perldoc command. | ||||||||||
| 244 | |||||||||||
| 245 | perldoc HTML::Auto | ||||||||||
| 246 | |||||||||||
| 247 | |||||||||||
| 248 | You can also look for information at: | ||||||||||
| 249 | |||||||||||
| 250 | =over 4 | ||||||||||
| 251 | |||||||||||
| 252 | =item * RT: CPAN's request tracker | ||||||||||
| 253 | |||||||||||
| 254 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=HTML-Auto> | ||||||||||
| 255 | |||||||||||
| 256 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||
| 257 | |||||||||||
| 258 | L<http://annocpan.org/dist/HTML-Auto> | ||||||||||
| 259 | |||||||||||
| 260 | =item * CPAN Ratings | ||||||||||
| 261 | |||||||||||
| 262 | L<http://cpanratings.perl.org/d/HTML-Auto> | ||||||||||
| 263 | |||||||||||
| 264 | =item * Search CPAN | ||||||||||
| 265 | |||||||||||
| 266 | L<http://search.cpan.org/dist/HTML-Auto/> | ||||||||||
| 267 | |||||||||||
| 268 | =back | ||||||||||
| 269 | |||||||||||
| 270 | |||||||||||
| 271 | =head1 ACKNOWLEDGEMENTS | ||||||||||
| 272 | |||||||||||
| 273 | |||||||||||
| 274 | =head1 LICENSE AND COPYRIGHT | ||||||||||
| 275 | |||||||||||
| 276 | Copyright 2012 Project Natura. | ||||||||||
| 277 | |||||||||||
| 278 | This program is free software; you can redistribute it and/or modify it | ||||||||||
| 279 | under the terms of either: the GNU General Public License as published | ||||||||||
| 280 | by the Free Software Foundation; or the Artistic License. | ||||||||||
| 281 | |||||||||||
| 282 | See http://dev.perl.org/licenses/ for more information. | ||||||||||
| 283 | |||||||||||
| 284 | |||||||||||
| 285 | =cut | ||||||||||
| 286 | |||||||||||
| 287 | 3 | 1; # End of HTML::Auto | |||||||||