line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
## no critic |
2
|
|
|
|
|
|
|
package Shell::Verbose; |
3
|
|
|
|
|
|
|
{ |
4
|
|
|
|
|
|
|
$Shell::Verbose::VERSION = '0.4'; |
5
|
|
|
|
|
|
|
} |
6
|
|
|
|
|
|
|
## use critic |
7
|
1
|
|
|
1
|
|
120083
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
82
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Shell::Verbose - A verbose version of system() |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 SYNOPSIS |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# Nothing is exported by default |
17
|
|
|
|
|
|
|
use Shell::Verbose qw/verboseSystem vsys/; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
verboseSystem('echo "foo"'); |
20
|
|
|
|
|
|
|
# echo "foo" |
21
|
|
|
|
|
|
|
# foo |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# Short form |
24
|
|
|
|
|
|
|
vsys('echo "foo"'); |
25
|
|
|
|
|
|
|
# echo "foo" |
26
|
|
|
|
|
|
|
# foo |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# Returns a true value when the command is successful |
29
|
|
|
|
|
|
|
print "How did true fail!?\n" unless (vsys('true'); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Shell::Verbose->prefix('===> '); |
32
|
|
|
|
|
|
|
# ===> echo 'foo' |
33
|
|
|
|
|
|
|
# foo |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
Shell::Verbose->before('Running the next line'); |
36
|
|
|
|
|
|
|
# Running the next line |
37
|
|
|
|
|
|
|
# ===> echo 'foo' |
38
|
|
|
|
|
|
|
# foo |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
Shell::Verbose->after('That was easy'); |
41
|
|
|
|
|
|
|
# Running the next line |
42
|
|
|
|
|
|
|
# ===> echo 'foo' |
43
|
|
|
|
|
|
|
# foo |
44
|
|
|
|
|
|
|
# That was easy |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 DESCRIPTION |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
A simple wrapper for system() that prints the command |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 METHODS |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=cut |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
our (@ISA, @EXPORT_OK); |
55
|
|
|
|
|
|
|
BEGIN { |
56
|
1
|
|
|
1
|
|
5
|
require Exporter; |
57
|
1
|
|
|
|
|
16
|
@ISA = qw/Exporter/; |
58
|
1
|
|
|
|
|
250
|
@EXPORT_OK = qw/verboseSystem vsys/; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
my $prefix = ''; |
62
|
|
|
|
|
|
|
my $before = ''; |
63
|
|
|
|
|
|
|
my $after = ''; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub prefix { |
66
|
2
|
|
|
2
|
0
|
5435
|
shift; |
67
|
2
|
|
|
|
|
16
|
$prefix = shift; |
68
|
2
|
|
|
|
|
30
|
return $prefix |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub before { |
72
|
2
|
|
|
2
|
0
|
2304
|
shift; |
73
|
2
|
|
|
|
|
13
|
$before = shift; |
74
|
2
|
|
|
|
|
8
|
return $before; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub after { |
78
|
2
|
|
|
2
|
0
|
2073
|
shift; |
79
|
2
|
|
|
|
|
10
|
$after = shift; |
80
|
2
|
|
|
|
|
128
|
return $after; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head2 verboseSystem($command) |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Run the specified command, printing the command along with before, prefix, |
86
|
|
|
|
|
|
|
and after if defined. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Returns the inverse of shell success, that is a true value (1) if the command |
89
|
|
|
|
|
|
|
exited with zero status (success) and a false value (0) if the command exited |
90
|
|
|
|
|
|
|
with a non-zero status (failure). See $? ($CHILD_ERROR) for the real deets. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=cut |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub verboseSystem { |
95
|
7
|
|
|
7
|
1
|
1827
|
my $command = shift; |
96
|
|
|
|
|
|
|
|
97
|
7
|
100
|
|
|
|
84
|
print "$before\n" if ($before); |
98
|
7
|
|
|
|
|
624
|
print $prefix . $command . "\n"; |
99
|
7
|
|
|
|
|
65873
|
my $ret = (system($command) == 0); |
100
|
7
|
100
|
|
|
|
190
|
print "$after\n" if ($after); |
101
|
7
|
|
|
|
|
417
|
return $ret; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub vsys { |
105
|
6
|
|
|
6
|
0
|
19221
|
verboseSystem(@_); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 SOURCE |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
L |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 AUTHOR |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Drew Stephens |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=cut |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
1; |