line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::WRT::FileIO; |
2
|
|
|
|
|
|
|
|
3
|
9
|
|
|
9
|
|
101542
|
use strict; |
|
9
|
|
|
|
|
24
|
|
|
9
|
|
|
|
|
258
|
|
4
|
9
|
|
|
9
|
|
43
|
use warnings; |
|
9
|
|
|
|
|
13
|
|
|
9
|
|
|
|
|
228
|
|
5
|
9
|
|
|
9
|
|
493
|
use open qw(:std :utf8); |
|
9
|
|
|
|
|
1318
|
|
|
9
|
|
|
|
|
45
|
|
6
|
|
|
|
|
|
|
|
7
|
9
|
|
|
9
|
|
1018
|
use Carp; |
|
9
|
|
|
|
|
28
|
|
|
9
|
|
|
|
|
404
|
|
8
|
9
|
|
|
9
|
|
684
|
use Encode; |
|
9
|
|
|
|
|
10421
|
|
|
9
|
|
|
|
|
535
|
|
9
|
9
|
|
|
9
|
|
4600
|
use File::Copy; |
|
9
|
|
|
|
|
21860
|
|
|
9
|
|
|
|
|
618
|
|
10
|
9
|
|
|
9
|
|
69
|
use File::Path qw(make_path); |
|
9
|
|
|
|
|
14
|
|
|
9
|
|
|
|
|
503
|
|
11
|
9
|
|
|
9
|
|
654
|
use Data::Dumper; |
|
9
|
|
|
|
|
6423
|
|
|
9
|
|
|
|
|
404
|
|
12
|
9
|
|
|
9
|
|
403
|
use App::WRT::Util; |
|
9
|
|
|
|
|
10
|
|
|
9
|
|
|
|
|
3555
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=pod |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 NAME |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
App::WRT::FileIO - read and write directories and files |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 SYNOPSIS |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
use App::WRT::FileIO; |
23
|
|
|
|
|
|
|
my $io = App::WRT::FileIO->new(); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 METHODS |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=over |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=item new($class) |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Get a new FileIO object. |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=cut |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub new { |
36
|
3
|
|
|
3
|
1
|
122
|
my $class = shift; |
37
|
|
|
|
|
|
|
|
38
|
3
|
|
|
|
|
12
|
my %params = ( |
39
|
|
|
|
|
|
|
last_error => '', |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
|
42
|
3
|
|
|
|
|
7
|
my $self = \%params; |
43
|
3
|
|
|
|
|
16
|
bless $self, $class; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=item dir_list($dir, $sort_order, $pattern) |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
Return a $sort_order sorted list of files matching regex $pattern in a |
49
|
|
|
|
|
|
|
directory. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Calls $sort_order, which can be one of: |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
alpha - alphabetical |
54
|
|
|
|
|
|
|
reverse_alpha - alphabetical, reversed |
55
|
|
|
|
|
|
|
high_to_low - numeric, high to low |
56
|
|
|
|
|
|
|
low_to_high - numeric, low to high |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=cut |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub dir_list { |
61
|
1
|
|
|
1
|
1
|
5
|
my $self = shift; |
62
|
1
|
|
|
|
|
5
|
return App::WRT::Util::dir_list(@_); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# Various named sorts for dir_list: |
66
|
0
|
|
|
0
|
0
|
0
|
sub alpha { $a cmp $b; } # alphabetical |
67
|
0
|
|
|
0
|
0
|
0
|
sub high_to_low { $b <=> $a; } # numeric, high to low |
68
|
0
|
|
|
0
|
0
|
0
|
sub low_to_high { $a <=> $b; } # numberic, low to high |
69
|
0
|
|
|
0
|
0
|
0
|
sub reverse_alpha { $b cmp $a; } # alphabetical, reversed |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=item file_put_contents($file, $contents) |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Write $contents string to $file path. Because: |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
L |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=cut |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub file_put_contents { |
81
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
82
|
0
|
|
|
|
|
0
|
App::WRT::Util::file_put_contents(@_); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=item file_get_contents($file) |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Get contents string of $file path. Because: |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
L |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=cut |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub file_get_contents { |
95
|
1
|
|
|
1
|
1
|
510
|
my $self = shift; |
96
|
1
|
|
|
|
|
6
|
return App::WRT::Util::file_get_contents(@_); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=item file_copy($source, $dest) |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=cut |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub file_copy { |
105
|
0
|
|
|
0
|
1
|
|
my ($self, $source, $dest) = @_; |
106
|
0
|
|
|
|
|
|
copy($source, $dest); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=item dir_make($source, $dest) |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=cut |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub dir_make { |
115
|
0
|
|
|
0
|
1
|
|
my ($self, $path) = @_; |
116
|
0
|
|
|
|
|
|
my $path_err; |
117
|
0
|
|
|
|
|
|
make_path($path, { error => \$path_err }); |
118
|
0
|
0
|
|
|
|
|
if (@{ $path_err }) { |
|
0
|
|
|
|
|
|
|
119
|
0
|
|
|
|
|
|
$self->{last_error} = Dumper($path_err); |
120
|
0
|
|
|
|
|
|
return 0; |
121
|
|
|
|
|
|
|
} |
122
|
0
|
|
|
|
|
|
return 1; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=back |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=cut |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
1; |