line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::SCM::Digest::Utils; |
2
|
|
|
|
|
|
|
|
3
|
9
|
|
|
9
|
|
55
|
use strict; |
|
9
|
|
|
|
|
17
|
|
|
9
|
|
|
|
|
253
|
|
4
|
9
|
|
|
9
|
|
44
|
use warnings; |
|
9
|
|
|
|
|
17
|
|
|
9
|
|
|
|
|
230
|
|
5
|
|
|
|
|
|
|
|
6
|
9
|
|
|
9
|
|
4572
|
use File::Temp; |
|
9
|
|
|
|
|
157599
|
|
|
9
|
|
|
|
|
686
|
|
7
|
|
|
|
|
|
|
|
8
|
9
|
|
|
9
|
|
78
|
use base qw(Exporter); |
|
9
|
|
|
|
|
17
|
|
|
9
|
|
|
|
|
3652
|
|
9
|
|
|
|
|
|
|
our @EXPORT_OK = qw(system_ad system_ad_op slurp); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub slurp |
12
|
|
|
|
|
|
|
{ |
13
|
11
|
|
|
11
|
0
|
398
|
my ($path) = @_; |
14
|
|
|
|
|
|
|
|
15
|
11
|
|
|
|
|
854
|
open my $fh, '<', $path; |
16
|
11
|
|
|
|
|
63
|
my @lines; |
17
|
11
|
|
|
|
|
337
|
while (my $line = <$fh>) { |
18
|
284
|
|
|
|
|
864
|
push @lines, $line; |
19
|
|
|
|
|
|
|
} |
20
|
11
|
|
|
|
|
157
|
close $fh; |
21
|
11
|
|
|
|
|
205
|
return join '', @lines; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub _system_ad |
25
|
|
|
|
|
|
|
{ |
26
|
88
|
|
|
88
|
|
349
|
my ($cmd, $ft) = @_; |
27
|
|
|
|
|
|
|
|
28
|
88
|
|
|
|
|
1059213
|
my $res = system("$cmd"); |
29
|
88
|
100
|
|
|
|
1753
|
if ($res != 0) { |
30
|
11
|
|
|
|
|
125
|
my $extra = ''; |
31
|
11
|
50
|
|
|
|
251
|
if ($ft) { |
32
|
11
|
|
|
|
|
372
|
my $content = slurp($ft->filename()); |
33
|
11
|
|
|
|
|
57
|
chomp $content; |
34
|
11
|
|
|
|
|
77
|
$extra = " ($content)"; |
35
|
|
|
|
|
|
|
} |
36
|
11
|
|
|
|
|
515
|
die "Command ($cmd) failed: $res$extra"; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
77
|
|
|
|
|
2652
|
return 1; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub system_ad |
43
|
|
|
|
|
|
|
{ |
44
|
80
|
|
|
80
|
1
|
23280
|
my ($cmd) = @_; |
45
|
|
|
|
|
|
|
|
46
|
80
|
|
|
|
|
1004
|
my $ft = File::Temp->new(); |
47
|
80
|
|
|
|
|
47795
|
my $redirect = '>'.$ft->filename(); |
48
|
|
|
|
|
|
|
|
49
|
80
|
|
|
|
|
1402
|
return _system_ad("$cmd $redirect 2>&1", $ft); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub system_ad_op |
53
|
|
|
|
|
|
|
{ |
54
|
8
|
|
|
8
|
1
|
6077
|
my ($cmd) = @_; |
55
|
|
|
|
|
|
|
|
56
|
8
|
|
|
|
|
96
|
return _system_ad("$cmd 2>&1"); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
__END__ |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 NAME |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
App::SCM::Digest::Utils |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 DESCRIPTION |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
Utility functions for use with L<App::SCM::Digest> modules. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 PUBLIC FUNCTIONS |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=over 4 |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=item B<system_ad> |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Takes a system command as its single argument. Executes that command, |
78
|
|
|
|
|
|
|
suppressing C<stdout> and C<stderr>. Dies if the command returns a |
79
|
|
|
|
|
|
|
non-zero exit status, and returns a true value otherwise. (The name |
80
|
|
|
|
|
|
|
is short for 'system autodie'.) |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=item B<system_ad_op> |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
As per C<system_ad>, except that C<stdout> and C<stderr> are merged, |
85
|
|
|
|
|
|
|
and not suppressed. (The name is short for 'system autodie output'.) |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=back |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=cut |