line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
21991
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
2
|
1
|
|
|
1
|
|
736
|
use HTML::Manipulator; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
41
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package HTML::Manipulator::Document; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.07'; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
4
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
934
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub from_string { |
11
|
13
|
|
|
13
|
0
|
1907
|
my ( $class, $html ) = @_; |
12
|
13
|
|
|
|
|
51
|
my $self = bless { html => $html }, $class; |
13
|
13
|
|
|
|
|
37
|
return $self; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub from_file { |
17
|
2
|
|
|
2
|
0
|
853
|
my ( $class, $file ) = @_; |
18
|
2
|
|
|
|
|
3
|
my $html; |
19
|
2
|
100
|
66
|
|
|
19
|
if ( UNIVERSAL::isa( $file, 'GLOB' ) or UNIVERSAL::isa( \$file, 'GLOB' ) ) { |
20
|
1
|
|
|
|
|
33
|
$html = join '', <$file>; |
21
|
|
|
|
|
|
|
} else { |
22
|
1
|
|
|
|
|
925
|
require FileHandle; |
23
|
1
|
|
|
|
|
12567
|
my $fh = new FileHandle( $file, 'r' ); |
24
|
1
|
50
|
|
|
|
116
|
croak "could not open the file $file for reading: $!" unless $fh; |
25
|
1
|
|
|
|
|
29
|
$html = join '', <$fh>; |
26
|
1
|
|
|
|
|
10
|
$fh->close; |
27
|
|
|
|
|
|
|
} |
28
|
2
|
|
|
|
|
29
|
return $class->from_string($html); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub as_string { |
32
|
2
|
|
|
2
|
1
|
9
|
my ($self) = @_; |
33
|
2
|
|
|
|
|
16
|
return $self->{html}; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub replace { |
37
|
2
|
|
|
2
|
1
|
18
|
my ( $self, @args ) = @_; |
38
|
2
|
|
|
|
|
13
|
$self->{html} = HTML::Manipulator::replace( $self->{html}, @args ); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub replace_title { |
42
|
1
|
|
|
1
|
0
|
7
|
my ( $self, @args ) = @_; |
43
|
1
|
|
|
|
|
5
|
$self->{html} = HTML::Manipulator::replace_title( $self->{html}, @args ); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub extract { |
47
|
1
|
|
|
1
|
0
|
8
|
my ( $self, @args ) = @_; |
48
|
1
|
|
|
|
|
5
|
HTML::Manipulator::extract( $self->{html}, @args ); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub extract_content { |
52
|
1
|
|
|
1
|
0
|
7
|
my ( $self, @args ) = @_; |
53
|
1
|
|
|
|
|
5
|
HTML::Manipulator::extract_content( $self->{html}, @args ); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub extract_all { |
57
|
0
|
|
|
0
|
0
|
0
|
my ( $self, @args ) = @_; |
58
|
0
|
|
|
|
|
0
|
HTML::Manipulator::extract_all( $self->{html}, @args ); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub extract_all_content { |
62
|
3
|
|
|
3
|
0
|
27
|
my ( $self, @args ) = @_; |
63
|
3
|
|
|
|
|
13
|
HTML::Manipulator::extract_all_content( $self->{html}, @args ); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub extract_all_ids { |
67
|
1
|
|
|
1
|
0
|
5
|
my ( $self, @args ) = @_; |
68
|
1
|
|
|
|
|
6
|
HTML::Manipulator::extract_all_ids( $self->{html}, @args ); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub extract_title { |
72
|
1
|
|
|
1
|
0
|
5
|
my ($self) = @_; |
73
|
1
|
|
|
|
|
5
|
HTML::Manipulator::extract_title( $self->{html} ); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub extract_all_comments { |
77
|
1
|
|
|
1
|
0
|
5
|
my ( $self, @filter ) = @_; |
78
|
1
|
|
|
|
|
9
|
HTML::Manipulator::extract_all_comments( $self->{html}, @filter ); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub insert_before_begin { |
82
|
1
|
|
|
1
|
0
|
7
|
my ( $self, @args ) = @_; |
83
|
1
|
|
|
|
|
5
|
$self->{html} = |
84
|
|
|
|
|
|
|
HTML::Manipulator::insert_before_begin( $self->{html}, @args ); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub insert_after_begin { |
88
|
1
|
|
|
1
|
0
|
6
|
my ( $self, @args ) = @_; |
89
|
1
|
|
|
|
|
4
|
$self->{html} = |
90
|
|
|
|
|
|
|
HTML::Manipulator::insert_after_begin( $self->{html}, @args ); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub insert_before_end { |
94
|
1
|
|
|
1
|
0
|
7
|
my ( $self, @args ) = @_; |
95
|
1
|
|
|
|
|
5
|
$self->{html} = |
96
|
|
|
|
|
|
|
HTML::Manipulator::insert_before_end( $self->{html}, @args ); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub insert_after_end { |
100
|
1
|
|
|
1
|
0
|
6
|
my ( $self, @args ) = @_; |
101
|
1
|
|
|
|
|
7
|
$self->{html} = HTML::Manipulator::insert_after_end( $self->{html}, @args ); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub save_as { |
105
|
1
|
|
|
1
|
1
|
6
|
my ( $self, $filename ) = @_; |
106
|
1
|
|
|
|
|
7
|
require File::Spec; |
107
|
1
|
|
|
|
|
16
|
my (@path) = File::Spec->splitdir($filename); |
108
|
1
|
|
|
|
|
2
|
pop @path; |
109
|
1
|
|
|
|
|
2
|
my $mkdir = ''; |
110
|
1
|
|
|
|
|
3
|
while (@path) { |
111
|
3
|
|
|
|
|
18
|
$mkdir = File::Spec->catfile( $mkdir, shift @path ); |
112
|
3
|
100
|
|
|
|
256
|
mkdir $mkdir unless -e $mkdir; |
113
|
|
|
|
|
|
|
} |
114
|
1
|
|
|
|
|
5
|
require FileHandle; |
115
|
1
|
50
|
|
|
|
6
|
my $fh = new FileHandle( $filename, 'w' ) |
116
|
|
|
|
|
|
|
or croak "failed to open the file $filename for saving HTML: $!"; |
117
|
1
|
|
|
|
|
131
|
print $fh $self->as_string; |
118
|
1
|
|
|
|
|
4
|
$fh->close; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
1; |
122
|
|
|
|
|
|
|
__END__ |