| 1 | # | ||||||||||||||||||||||||||||||||
| 2 | # Copyright (c) 2013-2019 Christian Jaeger, copying@christianjaeger.ch | ||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||
| 4 | # This is free software, offered under either the same terms as perl 5 | ||||||||||||||||||||||||||||||||
| 5 | # or the terms of the Artistic License version 2 or the terms of the | ||||||||||||||||||||||||||||||||
| 6 | # MIT License (Expat version). See the file COPYING.md that came | ||||||||||||||||||||||||||||||||
| 7 | # bundled with this file. | ||||||||||||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||
| 10 | =head1 NAME | ||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | PXML::XHTML | ||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||
| 14 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||
| 16 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||
| 19 | =head1 NOTE | ||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||
| 21 | This is alpha software! Read the status section in the package README | ||||||||||||||||||||||||||||||||
| 22 | or on the L<website|http://functional-perl.org/>. | ||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | =cut | ||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||
| 26 | package PXML::XHTML; | ||||||||||||||||||||||||||||||||
| 27 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 28 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 29 | 7 | ▶ | use warnings FATAL => 'uninitialized'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 30 | 7 | ▶ | use Exporter "import"; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||
| 32 | 7 | ▶ | use PXML::Element; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||
| 34 | 7 | our $nbsp = "\xa0"; | |||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||
| 36 | 7 | our $tags = [ | |||||||||||||||||||||||||||||||
| 37 | 'a', 'abbr', 'acronym', 'address', 'applet', 'area', 'b', 'base', | ||||||||||||||||||||||||||||||||
| 38 | 'basefont', 'bdo', 'big', 'blockquote', 'body', 'br', 'button', 'caption', | ||||||||||||||||||||||||||||||||
| 39 | 'center', 'cite', 'code', 'col', 'colgroup', 'dd', 'del', 'dfn', 'dir', | ||||||||||||||||||||||||||||||||
| 40 | 'div', 'dl', 'dt', 'em', 'fieldset', 'font', 'form', 'h1', 'h2', 'h3', | ||||||||||||||||||||||||||||||||
| 41 | 'h4', 'h5', 'h6', 'head', 'hr', 'html', 'i', 'iframe', 'img', 'input', | ||||||||||||||||||||||||||||||||
| 42 | 'ins', 'isindex', 'kbd', 'label', 'legend', 'li', 'link', 'map', 'menu', | ||||||||||||||||||||||||||||||||
| 43 | 'meta', 'noframes', 'noscript', 'object', 'ol', 'optgroup', 'option', 'p', | ||||||||||||||||||||||||||||||||
| 44 | 'param', 'pre', 'q', 's', 'samp', 'script', 'select', 'small', | ||||||||||||||||||||||||||||||||
| 45 | 'source', # not XHTML?, hack | ||||||||||||||||||||||||||||||||
| 46 | 'span', 'strike', 'strong', 'style', 'sub', 'sup', 'table', 'tbody', 'td', | ||||||||||||||||||||||||||||||||
| 47 | 'textarea', 'tfoot', 'th', 'thead', 'title', 'tr', 'tt', 'u', 'ul', 'var', | ||||||||||||||||||||||||||||||||
| 48 | 'video', # not XHTML?, hack | ||||||||||||||||||||||||||||||||
| 49 | ]; | ||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||
| 51 | our $funcs = [ | ||||||||||||||||||||||||||||||||
| 52 | map { | ||||||||||||||||||||||||||||||||
| 53 | 7 | my $tag = $_; | |||||||||||||||||||||||||||||||
| 54 | [ | ||||||||||||||||||||||||||||||||
| 55 | uc $tag, | ||||||||||||||||||||||||||||||||
| 56 | 229 | ▶ | sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 57 | 229 | ▶ | my $atts = ref($_[0]) eq "HASH" ? shift : undef; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 58 | 229 | PXML::_::XHTML->new($tag, $atts, [@_]); | |||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||
| 60 | 637 | ] | |||||||||||||||||||||||||||||||
| 61 | } @$tags | ||||||||||||||||||||||||||||||||
| 62 | ]; | ||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||
| 64 | 7 | for (@$funcs) { | |||||||||||||||||||||||||||||||
| 65 | 637 | my ($name, $fn) = @$_; | |||||||||||||||||||||||||||||||
| 66 | 7 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 67 | 637 | *{"PXML::XHTML::$name"} = $fn | |||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||
| 70 | 7 | our @EXPORT_OK = ('$nbsp', map { $$_[0] } @$funcs); | |||||||||||||||||||||||||||||||
| 71 | 7 | our %EXPORT_TAGS = (all => \@EXPORT_OK); | |||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||
| 73 | 7 | package PXML::_::XHTML { | |||||||||||||||||||||||||||||||
| 74 | 7 | our @ISA = "PXML::Element"; | |||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||
| 76 | # serialize to HTML5 compatible representation: | ||||||||||||||||||||||||||||||||
| 77 | 43 | ▶ | sub require_printing_nonvoid_elements_nonselfreferential { | ||||||||||||||||||||||||||||||
|
Subroutine
require_printing_nonvoid_elements_nonselfreferential: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 78 | 43 | 1 | |||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||
| 81 | 7 | ▶ | use PXML::HTML5 '$html5_void_element_h'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||
| 83 | 43 | ▶ | sub void_element_h { | ||||||||||||||||||||||||||||||
|
Subroutine
void_element_h: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 84 | 43 | $html5_void_element_h | |||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||
| 87 | 7 | ▶ | use FP::Show (); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||
| 89 | # This "should" be moved to PXML::Element except that we only know | ||||||||||||||||||||||||||||||||
| 90 | # in the HTML case how to map back tag names to constructors (XX | ||||||||||||||||||||||||||||||||
| 91 | # is it actually safe here?). (Would have to store what mapping | ||||||||||||||||||||||||||||||||
| 92 | # functions were created under which function names for which tag | ||||||||||||||||||||||||||||||||
| 93 | # names, and which packages they were exported to.) XXX at least | ||||||||||||||||||||||||||||||||
| 94 | # move to common base class of XHTML and HTML5. | ||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | sub FP_Show_show { | ||||||||||||||||||||||||||||||
|
Subroutine
FP_Show_show: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||
| 96 | 0 | my ($s, $show) = @_; | |||||||||||||||||||||||||||||||
| 97 | 0 | my $a = $s->maybe_attributes; | |||||||||||||||||||||||||||||||
| 98 | 0 | my $b = $s->body; | |||||||||||||||||||||||||||||||
| 99 | ( | ||||||||||||||||||||||||||||||||
| 100 | uc($s->name) . "(" | ||||||||||||||||||||||||||||||||
| 101 | . join(", ", | ||||||||||||||||||||||||||||||||
| 102 | (defined($a) and keys %$a) ? &$show($a) : (), | ||||||||||||||||||||||||||||||||
| 103 | ref($b) eq "ARRAY" | ||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | ? join(", ", map { &$show($_) } @$b) | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
defined $a and keys %$a
MC/DC0%0/2
defined $a and keys %$a
defined $a
keys %$a
Truth table0%0/3
A and B
A= defined $aB= keys %$a
| |||||||||||||||||||||||||||||||||
| 105 | : &$show($b)) | ||||||||||||||||||||||||||||||||
| 106 | . ")" | ||||||||||||||||||||||||||||||||
| 107 | ) | ||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||
| 111 | 7 | 1 | |||||||||||||||||||||||||||||||