| 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')
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')
| |||||||||||||||||||||
| 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')
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')
| |||||||||||||||||||||
| 40 | 7 | ▶ | Doit::Log::error("Unhandled options: " . join(" ", %opts)) if %opts; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 6 | ▶ | if (!$ensure->($doit)) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 43 | 5 | ▶ | if ($doit->is_dry_run) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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__ | ||||||||||||||||||||