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