line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package File::Slurper::Shortcuts; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY |
4
|
|
|
|
|
|
|
our $DATE = '2021-08-02'; # DATE |
5
|
|
|
|
|
|
|
our $DIST = 'File-Slurper-Shortcuts'; # DIST |
6
|
|
|
|
|
|
|
our $VERSION = '0.005'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
77243
|
use strict 'subs', 'vars'; |
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
30
|
|
9
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
10
|
1
|
|
|
1
|
|
5
|
no warnings 'once'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
11
|
1
|
|
|
1
|
|
4
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
74
|
|
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
6
|
use File::Slurper (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
15
|
|
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
4
|
use Exporter qw(import); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
183
|
|
16
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
17
|
|
|
|
|
|
|
modify_text |
18
|
|
|
|
|
|
|
modify_binary |
19
|
|
|
|
|
|
|
replace_text |
20
|
|
|
|
|
|
|
replace_binary |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub modify_text { |
24
|
1
|
|
|
1
|
1
|
2487
|
my ($filename, $code, $encoding, $crlf) = @_; |
25
|
|
|
|
|
|
|
|
26
|
1
|
|
|
|
|
4
|
local $_ = File::Slurper::read_text($filename, $encoding, $crlf); |
27
|
1
|
|
|
|
|
90
|
my $orig = $_; |
28
|
|
|
|
|
|
|
|
29
|
1
|
|
|
|
|
3
|
my $res = $code->($_); |
30
|
1
|
50
|
|
|
|
12
|
croak "replace_text(): Code does not return true" unless $res; |
31
|
|
|
|
|
|
|
|
32
|
1
|
50
|
|
|
|
3
|
return if $orig eq $_; |
33
|
|
|
|
|
|
|
|
34
|
1
|
|
|
|
|
6
|
File::Slurper::write_text($filename, $_, $encoding, $crlf); |
35
|
1
|
|
|
|
|
173
|
$orig; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub modify_binary { |
39
|
0
|
|
|
0
|
1
|
|
return modify_text(@_[0,1], 'latin-1'); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# old names, deprecated and will be removed in the future |
43
|
|
|
|
|
|
|
*replace_text = \&modify_text; |
44
|
|
|
|
|
|
|
*replace_binary = \&modify_binary; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
1; |
47
|
|
|
|
|
|
|
# ABSTRACT: Some convenience additions for File::Slurper |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
__END__ |