line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perlanet::Trait::Tidy; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
2227
|
use strict; |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
158
|
|
4
|
6
|
|
|
6
|
|
20
|
use warnings; |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
112
|
|
5
|
|
|
|
|
|
|
|
6
|
6
|
|
|
6
|
|
44
|
use 5.6.0; |
|
6
|
|
|
|
|
15
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.58'; |
8
|
|
|
|
|
|
|
|
9
|
6
|
|
|
6
|
|
20
|
use Moose::Role; |
|
6
|
|
|
|
|
7
|
|
|
6
|
|
|
|
|
31
|
|
10
|
6
|
|
|
6
|
|
19288
|
use namespace::autoclean; |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
36
|
|
11
|
|
|
|
|
|
|
|
12
|
6
|
|
|
6
|
|
271
|
use Encode; |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
402
|
|
13
|
6
|
|
|
6
|
|
2366
|
use HTML::Tidy; |
|
6
|
|
|
|
|
14108
|
|
|
6
|
|
|
|
|
1131
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 NAME |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Perlanet::Trait::Tidy - run posts through HTML::Tidy |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my $perlanet = Perlanet->new_with_traits( |
22
|
|
|
|
|
|
|
traits => [ 'Perlanet::Trait::Tidy' ] |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
$perlanet->run; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 DESCRIPTION |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Before a post is added to the aggregated feed, it will be ran through |
30
|
|
|
|
|
|
|
HTML::Tidy. |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head2 Configuring |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
To configure the HTML::Tidy instance, you should override the C<_build_tidy> |
35
|
|
|
|
|
|
|
method. This method takes no input, and returns a HTML::Tidy instance. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head2 tidy |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
An instance of L<HTML::Tidy> used to tidy the feed entry contents |
42
|
|
|
|
|
|
|
before outputting. For default settings see source.. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=cut |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
has 'tidy' => ( |
47
|
|
|
|
|
|
|
is => 'rw', |
48
|
|
|
|
|
|
|
lazy_build => 1 |
49
|
|
|
|
|
|
|
); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub _build_tidy { |
52
|
0
|
|
|
0
|
|
|
my $self = shift; |
53
|
0
|
|
|
|
|
|
my %tidy = ( |
54
|
|
|
|
|
|
|
doctype => 'omit', |
55
|
|
|
|
|
|
|
output_xhtml => 1, |
56
|
|
|
|
|
|
|
wrap => 0, |
57
|
|
|
|
|
|
|
alt_text => '', |
58
|
|
|
|
|
|
|
break_before_br => 0, |
59
|
|
|
|
|
|
|
char_encoding => 'raw', |
60
|
|
|
|
|
|
|
tidy_mark => 0, |
61
|
|
|
|
|
|
|
show_body_only => 1, |
62
|
|
|
|
|
|
|
preserve_entities => 1, |
63
|
|
|
|
|
|
|
show_warnings => 0, |
64
|
|
|
|
|
|
|
); |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
my $tidy = HTML::Tidy->new(\%tidy); |
67
|
0
|
|
|
|
|
|
$tidy->ignore( type => TIDY_WARNING ); |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
return $tidy; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
around 'clean_html' => sub { |
73
|
|
|
|
|
|
|
my $orig = shift; |
74
|
|
|
|
|
|
|
my ($self, $html) = @_; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
$html = $self->$orig($html); |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
my $clean = $self->tidy->clean(utf8::is_utf8($html) |
79
|
|
|
|
|
|
|
? $html |
80
|
|
|
|
|
|
|
: decode('utf8', $html)); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
return $clean; |
83
|
|
|
|
|
|
|
}; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 AUTHOR |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Oliver Charles, <oliver.g.charles@googlemail.com> |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Copyright (c) 2010 by Magnum Solutions Ltd. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
94
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.10.0 or, |
95
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=cut |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
1; |