| 1 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 1 | ▶ | use 5.010; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | |||||||||||
| 4 | package FusqlFS::Formatter::Htmltable; | ||||||||||
| 5 | 1 | ▶ | use parent 'FusqlFS::Formatter::Html'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use FusqlFS::Version; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | our $VERSION = $FusqlFS::Version::VERSION; | |||||||||
| 8 | |||||||||||
| 9 | =head1 NAME | ||||||||||
| 10 | |||||||||||
| 11 | FusqlFS::Formatter::Htmltable - HTML formatter class | ||||||||||
| 12 | |||||||||||
| 13 | =head1 DESCRIPTION | ||||||||||
| 14 | |||||||||||
| 15 | This formatter outputs data as HTML tables. | ||||||||||
| 16 | |||||||||||
| 17 | This is a dump-only formatter, it doesn't parse data back into Perl structures, | ||||||||||
| 18 | so you can't edit and save data while using this formatter. | ||||||||||
| 19 | |||||||||||
| 20 | See also L<FusqlFS::Formatter::Html> formatter for data formatted in HTML lists. | ||||||||||
| 21 | |||||||||||
| 22 | =begin testing | ||||||||||
| 23 | |||||||||||
| 24 | #!noinst | ||||||||||
| 25 | |||||||||||
| 26 | my $hvalue = { a => 1, b => 2, c => 3 }; | ||||||||||
| 27 | my $avalue = [ 1, 2, 3 ]; | ||||||||||
| 28 | my $svalue = "123"; | ||||||||||
| 29 | is {_tpkg}::_Dump($hvalue), q{<table class="table"><tbody><tr><th>a</th><td>1</td></tr><tr><th>b</th><td>2</td></tr><tr><th>c</th><td>3</td></tr></tbody></table>}, "hash dumped correctly"; | ||||||||||
| 30 | is {_tpkg}::_Dump($avalue), q{<table class="table"><thead><tr><th>#</th><th>Value</th></tr></thead><tbody><tr><th>1</th><td>1</td></tr><tr><th>2</th><td>2</td></tr><tr><th>3</th><td>3</td></tr></tbody></table>}, "array dumped correctly"; | ||||||||||
| 31 | is {_tpkg}::_Dump($svalue), "123", "scalar dumped correctly"; | ||||||||||
| 32 | |||||||||||
| 33 | my $complex = { a => 1, b => [2, 3, 4], c => [5] }; | ||||||||||
| 34 | is {_tpkg}::_Dump($complex), q{<table class="table"><tbody><tr><th>a</th><td>1</td></tr><tr><th>b</th><td><table class="table"><thead><tr><th>#</th><th>Value</th></tr></thead><tbody><tr><th>1</th><td>2</td></tr><tr><th>2</th><td>3</td></tr><tr><th>3</th><td>4</td></tr></tbody></table></td></tr><tr><th>c</th><td><table class="table"><thead><tr><th>#</th><th>Value</th></tr></thead><tbody><tr><th>1</th><td>5</td></tr></tbody></table></td></tr></tbody></table>}, "complex structure dumped correctly"; | ||||||||||
| 35 | |||||||||||
| 36 | =end testing | ||||||||||
| 37 | |||||||||||
| 38 | =cut | ||||||||||
| 39 | |||||||||||
| 40 | sub Dump | ||||||||||
| 41 | 0 | ▶ | { | ||||||||
|
Subroutine
Dump: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 42 | 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>'; | |||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | sub _Dump | ||||||||||
| 46 | 17 | ▶ | { | ||||||||
|
Subroutine
_Dump: called CC=2 SCAR=7.1
| |||||||||||
| 47 | 17 | my $value = shift; | |||||||||
| 48 | 17 | my $ref = ref $value; | |||||||||
| 49 | 17 | ▶ | return $value unless $ref; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | |||||||||||
| 51 | 5 | given ($ref) { | |||||||||
| 52 | 5 | when ('ARRAY') { | |||||||||
| 53 | 3 | my $index = 0; | |||||||||
| 54 | 3 | return '<table class="table"><thead><tr><th>#</th><th>Value</th></tr></thead><tbody><tr>' . join('</tr><tr>', map "<th>${\(++$index)}</th><td>${\_Dump($_)}</td>", @$value) . '</tr></tbody></table>'; | |||||||||
| 55 | } | ||||||||||
| 56 | 2 | when ('HASH') { | |||||||||
| 57 | 2 | return '<table class="table"><tbody><tr>' . join('</tr><tr>', map "<th>$_</th><td>${\_Dump($value->{$_})}</td>", sort keys %$value) . '</tr></tbody></table>'; | |||||||||
| 58 | } | ||||||||||
| 59 | 0 | when ('SCALAR') { | |||||||||
| 60 | 0 | return $$value; | |||||||||
| 61 | } | ||||||||||
| 62 | 0 | default { | |||||||||
| 63 | 0 | return $value; | |||||||||
| 64 | } | ||||||||||
| 65 | } | ||||||||||
| 66 | } | ||||||||||
| 67 | |||||||||||
| 68 | 1 | 1; | |||||||||