blib/lib/Cant.pm

filter: Statementstmt 77.5% 38 / 49 Branchbran 45.0% 9 / 20 Conditioncond 66.6% 8 / 12 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 2 totaltotal 66.3% 63 / 95 CC 15 SCAR 26.0
CC
15
Cov
68%
_cant_fmt
26.0
cant
4.1
wcant
4.1
CRAP 13.5
↑ Summary
1 package Cant;
2  
3 1 require 5.005_62;
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 require Exporter;
10  
11 1 our @ISA = qw(Exporter);
12  
13 # Items to export into callers namespace by default. Note: do not export
14 # names by default without a very good reason. Use EXPORT_OK instead.
15 # Do not simply export all your public functions/methods/constants.
16  
17 # This allows declaration use Cant ':all';
18 # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
19 # will save memory.
20 1 our %EXPORT_TAGS = ( 'all' => [ qw(
21 cant
22 wcant
23 ) ] );
24  
25 1 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
26  
27 1 our @EXPORT = qw(
28 cant
29 wcant
30 );
31 1 our $VERSION = '1.01';
32  
33 #
34 # cant and wcant -- print an error message and optionally die when a
35 # system or library call fails.
36 #
37  
38 6 ▶sub _cant_fmt {
Subroutine _cant_fmt: called CC=9 SCAR=32.6
39 6 my(@pre, @post, $first);
40 6 @pre = "$0: Unable to ";
41 6 $first = shift;
42 6 ▶ if ($first =~ s:^\n::) {
Branch: 1 branch
BranchTrueFalseTotal
if ($first =~ s/^\n//) 0 6 6
43 0 unshift @pre, "\n";
44 }
45 6 unshift @_, $first;
46 6 ▶ if (substr($_[-1], -1, 1) eq "\n") {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($_[-1], -1, 1) eq "\n") { } 0 6 6
47 # Strip the newline
48 0 @post = ( substr( pop @_, 0, -1) );
49 } else {
50 6 ▶ if ($!) {
Branch: 4 branches
BranchTrueFalseTotal
if ($!) { } 0 6 6
elsif ($? >> 8 == 0) { } 6 0 6
elsif (($? & 255) == 0) { } 0 0 0
elsif (($? & 255) == 127) { } 0 0 0
51 # Stick the errno message on the end
52 0 @post = ( ": $!" );
53 } elsif ($?>>8 == 0) {
54 # Do nothing. No errno, no last program return code --
55 # it's kind of ambiguous
56 } elsif (($? & 0377) == 0) {
57 # Error return from program
58 0 @post = ( ": program returned ", $? >> 8 );
59 } elsif (($? & 0377) == 0177) {
60 # 'stopped' return from program
61 0 @post = ( ": program stopped with signal ", $? >> 8 );
62 } else {
63 # Death by signal
64 0 @post = ( ": program died with signal ", $? & 0177 );
65 0 ▶ push @post, ", coredumped" if $? & 0200;
Branch: 1 branch
BranchTrueFalseTotal
if $? & 128 0 0 0
66 }
67 6 my($temp) = $_[0];
68 0 ▶ if ($temp =~ s:\n: join("", @post, "\n") :e) {
Branch: 1 branch
BranchTrueFalseTotal
if ($temp =~ s/\n/join "", @post, "\n";/e) 0 6 6
69 0 shift @_;
70 0 @post = ();
71 0 push @pre, $temp;
72 }
73 }
74 6 (@pre, @_, @post)
75 }
76  
77 3 ▶sub cant {
Subroutine cant: called CC=4 SCAR=14.0
Pod undocumented
78 3 my($package, $file, $line) = caller;
79 3 @_ = &_cant_fmt;
80 3 ▶ if (!defined $package || $package eq "main" || $package eq "") {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $package or $package eq 'main' or $package eq '') { } 1 2 3
Condition66%4/6
not defined $package or $package eq "main" or $package eq ""
l!l&&r!l&&!r
102
not defined $package or $package eq "main"
l!l&&r!l&&!r
012
MC/DC33%1/3
not defined $package or $package eq "main" or $package eq ""
not defined $package $package eq "main" $package eq ""
Truth table50%2/4
not(A) or B or C
A= not defined $packageB= $package eq "main"C= $package eq ""
ABCresult
1XX1
01X1
0011
0000
81 1 die @_, " at $file line $line\n"
82 } else {
83 2 goto &croak
84 }
85 }
86  
87 3 ▶sub wcant {
Subroutine wcant: called CC=4 SCAR=14.0
Pod undocumented
88 3 my($package, $file, $line) = caller;
89 3 @_ = &_cant_fmt;
90 3 ▶ if (!defined $package || $package eq "main" || $package eq "") {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $package or $package eq 'main' or $package eq '') { } 1 2 3
Condition66%4/6
not defined $package or $package eq "main" or $package eq ""
l!l&&r!l&&!r
102
not defined $package or $package eq "main"
l!l&&r!l&&!r
012
MC/DC33%1/3
not defined $package or $package eq "main" or $package eq ""
not defined $package $package eq "main" $package eq ""
Truth table50%2/4
not(A) or B or C
A= not defined $packageB= $package eq "main"C= $package eq ""
ABCresult
1XX1
01X1
0011
0000
91 1 warn @_, " at $file line $line\n"
92 } else {
93 2 goto &carp
94 }
95 }
96  
97 1 1
98 __END__
↑ Summary