File Coverage

blib/lib/Pod/HtmlEasy/Data.pm
Criterion Covered Total %
statement 68 68 100.0
branch 12 12 100.0
condition 3 3 100.0
subroutine 22 22 100.0
pod 0 17 0.0
total 105 122 86.0


line stmt bran cond sub pod time code
1             #
2             #===============================================================================
3             #
4             # FILE: Data.pm
5             #
6             # DESCRIPTION: Data definitions
7             #
8             # FILES: ---
9             # BUGS: ---
10             # NOTES: --- The intent of this module is to localize some of the HTML
11             # generation so as to make it accessible to the test suite.
12             # AUTHOR: Geoffrey Leach,
13             # VERSION: 1.1.11
14             # CREATED: 10/17/07 15:14:33 PDT
15             # UPDATED: Wed Jan 20 05:28:34 PST 2013
16             # COPYRIGHT: (c) 2008-2010 Geoffrey Leach
17             #
18             #===============================================================================
19              
20             package Pod::HtmlEasy::Data;
21 5     5   81235 use 5.006002;
  5         47  
  5         430  
22              
23 5     5   26 use strict;
  5         6  
  5         156  
24 5     5   25 use warnings;
  5         9  
  5         171  
25 5     5   1717 use English qw{ -no_match_vars };
  5         4507  
  5         51  
26             our $VERSION = version->declare("v1.1.11");
27              
28             use Exporter::Easy (
29 5         53 OK => [
30             qw( EMPTY FALSE NL NUL SPACE TRUE
31             body css gen head headend podoff podon title toc toc_tag top )
32             ],
33 5     5   8059 );
  5         7907  
34              
35 1425     1425 0 23492 sub EMPTY { return q{}; }
36 2462     2462 0 14355 sub NL { return $INPUT_RECORD_SEPARATOR; }
37 9     9 0 605 sub NUL { return qq{\0}; }
38 1     1 0 535 sub SPACE { return q{ }; }
39 10     10 0 610 sub TRUE { return 1; }
40 22     22 0 1147 sub FALSE { return 0; }
41              
42             sub head {
43 95     95 0 428346 return q{},
44             q{},
45             q{};
46             }
47              
48 95     95 0 1293 sub headend { return q{}; }
49              
50             sub gen {
51 13     13 0 752 my ( $ver, $pver ) = @_;
52 13         76 my $g
53             = q{ 54             . qq{Perl/$] [$^O]">};
55 13         450 $g =~ s{VERSION}{$ver}msx;
56 13         46 $g =~ s{PVERSION}{$pver}msx;
57 13         54 return $g;
58             }
59              
60 98     98 0 1206 sub podon { return q{
}; }
61              
62             sub podoff {
63 99     99 0 2008 my $no_body = shift;
64 99 100       327 return defined $no_body ? q{} : q{};
65             }
66              
67             sub title {
68 95     95 0 1229 my $title = shift;
69 95         326 return q{}, $title, q{};
70             }
71              
72             sub toc {
73 79     79 0 1616 my @index = @_;
74 79         184 my @toc = ( q{
}, q{
    }, q{
}, q{
} );
75             ## no critic (ProhibitMagicNumbers)
76             return @index
77 79 100       642 ? ( @toc[ 0 .. 1 ], @index, @toc[ 2 .. 3 ] )
78             : @toc;
79             }
80              
81             # Create the toc tag.
82             # First we remove <' to '>'. These are HTML encodings ( ... , for example)
83             # that have been introduced processing directives (I<...>, for example)
84             # Spaces are reduced to one to eliminate problems created by embedded tabs.
85             # HTTP prefix removed to avoid getting tag post-processed as an URL.
86              
87             sub toc_tag {
88 162     162 0 796 my $txt = shift;
89 162         348 $txt =~ s{<.+?>}{}msxg;
90 162         582 $txt =~ s{\s+}{ }msxg;
91 162         262 $txt =~ s{https?://}{}msxg;
92 162         555 return $txt;
93             }
94              
95 5     5 0 570 sub top { return q{}; }
96              
97             sub body {
98 97     97 0 3054 my $body_spec = shift;
99 97         790 my %body = (
100             alink => '#FF0000',
101             bgcolor => '#FFFFFF',
102             link => '#000000',
103             text => '#000000',
104             vlink => '#000066',
105             );
106 97         162 my $body = q{
107              
108             # First case - provide the defau( $body, lt body addtributes
109 97 100       338 if ( not defined $body_spec ) {
110 91         543 foreach my $key ( sort keys %body ) {
111 455         919 $body .= qq{ $key="$body{$key}"};
112             }
113 91         621 return $body . q{>};
114             }
115              
116             # Second case - we're given a new, complete (by definition), set of body attributes
117 6 100       21 if ( ref $body_spec ne q{HASH} ) { return qq{}; }
  3         21  
118              
119             # Third case - we have a hash to update the body attributes
120 3         17 my %new_body = %body;
121              
122             # Make sure that the user-defined keys are formatted correctly
123 3         8 foreach my $key ( keys %{$body_spec} ) {
  3         12  
124 3         8 my $value = $body_spec->{$key};
125 3         16 $value =~ s{['"#]}{}smxg;
126 3         12 $new_body{$key} = qq{#$value};
127             }
128              
129             # Convert the hash to a string of HTML stuff, maintaining alpha sort
130 3         19 foreach my $key ( sort keys %new_body ) {
131 15         36 $body .= qq{ $key="$new_body{$key}"};
132             }
133              
134 3         24 return $body . q{>};
135             }
136              
137             sub css {
138 11     11 0 2230 my $data = shift;
139              
140 11         18 my $css = << "END_CSS";
141             /* Properties that apply to the entire HTML file produced */
142             BODY {
143             background: white;
144             color: black;
145             font-family: arial,sans-serif;
146             margin: 0;
147             padding: 1ex;
148             }
149             /* The links; no change once visited */
150             A:link, A:visited {
151             background: transparent;
152             color: #006699;
153             }
154             /* Applies to
contents; that's most everything
155             DIV {
156             border-width: 0;
157             }
158             /*
 is used for verbatum POD */ 
159             .pod PRE {
160             background: #eeeeee;
161             border: 1px solid #888888;
162             color: black;
163             padding: 1em;
164             white-space: pre;
165             }
166             /* This is the style of the header/footer of the POD pages */
167             .HF {
168             background: #eeeeee;
169             border: 1px solid #888888;
170             color: black;
171             margin: 1ex 0;
172             padding: 0.5ex 1ex;
173             }
174             /*

result from processing =head1, and are generated only in class="pod" */

175             .pod H1 {
176             background: transparent;
177             color: #006699;
178             font-size: large;
179             }
180             /* Ditto

*/

181             .pod H2, H3, H4 {
182             background: transparent;
183             color: #006699;
184             font-size: medium;
185             }
186             /* Applies to all
187             .pod .toc A {
188             text-decoration: none;
189             }
190             /*
  • items in the class="toc"; the table of contents, aka "index" */
  • 191             /*
  • in class="pod" -- the actual POD -- default to browser defaults */
  • 192             .toc li {
    193             line-height: 1.2em;
    194             list-style-type: none;
    195             }
    196              
    197             END_CSS
    198              
    199 11         27 my $NL = NL;
    200              
    201             # "x" modifier inappropriate here
    202             # RE sees it as embedded whitespace
    203             ## no critic (RequireExtendedFormatting)
    204 11 100 100     111 if ( defined $data && $data !~ m{$NL}sm ) {
    205              
    206             # No newlines in $css, so we assume that it is a file name
    207 3         17 return qq{};
    208             }
    209              
    210 8 100       22 if ( not defined $data ) { $data = $css; }
      5         9  
    211 8         84 return qq{};
    212             }
    213             1;