line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package UTF8BOM; |
2
|
2
|
|
|
2
|
|
31931
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
70
|
|
3
|
|
|
|
|
|
|
|
4
|
2
|
|
|
2
|
|
1933
|
use IO::File; |
|
2
|
|
|
|
|
25234
|
|
|
2
|
|
|
|
|
317
|
|
5
|
2
|
|
|
2
|
|
2107
|
use IO::Dir; |
|
2
|
|
|
|
|
41234
|
|
|
2
|
|
|
|
|
116
|
|
6
|
2
|
|
|
2
|
|
20
|
use File::Spec; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
108
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '1.02'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my $BOM = "\x{ef}\x{bb}\x{bf}"; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub check_bom { |
13
|
2
|
|
|
2
|
|
1286
|
use bytes; |
|
2
|
|
|
|
|
14
|
|
|
2
|
|
|
|
|
16
|
|
14
|
2
|
|
|
2
|
1
|
431
|
my($class, $str) = @_; |
15
|
2
|
100
|
|
|
|
18
|
return ($BOM eq substr($str, 0, length($BOM))) |
16
|
|
|
|
|
|
|
? 1 : 0; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub remove_from_str { |
20
|
0
|
|
|
0
|
1
|
|
my($class, $str) = @_; |
21
|
0
|
0
|
|
|
|
|
return $class->check_bom($str) |
22
|
|
|
|
|
|
|
? return substr($str, length($BOM)) |
23
|
|
|
|
|
|
|
: $str; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub insert_into_str { |
27
|
0
|
|
|
0
|
1
|
|
my($class, $str) = @_; |
28
|
0
|
0
|
|
|
|
|
return $class->check_bom($str) |
29
|
|
|
|
|
|
|
? $str |
30
|
|
|
|
|
|
|
: $BOM.$str; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub remove_from_file { |
34
|
0
|
|
|
0
|
1
|
|
my($class, $file) = @_; |
35
|
0
|
0
|
|
|
|
|
my $fh = IO::File->new($file) |
36
|
|
|
|
|
|
|
or $class->_croak(qq/Couldn't open file "$file"./); |
37
|
0
|
|
|
|
|
|
my @lines = $fh->getlines; |
38
|
0
|
|
|
|
|
|
$fh->close; |
39
|
0
|
|
|
|
|
|
my $str = $class->remove_from_str( join("", @lines) ); |
40
|
0
|
0
|
|
|
|
|
$fh = IO::File->new($file, "w") |
41
|
|
|
|
|
|
|
or $class->_croak(qq/Couldn't open file "$file"./); |
42
|
0
|
|
|
|
|
|
$fh->print($str); |
43
|
0
|
|
|
|
|
|
$fh->close; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub insert_into_file { |
47
|
0
|
|
|
0
|
1
|
|
my($class, $file) = @_; |
48
|
0
|
0
|
|
|
|
|
my $fh = IO::File->new($file) |
49
|
|
|
|
|
|
|
or $class->_croak(qq/Couldn't open file "$file"./); |
50
|
0
|
|
|
|
|
|
my @lines = $fh->getlines; |
51
|
0
|
|
|
|
|
|
$fh->close; |
52
|
0
|
|
|
|
|
|
my $str = $class->insert_into_str( join("", @lines) ); |
53
|
0
|
0
|
|
|
|
|
$fh = IO::File->new($file, "w") |
54
|
|
|
|
|
|
|
or $class->_croak(qq/Couldn't open file "$file"./); |
55
|
0
|
|
|
|
|
|
$fh->print($str); |
56
|
0
|
|
|
|
|
|
$fh->close; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub remove_from_files { |
60
|
0
|
|
|
0
|
1
|
|
my($class, %options) = @_; |
61
|
0
|
|
0
|
|
|
|
my $dir = $options{dir} || File::Spec->curdir; |
62
|
0
|
|
0
|
|
|
|
my $recursive = $options{recursive} || 0; |
63
|
0
|
0
|
|
|
|
|
my $dh = IO::Dir->new($dir) |
64
|
|
|
|
|
|
|
or $class->_croak(qq/Couldn't open directory "$dir"./); |
65
|
0
|
|
|
|
|
|
while( defined( my $file = $dh->read ) ) { |
66
|
0
|
0
|
0
|
|
|
|
next if($file eq '.' || $file eq '..'); |
67
|
0
|
|
|
|
|
|
my $path = File::Spec->catfile($dir, $file); |
68
|
0
|
0
|
0
|
|
|
|
if (-e $path && -f $path) { |
|
|
0
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
69
|
0
|
|
|
|
|
|
$class->remove_from_file($path); |
70
|
|
|
|
|
|
|
} elsif (-e $path && -d $path && $recursive) { |
71
|
0
|
|
|
|
|
|
$class->remove_from_files( |
72
|
|
|
|
|
|
|
dir => $path, |
73
|
|
|
|
|
|
|
recursive => 1, |
74
|
|
|
|
|
|
|
); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
0
|
|
|
|
|
|
$dh->close; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub insert_into_files { |
81
|
0
|
|
|
0
|
1
|
|
my($class, %options) = @_; |
82
|
0
|
|
0
|
|
|
|
my $dir = $options{dir} || File::Spec->curdir; |
83
|
0
|
|
0
|
|
|
|
my $recursive = $options{recursive} || 0; |
84
|
0
|
0
|
|
|
|
|
my $dh = IO::Dir->new($dir) |
85
|
|
|
|
|
|
|
or $class->_croak(qq/Coundn't open directory "$dir"./); |
86
|
0
|
|
|
|
|
|
while( defined( my $file = $dh->read ) ) { |
87
|
0
|
0
|
0
|
|
|
|
next if($file eq '.' || $file eq '..'); |
88
|
0
|
|
|
|
|
|
my $path = File::Spec->catfile($dir, $file); |
89
|
0
|
0
|
0
|
|
|
|
if (-e $path && -f $path) { |
|
|
0
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
90
|
0
|
|
|
|
|
|
$class->insert_into_file($path); |
91
|
|
|
|
|
|
|
} elsif (-e $path && -d $path && $recursive) { |
92
|
0
|
|
|
|
|
|
$class->insert_into_files( |
93
|
|
|
|
|
|
|
dir => $path, |
94
|
|
|
|
|
|
|
recursive => 1, |
95
|
|
|
|
|
|
|
); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
0
|
|
|
|
|
|
$dh->close; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub _croak { |
102
|
0
|
|
|
0
|
|
|
my($self, $msg) = @_; |
103
|
0
|
|
|
|
|
|
require Carp; Carp::croak($msg); |
|
0
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
1; |
107
|
|
|
|
|
|
|
__END__ |