line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/env perl |
2
|
|
|
|
|
|
|
# ABSTRACT: output HTML document as a flat XPath/content list |
3
|
|
|
|
|
|
|
# PODNAME: xpathify |
4
|
31
|
|
|
31
|
|
1430
|
use 5.010; |
|
31
|
|
|
|
|
232
|
|
|
31
|
|
|
|
|
1797
|
|
5
|
31
|
|
|
31
|
|
229
|
use strict; |
|
31
|
|
|
|
|
47
|
|
|
31
|
|
|
|
|
1351
|
|
6
|
31
|
|
|
31
|
|
44699
|
use utf8::all; |
|
31
|
|
|
|
|
3041149
|
|
|
31
|
|
|
|
|
254
|
|
7
|
31
|
|
|
31
|
|
279169
|
use warnings qw(all); |
|
31
|
|
|
|
|
84
|
|
|
31
|
|
|
|
|
1384
|
|
8
|
|
|
|
|
|
|
|
9
|
31
|
|
|
31
|
|
152
|
use Carp qw(croak); |
|
31
|
|
|
|
|
56
|
|
|
31
|
|
|
|
|
2211
|
|
10
|
31
|
|
|
31
|
|
175
|
use Encode; |
|
31
|
|
|
|
|
1166
|
|
|
31
|
|
|
|
|
3335
|
|
11
|
31
|
|
|
31
|
|
60194
|
use Getopt::Long; |
|
31
|
|
|
|
|
682241
|
|
|
31
|
|
|
|
|
305
|
|
12
|
31
|
|
|
31
|
|
33538
|
use HTML::Linear; |
|
31
|
|
|
|
|
142
|
|
|
31
|
|
|
|
|
421
|
|
13
|
31
|
|
|
31
|
|
52525
|
use HTTP::Tiny; |
|
31
|
|
|
|
|
2405050
|
|
|
31
|
|
|
|
|
2581
|
|
14
|
31
|
|
|
31
|
|
49848
|
use IO::Interactive qw(is_interactive); |
|
31
|
|
|
|
|
195643
|
|
|
31
|
|
|
|
|
229
|
|
15
|
31
|
|
|
31
|
|
46546
|
use Pod::Usage; |
|
31
|
|
|
|
|
1712156
|
|
|
31
|
|
|
|
|
152013
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
## no critic (ProhibitPackageVars) |
18
|
|
|
|
|
|
|
|
19
|
31
|
|
|
|
|
116
|
our $VERSION = '0.019'; # VERSION |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
31
|
100
|
|
|
|
317
|
GetOptions( |
23
|
|
|
|
|
|
|
q(help) => \my $help, |
24
|
|
|
|
|
|
|
q(color!) => \my $color, |
25
|
|
|
|
|
|
|
q(16) => \my $sixteen, |
26
|
|
|
|
|
|
|
q(html!) => \my $html, |
27
|
|
|
|
|
|
|
q(encoding=s) => \my $encoding, |
28
|
|
|
|
|
|
|
q(shrink!) => \my $shrink, |
29
|
|
|
|
|
|
|
q(strict!) => \my $strict, |
30
|
|
|
|
|
|
|
q(weight!) => \my $weight, |
31
|
|
|
|
|
|
|
) or pod2usage(q(-verbose) => 1); |
32
|
30
|
100
|
100
|
|
|
30847
|
pod2usage(q(-verbose) => 1) |
33
|
|
|
|
|
|
|
if $help or $#ARGV != 0; |
34
|
|
|
|
|
|
|
|
35
|
28
|
|
66
|
|
|
194
|
$color //= is_interactive(*STDOUT); |
36
|
28
|
|
100
|
|
|
371
|
$weight //= 0; |
37
|
|
|
|
|
|
|
|
38
|
28
|
100
|
|
|
|
150
|
if ($html) { |
|
|
100
|
|
|
|
|
|
39
|
8
|
|
|
|
|
18
|
(%HTML::Linear::Path::xpath_wrap) = (%{$HTML::Linear::Path::Colors::scheme{html}}); |
|
8
|
|
|
|
|
129
|
|
40
|
8
|
|
|
|
|
32
|
$color = 0; |
41
|
8
|
|
|
|
|
130
|
print $HTML::Linear::Path::Colors::html[0]; |
42
|
|
|
|
|
|
|
} elsif ($color) { |
43
|
10
|
100
|
100
|
|
|
23
|
(%HTML::Linear::Path::xpath_wrap) = (%{$HTML::Linear::Path::Colors::scheme{($sixteen // 0) ? q(terminal) : q(terminal256)}}); |
|
10
|
|
|
|
|
226
|
|
44
|
10
|
|
|
|
|
40
|
$html = 0; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
28
|
|
|
|
|
382
|
my $hl = HTML::Linear->new; |
48
|
|
|
|
|
|
|
|
49
|
28
|
100
|
100
|
|
|
2080
|
$hl->set_shrink |
50
|
|
|
|
|
|
|
if $shrink // 1; |
51
|
|
|
|
|
|
|
|
52
|
28
|
100
|
100
|
|
|
12448
|
$hl->set_strict |
53
|
|
|
|
|
|
|
if $strict // 0; |
54
|
|
|
|
|
|
|
|
55
|
28
|
100
|
|
|
|
8030
|
my $encoding_layer = ':' . ($encoding ? "encoding($encoding)" : 'utf8'); |
56
|
28
|
50
|
|
|
|
467
|
if ($ARGV[0] =~ m{^https?://}x) { |
|
|
50
|
|
|
|
|
|
57
|
0
|
|
|
|
|
0
|
my $res = HTTP::Tiny->new->get($ARGV[0]); |
58
|
0
|
0
|
|
|
|
0
|
croak "Can't download $ARGV[0]: " . $res->{reason} unless $res->{success}; |
59
|
0
|
|
0
|
|
|
0
|
$hl->parse_content(decode($encoding || 'utf8', $res->{content})); |
60
|
|
|
|
|
|
|
} elsif ($ARGV[0] eq '-') { |
61
|
0
|
|
|
|
|
0
|
binmode(\*STDIN, $encoding_layer); |
62
|
0
|
|
|
|
|
0
|
$hl->parse_file(\*STDIN); |
63
|
|
|
|
|
|
|
} else { |
64
|
28
|
100
|
|
|
|
2527
|
open(my $fh, '<' . $encoding_layer, $ARGV[0]) |
65
|
|
|
|
|
|
|
or croak "Can't open $ARGV[0]: $!"; |
66
|
27
|
|
|
|
|
1127
|
$hl->parse_file($fh); |
67
|
27
|
|
|
|
|
1574
|
close $fh; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
27
|
|
|
|
|
193
|
scan($hl); |
71
|
|
|
|
|
|
|
|
72
|
27
|
100
|
|
|
|
0
|
print $HTML::Linear::Path::Colors::html[1] |
73
|
|
|
|
|
|
|
if $html; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub scan { |
76
|
27
|
|
|
27
|
|
90
|
my ($tree) = @_; |
77
|
27
|
|
|
|
|
215
|
for my $el ($tree->as_list) { |
78
|
119
|
|
|
|
|
523
|
my $hash = $el->as_hash; |
79
|
119
|
|
|
|
|
188
|
for (sort keys %{$hash}) { |
|
119
|
|
|
|
|
558
|
|
80
|
37
|
|
|
|
|
103
|
my @line; |
81
|
37
|
100
|
|
|
|
211
|
if ($html) { |
|
|
100
|
|
|
|
|
|
82
|
8
|
|
|
|
|
59
|
push @line, HTML::Linear::Path::Colors::wrap_xpath($_); |
83
|
8
|
|
|
|
|
66
|
$hash->{$_} = HTML::Linear::Path::Colors::wrap_content($hash->{$_}, 1); |
84
|
|
|
|
|
|
|
} elsif ($color) { |
85
|
9
|
|
|
|
|
30
|
push @line, $_; |
86
|
9
|
|
|
|
|
70
|
$hash->{$_} = HTML::Linear::Path::Colors::wrap_content($hash->{$_}); |
87
|
|
|
|
|
|
|
} else { |
88
|
20
|
|
|
|
|
49
|
push @line, $_; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
37
|
100
|
|
|
|
198
|
push @line, $el->weight if $weight; |
92
|
37
|
|
|
|
|
135
|
push @line, $hash->{$_}; |
93
|
37
|
100
|
|
|
|
124
|
if ($html) { |
94
|
8
|
|
|
|
|
133
|
say ' |
' . join(' | ', @line) . ' |
';
95
|
|
|
|
|
|
|
} else { |
96
|
29
|
|
|
|
|
542
|
say join("\t", @line); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
27
|
|
|
|
|
103
|
return; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
__END__ |