| 1 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 2 | ▶ | use 5.010; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | |||||||||||
| 4 | package FusqlFS::Formatter::Html; | ||||||||||
| 5 | 2 | ▶ | use parent 'FusqlFS::Formatter::Base'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 2 | ▶ | use FusqlFS::Version; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 2 | our $VERSION = $FusqlFS::Version::VERSION; | |||||||||
| 8 | |||||||||||
| 9 | =head1 NAME | ||||||||||
| 10 | |||||||||||
| 11 | FusqlFS::Formatter::Html - HTML formatter class | ||||||||||
| 12 | |||||||||||
| 13 | =head1 DESCRIPTION | ||||||||||
| 14 | |||||||||||
| 15 | This formatter outputs data as lists (ordered C<E<lt>olE<gt>> lists for arrays | ||||||||||
| 16 | and definition C<E<lt>dlE<gt>> lists for hashes). | ||||||||||
| 17 | |||||||||||
| 18 | This is a dump-only formatter, it doesn't parse data back into Perl structures, | ||||||||||
| 19 | so you can't edit and save data while using this formatter. | ||||||||||
| 20 | |||||||||||
| 21 | See also L<FusqlFS::Formatter::Htmltable> formatter for data formatted in HTML | ||||||||||
| 22 | tables. | ||||||||||
| 23 | |||||||||||
| 24 | =begin testing | ||||||||||
| 25 | |||||||||||
| 26 | #!noinst | ||||||||||
| 27 | |||||||||||
| 28 | my $hvalue = { a => 1, b => 2, c => 3 }; | ||||||||||
| 29 | my $avalue = [ 1, 2, 3 ]; | ||||||||||
| 30 | my $svalue = "123"; | ||||||||||
| 31 | is {_tpkg}::_Dump($hvalue), q{<dl><dt>a</dt><dd>1</dd><dt>b</dt><dd>2</dd><dt>c</dt><dd>3</dd></dl>}, "hash dumped correctly"; | ||||||||||
| 32 | is {_tpkg}::_Dump($avalue), q{<ol><li>1</li><li>2</li><li>3</li></ol>}, "array dumped correctly"; | ||||||||||
| 33 | is {_tpkg}::_Dump($svalue), "123", "scalar dumped correctly"; | ||||||||||
| 34 | |||||||||||
| 35 | my $complex = { a => 1, b => [2, 3, 4], c => [5] }; | ||||||||||
| 36 | is {_tpkg}::_Dump($complex), q{<dl><dt>a</dt><dd>1</dd><dt>b</dt><dd><ol><li>2</li><li>3</li><li>4</li></ol></dd><dt>c</dt><dd><ol><li>5</li></ol></dd></dl>}, "complex structure dumped correctly"; | ||||||||||
| 37 | |||||||||||
| 38 | =end testing | ||||||||||
| 39 | |||||||||||
| 40 | =cut | ||||||||||
| 41 | |||||||||||
| 42 | sub Dump | ||||||||||
| 43 | 0 | ▶ | { | ||||||||
|
Subroutine
Dump: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 44 | 0 | '<html><head><meta charset="utf-8" /><title>FusqlFS data</title><link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/css/bootstrap.no-icons.min.css" rel="stylesheet"></head><body>' . &_Dump . '</body></html>'; | |||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | sub _Dump | ||||||||||
| 48 | 17 | ▶ | { | ||||||||
|
Subroutine
_Dump: called CC=2 SCAR=7.3
| |||||||||||
| 49 | 17 | my $value = shift; | |||||||||
| 50 | 17 | my $ref = ref $value; | |||||||||
| 51 | 17 | ▶ | return $value unless $ref; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | |||||||||||
| 53 | 5 | given ($ref) { | |||||||||
| 54 | 5 | when ('ARRAY') { | |||||||||
| 55 | 3 | return '<ol><li>' . join('</li><li>', map _Dump($_), @$value) . '</li></ol>'; | |||||||||
| 56 | } | ||||||||||
| 57 | 2 | when ('HASH') { | |||||||||
| 58 | 2 | return '<dl>' . join('', map "<dt>$_</dt><dd>${\_Dump($value->{$_})}</dd>", sort keys %$value) . '</dl>'; | |||||||||
| 59 | } | ||||||||||
| 60 | 0 | when ('SCALAR') { | |||||||||
| 61 | 0 | return $$value; | |||||||||
| 62 | } | ||||||||||
| 63 | 0 | default { | |||||||||
| 64 | 0 | return $value; | |||||||||
| 65 | } | ||||||||||
| 66 | } | ||||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | 2 | 1; | |||||||||