File Coverage

blib/lib/HTML/Laundry/Rules.pm
Criterion Covered Total %
statement 37 40 92.5
branch n/a
condition n/a
subroutine 10 11 90.9
pod 9 9 100.0
total 56 60 93.3


line stmt bran cond sub pod time code
1             ########################################################
2             # Copyright © 2009 Six Apart, Ltd.
3              
4             package HTML::Laundry::Rules;
5 15     15   183739 use strict;
  15         35  
  15         623  
6 15     15   82 use warnings;
  15         32  
  15         11058  
7              
8             =head1 NAME
9              
10             HTML::Laundry::Rules - base class for HTML::Laundry rulesets
11              
12             =head1 VERSION
13              
14             Version 0.0002
15              
16             =cut
17              
18             =head1 FUNCTIONS
19              
20             =head2 new
21              
22             Create an HTML::Tidy::Rules object.
23              
24             my $rules = HTML::Laundry::Rules::MyRules->new();
25              
26             =cut
27              
28             sub new {
29 27     27 1 2507 my $class = shift;
30 27         47 my $self = {};
31 27         91 bless $self, $class;
32 27         164 return $self;
33             }
34              
35             =head2 tidy_ruleset
36              
37             Return a hashref representing a ruleset for an HTML::Tidy object.
38              
39             =cut
40              
41             sub tidy_ruleset {
42 0     0 1 0 my $self = shift;
43 0         0 my $tidy_ruleset = {
44             show_body_only => 1,
45             output_xhtml => 1,
46             fix_backslash => 1,
47             fix_uri => 1,
48             numeric_entities => 1,
49             drop_empty_paras => 0,
50             vertical_space => 0,
51             wrap => 0,
52             quote_marks => 1,
53             };
54 0         0 return $tidy_ruleset;
55             }
56              
57             =head2 acceptable_a
58              
59             Return a hashref representing a list of acceptable attributes
60              
61             =cut
62              
63             sub acceptable_a {
64 22     22 1 41 my $self = shift;
65             my @acceptable
66 22         310 = qw(abbr accept accept-charset accesskey action align alt axis border
67             cellpadding cellspacing char charoff charset checked cite class clear
68             cols colspan color compact coords datetime dir disabled enctype for
69             frame headers height href hreflang hspace id ismap label lang longdesc
70             maxlength media method multiple name nohref noshade nowrap prompt
71             readonly rel rev rows rowspan rules scope selected shape size span src
72             start summary tabindex target title type usemap valign value vspace
73             width xml:lang );
74 22         53 my %acceptable = map { ( $_, 1 ) } @acceptable;
  1584         3075  
75 22         242 return \%acceptable;
76             }
77              
78             =head2 acceptable_e
79              
80             Return a hashref representing a list of acceptable elements
81              
82             =cut
83              
84             sub acceptable_e {
85 22     22 1 42 my $self = shift;
86 22         260 my @acceptable = qw(
87             a abbr acronym address area b bdo big blockquote
88             br button caption center cite code col colgroup dd
89             del dfn dir div dl dt em fieldset font form
90             h1 h2 h3 h4 h5 h6 hr i img input ins kbd
91             label legend li map menu ol optgroup option p
92             pre q s samp select small span strike strong
93             sub sup table tbody td textarea tfoot th thead
94             tr tt u ul var wbr
95             );
96 22         48 my %acceptable = map { ( $_, 1 ) } @acceptable;
  1606         2764  
97 22         244 return \%acceptable;
98             }
99              
100             =head2 empty_e
101              
102             Return a hashref representing a list of empty elements
103              
104             =cut
105              
106             sub empty_e {
107 25     25 1 45 my $self = shift;
108             my @empty
109 25         99 = qw( area base basefront br col frame hr img input isindex link meta param );
110 25         49 my %empty = map { ( $_, 1 ) } @empty;
  325         571  
111 25         118 return \%empty;
112             }
113              
114             =head2 unacceptable_e
115              
116             Return a hashref representing a list of unacceptable elements
117              
118             =cut
119              
120             sub unacceptable_e {
121 26     26 1 42 my $self = shift;
122 26         56 my @unacceptable = qw( applet script );
123 26         45 my %unacceptable = map { ( $_, 1 ) } @unacceptable;
  52         133  
124 26         90 return \%unacceptable;
125             }
126              
127             =head2 uri_list
128              
129             Return a hashref representing a list of elements/attribute pairs known to contain
130             hrefs (for rebasing and URI scheme checking)
131              
132             =cut
133              
134             sub uri_list {
135 25     25 1 35 my $self = shift;
136             return {
137 25         500 a => ['href'],
138             applet => ['codebase'],
139             area => ['href'],
140             blockquote => ['cite'],
141             body => ['background'],
142             del => ['cite'],
143             form => ['action'],
144             frame => [ 'longdesc', 'src' ],
145             iframe => [ 'longdesc', 'src' ],
146             img => [ 'longdesc', 'src', 'usemap' ],
147             input => [ 'src', 'usemap' ],
148             ins => ['cite'],
149             link => ['href'],
150             object => [ 'classid', 'codebase', 'data', 'usemap' ],
151             q => ['cite'],
152             script => ['src']
153             };
154             }
155              
156             =head2 allowed_schemes
157              
158             Return an arrayref representing a list of allowed schemas
159              
160             =cut
161              
162             sub allowed_schemes {
163 21     21 1 36 my $self = shift;
164             return {
165 21         613 http => 1,
166             https => 1,
167             afs => 1,
168             aim => 1,
169             callto => 1,
170             #data => 1,
171             ed2k => 1,
172             feed => 1,
173             ftp => 1,
174             gopher => 1,
175             irc => 1,
176             mailto => 1,
177             news => 1,
178             nntp => 1,
179             rsync => 1,
180             rtsp => 1,
181             sftp => 1,
182             ssh => 1,
183             tag => 1,
184             tel => 1,
185             telnet => 1,
186             urn => 1,
187             webcal => 1,
188             wtai => 1,
189             xmpp => 1,
190             };
191             }
192              
193             =head2 finalize_initialization
194              
195             Function allowing transformation of the HTML::Laundry object.
196              
197             =cut
198              
199             sub finalize_initialization {
200 25     25 1 37 my $self = shift;
201 25         33 my $laundry = shift;
202 25         52 return 1;
203             }
204              
205             1;