File Coverage

blib/lib/String/Tagged/HTML.pm
Criterion Covered Total %
statement 73 94 77.6
branch 26 40 65.0
condition 1 2 50.0
subroutine 11 15 73.3
pod 4 4 100.0
total 115 155 74.1


line stmt bran cond sub pod time code
1             # You may distribute under the terms of either the GNU General Public License
2             # or the Artistic License (the same terms as Perl itself)
3             #
4             # (C) Paul Evans, 2011-2021 -- leonerd@leonerd.org.uk
5              
6             package String::Tagged::HTML 0.02;
7              
8 7     7   1344962 use v5.14;
  7         58  
9 7     7   40 use warnings;
  7         14  
  7         199  
10              
11 7     7   35 use base qw( String::Tagged );
  7         13  
  7         4352  
12             String::Tagged->VERSION( '0.20' );
13              
14             =head1 NAME
15              
16             C - handle HTML content using C
17              
18             =head1 SYNOPSIS
19              
20             use String::Tagged::HTML;
21              
22             my $st = String::Tagged::HTML->new( "An important message" );
23              
24             $st->apply_tag( 3, 9, b => 1 );
25              
26             print $st->as_html( "h1" );
27              
28             =head1 DESCRIPTION
29              
30             This subclass of L provides a method, C, for rendering
31             the string as an HTML fragment, using the tags to provide formatting. For
32             example, the SYNOPSIS example will produce the output
33              
34            

An important message

35              
36             With the exception of tags named C, a tag applied to an extent of the
37             C will be rendered using start and end HTML tags of the
38             same name. If the tag's value is a C reference, then this hash will be
39             used to provide additional attributes for the HTML element. Tags whose names
40             begin with C<_> will be ignored for this purpose.
41              
42             my $str = String::Tagged::HTML->new( "click " )
43             ->append_tagged( "here", a => { href => "/see/other.html" } );
44              
45             print $str->as_html( "p" );
46              
47             Z<>
48              
49            

click here

50              
51             If it is not a C reference, then its value ought to be a simple boolean
52             true value, such as C<1>.
53              
54             The special tag named C disables HTML entity escaping over its extent.
55              
56             my $str = String::Tagged::HTML->new( "This is escaped" );
57              
58             my $br = String::Tagged::HTML->new_tagged( "
", raw => 1 );
59              
60             print +( $str . $br )->as_html( "p" );
61              
62             Z<>
63              
64            

This <content> is escaped

65              
66             =head2 Automatic C<< >> Generation
67              
68             Tags whose names begin C<_span_style_...> are used to create a C