line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Acme::SList::Utilities; |
2
|
|
|
|
|
|
|
$Acme::SList::Utilities::VERSION = '0.04'; |
3
|
1
|
|
|
1
|
|
631
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
36
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
503
|
use File::Copy; |
|
1
|
|
|
|
|
1916
|
|
|
1
|
|
|
|
|
64
|
|
7
|
1
|
|
|
1
|
|
524
|
use File::Slurp; |
|
1
|
|
|
|
|
9825
|
|
|
1
|
|
|
|
|
681
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
require Exporter; |
10
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
11
|
|
|
|
|
|
|
our @EXPORT = qw(); |
12
|
|
|
|
|
|
|
our @EXPORT_OK = qw(crdir sdate sduration commify target dircopy); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub crdir { |
15
|
0
|
|
|
0
|
0
|
|
my ($path) = @_; |
16
|
|
|
|
|
|
|
|
17
|
0
|
|
|
|
|
|
my $dir = ''; |
18
|
0
|
|
|
|
|
|
for my $elem (split m{[/\\]}xms, $path) { |
19
|
0
|
0
|
|
|
|
|
if ($elem =~ m{\A \s* \z}xms) { |
20
|
0
|
|
|
|
|
|
$! = 33; # Domain error |
21
|
0
|
|
|
|
|
|
return; |
22
|
|
|
|
|
|
|
} |
23
|
0
|
|
|
|
|
|
$dir .= $elem.'/'; |
24
|
0
|
0
|
0
|
|
|
|
if ($elem ne '..' and !-d $dir) { |
25
|
0
|
0
|
|
|
|
|
mkdir $dir or return; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
} |
28
|
0
|
|
|
|
|
|
return 1; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub dircopy { |
32
|
0
|
|
|
0
|
0
|
|
my ($from, $to) = @_; |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
$from =~ s{/+ \z}''xms; |
35
|
0
|
|
|
|
|
|
$to =~ s{/+ \z}''xms; |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
for my $file (read_dir $from) { |
38
|
0
|
0
|
|
|
|
|
copy "$from/$file", "$to/$file" or return; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
return 1; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub sdate { |
45
|
0
|
|
|
0
|
0
|
|
my ($stamp) = @_; |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = localtime $stamp; |
48
|
0
|
|
|
|
|
|
return sprintf("%02d/%02d/%04d %02d:%02d:%02d", |
49
|
|
|
|
|
|
|
$mday, $mon + 1, $year + 1900, $hour, $min, $sec); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub sduration { # calculate a duration ($_[0]...$_[1]) |
53
|
0
|
|
|
0
|
0
|
|
my ($from, $to) = @_; |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
my $tsec = $to - $from; my $sec = $tsec % 60; |
|
0
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
my $tmin = int($tsec / 60); my $min = $tmin % 60; |
|
0
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
my $thour = int($tmin / 60); my $hour = $thour; |
|
0
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
my $dur = "$sec sec"; |
60
|
0
|
0
|
|
|
|
|
$dur = "$min min ".$dur unless $min == 0; |
61
|
0
|
0
|
|
|
|
|
$dur = "$hour hrs ".$dur unless $hour == 0; |
62
|
0
|
|
|
|
|
|
return $dur; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub commify { |
66
|
0
|
|
|
0
|
0
|
|
my ($number) = @_; |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
1 while $number =~ s/^([-+]?\d+)(\d{3})/$1_$2/; |
69
|
0
|
|
|
|
|
|
$number =~ s/\./,/; |
70
|
0
|
|
|
|
|
|
return $number; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub target { |
74
|
0
|
|
|
0
|
0
|
|
my ($Program) = @_; |
75
|
|
|
|
|
|
|
|
76
|
0
|
0
|
0
|
|
|
|
if (defined($ENV{'SL_Target'}) and $ENV{'SL_Target'} ne '') { |
77
|
0
|
|
|
|
|
|
my $sl_target = lc $ENV{'SL_Target'}; |
78
|
0
|
0
|
|
|
|
|
if ($sl_target !~ m{\A [0-9a-z]{0,4} \z}xms) { |
79
|
0
|
|
|
|
|
|
die "Variable SL_Target: '$sl_target' contains non-alphanumeric characters or is more than 4 characters long"; |
80
|
|
|
|
|
|
|
} |
81
|
0
|
|
|
|
|
|
return "SList-$Program-$sl_target"; |
82
|
|
|
|
|
|
|
} |
83
|
0
|
|
|
|
|
|
return "SList-$Program"; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
1; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
__END__ |