blib/lib/Devel/System.pm

filter: Statementstmt 100% 24 / 24 Branchbran 100% 6 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 100% 35 / 35 CC 5 SCAR 8.5
CC
5
Cov
100%
__ANON__
3.0
import
3.0
BEGIN
1.0
CRAP 2.3
↑ Summary
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package Devel::System;
3 1 ▶use String::ShellQuote qw( shell_quote );
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 our $VERSION = '0.01';
6  
7 =head1 NAME
8  
9 Devel::System - intercept calls to C<system> to add extra diagnostics
10  
11 =head1 SYNOPSIS
12  
13 use Devel::System;
14 $Devel::System::dry_run = 1; # don't really do it
15  
16 system qw( rm -rf / );
17  
18 or from the command line:
19  
20 perl -MDevel::System=dry_run -e'system qw( rm -rf / )'
21  
22 =head1 DESCRIPTION
23  
24 Devel::System hooks the system builtin to add diagnostic output about
25 what system calls are being made. It's like the -x switch for /bin/sh
26 all over again.
27  
28 =head2 Variables
29  
30 The behaviour of the substitued C<system> builtin can be swayed by the
31 following package variables in the C<Devel::System> namespace
32  
33 =over
34  
35 =item $dry_run
36  
37 Don't actually perform the command. Always returns $return
38  
39 =cut
40  
41 1 our $dry_run;
42  
43  
44 =item $return
45  
46 The return value to use when $dry_run is active. Defaults to 0
47  
48 =cut
49  
50 1 our $return = 0;
51  
52  
53 =item $fh
54  
55 The filehandle to print the diagnostics to. Defaults to \*STDERR
56  
57 =back
58  
59 =cut
60  
61 1 our $fh = \*STDERR;
62  
63 5 ▶*CORE::GLOBAL::system = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
64 5 ▶ print $fh "+ ", @_ > 1 ? shell_quote(@_) : @_, "\n";
Branch: 1 branch
BranchTrueFalseTotal
@_ > 1 ? : 1 4 5
65 5 ▶ return $return if $dry_run;
Branch: 1 branch
BranchTrueFalseTotal
if $Devel::System::dry_run 4 1 5
66  
67 1 return CORE::system @_;
68 1 };
69  
70  
71 =head2 Options
72  
73 In addition there are the following import symbols that you can use to
74 set options from the commands line.
75  
76 =over
77  
78 =item dry_run
79  
80 Sets $dry_run to a true value.
81  
82 =back
83  
84 =cut
85  
86  
87 3 ▶sub import {
Subroutine import: called CC=3 SCAR=11.0
88 3 my $class = shift;
89 3 for (@_) {
90 2 ▶ /^dry_run$/ and do { $dry_run = 1; next };
Branch: 1 branch
BranchTrueFalseTotal
/^dry_run$/ and do { $dry_run = 1; next } 1 1 2
91 1 croak "unknown option '$_'";
92 }
93 }
94  
95 1 1;
96 __END__
↑ Summary