| 1 | ## no critic | ||||||||||
| 2 | package Shell::Verbose; | ||||||||||
| 3 | { | ||||||||||
| 4 | 1 | $Shell::Verbose::VERSION = '0.4'; | |||||||||
| 5 | } | ||||||||||
| 6 | ## use critic | ||||||||||
| 7 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 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 | 1 | our (@ISA, @EXPORT_OK); | |||||||||
| 55 | 1 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 56 | 1 | require Exporter; | |||||||||
| 57 | 1 | @ISA = qw/Exporter/; | |||||||||
| 58 | 1 | @EXPORT_OK = qw/verboseSystem vsys/; | |||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | 1 | my $prefix = ''; | |||||||||
| 62 | 1 | my $before = ''; | |||||||||
| 63 | 1 | my $after = ''; | |||||||||
| 64 | |||||||||||
| 65 | 2 | ▶ | sub prefix { | ||||||||
|
Subroutine
prefix: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 66 | 2 | shift; | |||||||||
| 67 | 2 | $prefix = shift; | |||||||||
| 68 | 2 | return $prefix | |||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | 2 | ▶ | sub before { | ||||||||
|
Subroutine
before: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 72 | 2 | shift; | |||||||||
| 73 | 2 | $before = shift; | |||||||||
| 74 | 2 | return $before; | |||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | 2 | ▶ | sub after { | ||||||||
|
Subroutine
after: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 78 | 2 | shift; | |||||||||
| 79 | 2 | $after = shift; | |||||||||
| 80 | 2 | 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 | 7 | ▶ | sub verboseSystem { | ||||||||
|
Subroutine
verboseSystem: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 95 | 7 | my $command = shift; | |||||||||
| 96 | |||||||||||
| 97 | 7 | ▶ | print "$before\n" if ($before); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 98 | 7 | print $prefix . $command . "\n"; | |||||||||
| 99 | 7 | my $ret = (system($command) == 0); | |||||||||
| 100 | 7 | ▶ | print "$after\n" if ($after); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 101 | 7 | return $ret; | |||||||||
| 102 | } | ||||||||||
| 103 | |||||||||||
| 104 | 6 | ▶ | sub vsys { | ||||||||
|
Subroutine
vsys: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 105 | 6 | verboseSystem(@_); | |||||||||
| 106 | } | ||||||||||
| 107 | |||||||||||
| 108 | =head1 SOURCE | ||||||||||
| 109 | |||||||||||
| 110 | L<https://github.com/dinomite/Shell-Verbose> | ||||||||||
| 111 | |||||||||||
| 112 | =head1 AUTHOR | ||||||||||
| 113 | |||||||||||
| 114 | Drew Stephens <drew@dinomite.net> | ||||||||||
| 115 | |||||||||||
| 116 | =cut | ||||||||||
| 117 | |||||||||||
| 118 | 1 | 1; | |||||||||