blib/lib/Doit/Guarded.pm

filter: Statementstmt 100% 29 / 29 Branchbran 100% 8 / 8 Conditioncond 66.6% 4 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 5 totaltotal 81.6% 49 / 60 SCAR 19.5
CC
7
Cov
95%
guarded_step
7.0
BEGIN
1.0
BEGIN
1.0
CRAP 7.0
« blib/lib/Doit/Pip.pm ↑ Summary blib/lib/Doit/Extcmd.pm »
1 # -*- perl -*-
2  
3 #
4 # Author: Slaven Rezic
5 #
6 # Copyright (C) 2017,2018 Slaven Rezic. All rights reserved.
7 # This package is free software; you can redistribute it and/or
8 # modify it under the same terms as Perl itself.
9 #
10 # Mail: slaven@rezic.de
11 # WWW: http://www.rezic.de/eserte/
12 #
13  
14 package Doit::Guarded;
15  
16 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 our $VERSION = '0.011';
19  
20 2 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
21 2 our @EXPORT = qw(ensure using);
22  
23 sub ensure (&;@) {
24 1 ▶ my $code = shift;
Subroutine ensure: called CC=1 SCAR=0.0
Pod undocumented
25 1 (ensure => $code, @_);
26 }
27  
28 sub using (&) {
29 1 ▶ my $code = shift;
Subroutine using: called CC=1 SCAR=0.0
Pod undocumented
30 1 (using => $code, @_);
31 }
32  
33 2 ▶sub new { bless {}, shift }
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
34 2 ▶sub functions { qw(guarded_step) }
Subroutine functions: called CC=1 SCAR=0.0
Pod undocumented
35  
36 sub guarded_step {
37 9 ▶ my($doit, $name, %opts) = @_;
Subroutine guarded_step: called CC=7 SCAR=19.5
Pod undocumented
38 9 ▶ my $ensure = delete $opts{ensure} || Doit::Log::error("ensure is missing");
Condition66%2/3
delete $opts{'ensure'} || &Doit::Log::error('ensure is missing')
l!l&&r!l&&!r
810
MC/DC0%0/2
delete $opts{'ensure'} || &Doit::Log::error('ensure is missing')
delete $opts{'ensure'} &Doit::Log::error('ensure is missing')
Truth table33%1/3
A || B
A= delete $opts{'ensure'}B= &Doit::Log::error('ensure is missing')
ABresult
1X1
011
000
39 8 ▶ my $using = delete $opts{using} || Doit::Log::error("using is missing");
Condition66%2/3
delete $opts{'using'} || &Doit::Log::error('using is missing')
l!l&&r!l&&!r
710
MC/DC0%0/2
delete $opts{'using'} || &Doit::Log::error('using is missing')
delete $opts{'using'} &Doit::Log::error('using is missing')
Truth table33%1/3
A || B
A= delete $opts{'using'}B= &Doit::Log::error('using is missing')
ABresult
1X1
011
000
40 7 ▶ Doit::Log::error("Unhandled options: " . join(" ", %opts)) if %opts;
Branch: 1 branch
BranchTrueFalseTotal
if %opts 1 6 7
41  
42 6 ▶ if (!$ensure->($doit)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not &$ensure($doit)) 5 1 6
43 5 ▶ if ($doit->is_dry_run) {
Branch: 1 branch
BranchTrueFalseTotal
if ($doit->is_dry_run) { } 1 4 5
44 1 Doit::Log::info("$name (dry-run)");
45 } else {
46 4 Doit::Log::info($name);
47 4 $using->($doit);
48 4 ▶ if (!$ensure->($doit)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not &$ensure($doit)) 1 3 4
49 1 Doit::Log::error("'ensure' block for '$name' still fails after running the 'using' block");
50 }
51 }
52 }
53 }
54  
55 2 1;
56  
57 __END__
« blib/lib/Doit/Pip.pm ↑ Summary blib/lib/Doit/Extcmd.pm »