| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package PPI::Util; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Provides some common utility functions that can be imported |
|
4
|
|
|
|
|
|
|
|
|
5
|
67
|
|
|
67
|
|
333
|
use strict; |
|
|
67
|
|
|
|
|
102
|
|
|
|
67
|
|
|
|
|
1988
|
|
|
6
|
67
|
|
|
67
|
|
276
|
use Exporter (); |
|
|
67
|
|
|
|
|
129
|
|
|
|
67
|
|
|
|
|
995
|
|
|
7
|
67
|
|
|
67
|
|
232
|
use Digest::MD5 (); |
|
|
67
|
|
|
|
|
99
|
|
|
|
67
|
|
|
|
|
1346
|
|
|
8
|
67
|
|
|
67
|
|
19331
|
use Params::Util qw{_INSTANCE _SCALAR0 _ARRAY0}; |
|
|
67
|
|
|
|
|
277219
|
|
|
|
67
|
|
|
|
|
8263
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '1.284'; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @ISA = 'Exporter'; |
|
13
|
|
|
|
|
|
|
our @EXPORT_OK = qw{ _Document _slurp }; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# 5.8.7 was the first version to resolve the notorious |
|
16
|
|
|
|
|
|
|
# "unicode length caching" bug. |
|
17
|
67
|
|
|
67
|
|
418
|
use constant HAVE_UNICODE => !! ( $] >= 5.008007 ); |
|
|
67
|
|
|
|
|
86
|
|
|
|
67
|
|
|
|
|
32728
|
|
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# Common reusable true and false functions |
|
20
|
|
|
|
|
|
|
# This makes it easy to upgrade many places in PPI::XS |
|
21
|
|
|
|
|
|
|
sub TRUE () { 1 } |
|
22
|
|
|
|
|
|
|
sub FALSE () { '' } |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
##################################################################### |
|
29
|
|
|
|
|
|
|
# Functions |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# Allows a sub that takes a L<PPI::Document> to handle the full range |
|
32
|
|
|
|
|
|
|
# of different things, including file names, SCALAR source, etc. |
|
33
|
|
|
|
|
|
|
sub _Document { |
|
34
|
17
|
50
|
|
17
|
|
1899
|
shift if @_ > 1; |
|
35
|
17
|
50
|
|
|
|
27
|
return undef unless defined $_[0]; |
|
36
|
17
|
|
|
|
|
95
|
require PPI::Document; |
|
37
|
17
|
100
|
|
|
|
34
|
return PPI::Document->new(shift) unless ref $_[0]; |
|
38
|
16
|
100
|
|
|
|
55
|
return PPI::Document->new(shift) if _SCALAR0($_[0]); |
|
39
|
10
|
100
|
|
|
|
47
|
return PPI::Document->new(shift) if _ARRAY0($_[0]); |
|
40
|
9
|
100
|
|
|
|
62
|
return shift if _INSTANCE($_[0], 'PPI::Document'); |
|
41
|
2
|
|
|
|
|
6
|
return undef; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# Provide a simple _slurp implementation |
|
45
|
|
|
|
|
|
|
sub _slurp { |
|
46
|
674
|
|
|
674
|
|
2090
|
my $file = shift; |
|
47
|
674
|
|
|
|
|
3093
|
local $/ = undef; |
|
48
|
674
|
|
|
|
|
2080
|
local *FILE; |
|
49
|
674
|
50
|
|
|
|
46078
|
open( FILE, '<', $file ) or return "open($file) failed: $!"; |
|
50
|
674
|
|
|
|
|
49385
|
my $source = <FILE>; |
|
51
|
674
|
50
|
|
|
|
8048
|
close( FILE ) or return "close($file) failed: $!"; |
|
52
|
674
|
|
|
|
|
5389
|
return \$source; |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# Provides a version of Digest::MD5's md5hex that explicitly |
|
56
|
|
|
|
|
|
|
# works on the unix-newlined version of the content. |
|
57
|
|
|
|
|
|
|
sub md5hex { |
|
58
|
335
|
|
|
335
|
0
|
1287
|
my $string = shift; |
|
59
|
335
|
|
|
|
|
187805
|
$string =~ s/(?:\015{1,2}\012|\015|\012)/\015/gs; |
|
60
|
335
|
|
|
|
|
5344
|
Digest::MD5::md5_hex($string); |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# As above but slurps and calculates the id for a file by name |
|
64
|
|
|
|
|
|
|
sub md5hex_file { |
|
65
|
163
|
|
|
163
|
0
|
2069
|
my $file = shift; |
|
66
|
163
|
|
|
|
|
601
|
my $content = _slurp($file); |
|
67
|
163
|
50
|
|
|
|
546
|
return undef unless ref $content; |
|
68
|
163
|
|
|
|
|
93574
|
$$content =~ s/(?:\015{1,2}\012|\015|\012)/\n/gs; |
|
69
|
163
|
|
|
|
|
717
|
md5hex($$content); |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
1; |