| 1 | #======================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # Badger::Base | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # Base class module implementing common functionality for various | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # other Badger modules. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # Andy Wardley <abw@wardley.org> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | #======================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | package Badger::Base; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | use Badger::Class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 70 | ▶ | version => 0.01, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | debug => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | constants => 'CODE HASH ARRAY BLANK SPACE PKG REFS ONCE WARN NONE', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | import => 'class classes', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | utils => 'blessed reftype xprintf', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | words => 'ID EXCEPTION THROWS ERROR DECLINED before after', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | constant => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | base_id => 'Badger', # stripped from class name to make id | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | TRIAL => 'Badger::Base::Trial', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 70 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 70 | ▶ | use Badger::Exception; # TODO: autoload | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 70 | ▶ | use Badger::Debug 'debug debug_up dump_data_inline dump_data dump_list dump_hash'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 70 | ▶ | our $EXCEPTION = 'Badger::Exception' unless defined $EXCEPTION; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 70 | our $ON_WARN = WARN; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 70 | our $MESSAGES = { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | not_found => '%s not found: %s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | not_found_in => '%s not found in %s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | not_implemented => '%s is not implemented %s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | no_component => 'No %s component defined', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | bad_method => "Invalid method '%s' called on %s at %s line %s", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | invalid => 'Invalid %s specified: %s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | unexpected => 'Invalid %s specified: %s (expected a %s)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | missing_to => 'No %s specified to %s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | missing => 'No %s specified', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | todo => '%s is TODO %s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | at_line => '%s at line %s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | at_file_line => '%s in %s at line %s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 491 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=16.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 491 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | # install warning handling for odd number of parameters when DEBUG enabled | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | local $SIG{__WARN__} = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | Badger::Utils::odd_params(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 491 | } if DEBUG; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 491 | ▶ | my $args = @_ && ref $_[0] eq HASH ? shift : { @_ }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@_ and ref $_[0] eq "HASH"
MC/DC100%2/2
@_ and ref $_[0] eq "HASH"
@_
ref $_[0] eq "HASH"
Truth table100%3/3
A and B
A= @_B= ref $_[0] eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 491 | ▶ | my $self = bless { }, ref $class || $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 491 | $self = $self->init($args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | # be careful to account for object that overload the boolean comparison | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | # operator and may return false to a simple truth test. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 488 | ▶ | return defined $self | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | ? $self | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | : $self->error("init() method failed\n"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 63 | ▶ | sub init { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 63 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | # default action is to store reference to entire configuration so | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | # that methods can examine it later if they need to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 63 | $self->{ config } = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 63 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 8 | ▶ | sub warn { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
warn: called CC=4 SCAR=15.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 8 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 8 | ▶ | return unless @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 8 | my $message = join(BLANK, @_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 8 | my $handlers = $self->on_warn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 8 | $self->debug("dispatching handlers for warn: ", $self->dump_data_inline($handlers), "\n") if DEBUG; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 8 | ▶ | $self->_dispatch_handlers( warn => $handlers => $message ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$handlers and @$handlers
MC/DC0%0/2
$handlers and @$handlers
$handlers
@$handlers
Truth table33%1/3
A and B
A= $handlersB= @$handlers
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | if $handlers && @$handlers; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | # Warning is usually raised by the last handler in the chain which | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | # defaults to 'warn', so it's OK to just drop out here. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 69 | ▶ | sub error { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
error: called CC=10 SCAR=23.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 69 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 69 | ▶ | my $class = ref $self || $self; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table66%2/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 69 | ▶ | my $type = reftype $self || BLANK; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
builtin::reftype($self) || ''
MC/DC100%1/1
builtin::reftype($self) || ''
builtin::reftype($self)
Truth table100%2/2
A
A= builtin::reftype($self)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 70 | ▶ | no strict REFS; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 70 | ▶ | no warnings ONCE; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 69 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | # don't stringify objects passed as argument | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 56 | ▶ | my $message = ref $_[0] ? shift : join(BLANK, map { defined($_) ? $_ : BLANK } @_); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 56 | my $handlers = $self->on_error; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | # set package variable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 56 | ${ $class.PKG.ERROR } = $message; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 56 | ${ $class.PKG.DECLINED } = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 56 | ▶ | if ($type eq HASH) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | # set ERROR and DECLINED items in object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 53 | $self->{ ERROR } = $message; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 53 | $self->{ DECLINED } = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 56 | ▶ | ($message) = $self->_dispatch_handlers( error => $handlers => $message ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$handlers and @$handlers
MC/DC50%1/2
$handlers and @$handlers
$handlers
@$handlers
Truth table66%2/3
A and B
A= $handlersB= @$handlers
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | if $handlers && @$handlers; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 56 | $self->throw($message); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | elsif ($type eq HASH) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 11 | return $self->{ ERROR }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 2 | return ${ $class.PKG.ERROR }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | # not reached | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 50 | ▶ | sub decline { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
decline: called CC=5 SCAR=16.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 50 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 50 | ▶ | my $class = ref $self || $self; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table33%1/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 50 | ▶ | my $type = reftype $self || BLANK; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
builtin::reftype($self) || ''
MC/DC0%0/1
builtin::reftype($self) || ''
builtin::reftype($self)
Truth table50%1/2
A
A= builtin::reftype($self)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 50 | ▶ | my $reason = @_ == 1 ? shift : join(BLANK, @_); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 70 | ▶ | no strict REFS; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 70 | ▶ | no warnings ONCE; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 50 | ${ $class.PKG.ERROR } = $reason; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 50 | ${ $class.PKG.DECLINED } = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 50 | ▶ | if ($type eq HASH) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 50 | $self->{ ERROR } = $reason; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 50 | $self->{ DECLINED } = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 50 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 2 | ▶ | sub declined { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
declined: called CC=4 SCAR=15.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 2 | ▶ | my $class = ref $self || $self; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table33%1/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 2 | ▶ | my $type = reftype $self || BLANK; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
builtin::reftype($self) || ''
MC/DC0%0/1
builtin::reftype($self) || ''
builtin::reftype($self)
Truth table50%1/2
A
A= builtin::reftype($self)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 70 | ▶ | no strict REFS; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | return ($type eq HASH) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | ? $self->{ DECLINED } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | : ${ $class.PKG.DECLINED }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 27 | ▶ | sub reason { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reason: called CC=4 SCAR=15.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 27 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 27 | ▶ | my $class = ref $self || $self; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table33%1/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 27 | ▶ | my $type = reftype $self || BLANK; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
builtin::reftype($self) || ''
MC/DC0%0/1
builtin::reftype($self) || ''
builtin::reftype($self)
Truth table50%1/2
A
A= builtin::reftype($self)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 70 | ▶ | no strict REFS; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | return $type eq HASH | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | ? $self->{ ERROR } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | ▶ | : ${ $class.PKG.ERROR }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 59 | ▶ | sub throw { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
throw: called CC=10 SCAR=24.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 59 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 59 | my $type = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 59 | my $emod = $self->exception; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 59 | my $e; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | # TODO: grok file/line/sub from caller and add to exceptions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 59 | ▶ | if (! @_) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | # single argument can be an exception object or an error message | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | # which is given whatever type is returned by throws() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | # throw($exception) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | # throw($info) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 56 | ▶ | if (blessed $type && $type->isa($emod)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($type) and $type->isa($emod)
MC/DC0%0/2
builtin::blessed($type) and $type->isa($emod)
builtin::blessed($type)
$type->isa($emod)
Truth table33%1/3
A and B
A= builtin::blessed($type)B= $type->isa($emod)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | $self->debug("returning exception object: ", ref $type, " => [$type]\n") if DEBUG; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | $e = $type; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 56 | $self->debug("creating new exception object chain: info => $type\n") if DEBUG; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 56 | $e = $emod->new( type => $self->throws, info => $type ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | # Next argument can also be an exception object (e.g. when chaining | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | # exceptions) or a regular info message. In the first case, we don't | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | # re-throw the exception if it's already of the correct $type (but we | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | # do if any extra arguments are provided) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | # throw($type, $exception) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | # throw($type, $info) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 3 | my $info = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 3 | ▶ | if (! @_ && blessed $info && $info->isa($emod) && $info->type eq $type) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition77%7/9
not @_ and builtin::blessed($info) and $info->isa($emod) and $info->type eq $type
not @_ and builtin::blessed($info) and $info->isa($emod)
not @_ and builtin::blessed($info)
MC/DC50%2/4
not @_ and builtin::blessed($info) and $info->isa($emod) and $info->type eq $type
not @_
builtin::blessed($info)
$info->isa($emod)
$info->type eq $type
Truth table60%3/5
not(A) and B and C and D
A= not @_B= builtin::blessed($info)C= $info->isa($emod)D= $info->type eq $type
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | # second argument is already an exception of type $type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 1 | $e = $info; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 2 | ▶ | my $config = @_ && ref $_[0] eq HASH ? shift : { @_ }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ and ref $_[0] eq "HASH"
MC/DC0%0/2
@_ and ref $_[0] eq "HASH"
@_
ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= @_B= ref $_[0] eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | # construct a new exception from $type and $info fields | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 2 | $config->{ type } = $type; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 2 | $config->{ info } = $info; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 2 | $self->debug("creating new exception object: ", $self->dump_hash($config), "\n") if DEBUG; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 2 | $e = $emod->new($config); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 59 | $e->throw; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 364 | ▶ | sub try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
try: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 364 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 364 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 16 | my $method = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 16 | ▶ | if (wantarray) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 1 | my @result = eval { $self->$method(@_) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 1 | ▶ | $self->decline($@) if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 1 | return @result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 15 | my $result = eval { $self->$method(@_) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 15 | ▶ | $self->decline($@) if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 15 | return $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 348 | return TRIAL->_bind_($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | ▶ | sub catch { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
catch: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | # this depends on some code in Badger::Exception which I haven't | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | # written yet... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | shift->todo; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 63 | ▶ | sub throws { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
throws: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 63 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 63 | ▶ | my $type = reftype $self || BLANK; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
builtin::reftype($self) || ''
MC/DC100%1/1
builtin::reftype($self) || ''
builtin::reftype($self)
Truth table100%2/2
A
A= builtin::reftype($self)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 63 | my $class = class($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 63 | my $throws; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 63 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | # hash objects store exception type in $self->{ THROWS }, anything | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | # else (classes and non-hash objects) use the $THROWS package var | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | $throws = $type eq HASH | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | ? ($self->{ THROWS } = shift) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 4 | ▶ | : $class->var(THROWS, shift); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | elsif ($type eq HASH) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | # we also look in $self->{ config } to see if a 'throws' was | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | # specified as a constructor argument. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | $throws = $self->{ THROWS } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | ||= $self->{ config } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 52 | ▶ | && $self->{ config }->{ throws }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
$self->{"THROWS"} ||= $self->{"config"} && $self->{"config"}{"throws"}
$self->{'config'} && $self->{'config'}{'throws'}
MC/DC0%0/3
$self->{"THROWS"} ||= $self->{"config"} && $self->{"config"}{"throws"}
$self->{"THROWS"}
$self->{'config'}
$self->{'config'}{'throws'}
Truth table0%0/4
A ||= B && C
A= $self->{"THROWS"}B= $self->{'config'}C= $self->{'config'}{'throws'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | # fall back on looking for any package variable in class / base classes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 63 | ▶ | return $throws | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
$throws || $class->any_var('THROWS') || $class->id
$throws or $class->any_var("THROWS")
MC/DC0%0/3
$throws || $class->any_var('THROWS') || $class->id
$throws
$class->any_var("THROWS")
$class->id
Truth table75%3/4
A or B || C
A= $throwsB= $class->any_var("THROWS")C= $class->id
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | || $class->any_var(THROWS) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | || $class->id; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 59 | ▶ | sub exception { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
exception: called CC=8 SCAR=25.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 59 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 59 | ▶ | my $type = reftype $self || BLANK; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
builtin::reftype($self) || ''
MC/DC100%1/1
builtin::reftype($self) || ''
builtin::reftype($self)
Truth table100%2/2
A
A= builtin::reftype($self)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 59 | my $emod; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | # TODO: Move this into Template::Class. It's so rare that you want to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | # set an exception type this way. Then we can have throw() pass the $type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | # to exception() and allow subclasses to make a decision about what kind | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | # of exception to return based on the $type. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 59 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | # as per throws() above, we have to be careful to only treat $self | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | # like a hash when it is a hash-based object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | $emod = $type eq HASH | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | ? ($self->{ EXCEPTION } = shift) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | ▶ | : class($self)->var(EXCEPTION, shift); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | elsif ($type eq HASH) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | $emod = $self->{ EXCEPTION } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | ||= $self->{ config } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 56 | ▶ | && $self->{ config }->{ exception }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%2/6
$self->{"EXCEPTION"} ||= $self->{"config"} && $self->{"config"}{"exception"}
$self->{'config'} && $self->{'config'}{'exception'}
MC/DC0%0/3
$self->{"EXCEPTION"} ||= $self->{"config"} && $self->{"config"}{"exception"}
$self->{"EXCEPTION"}
$self->{'config'}
$self->{'config'}{'exception'}
Truth table0%0/4
A ||= B && C
A= $self->{"EXCEPTION"}B= $self->{'config'}C= $self->{'config'}{'exception'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 59 | ▶ | return $emod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$emod || Badger::Base::class($self)->any_var('EXCEPTION')
MC/DC0%0/2
$emod || Badger::Base::class($self)->any_var('EXCEPTION')
$emod
Badger::Base::class($self)->any_var('EXCEPTION')
Truth table33%1/3
A || B
A= $emodB= Badger::Base::class($self)->any_var('EXCEPTION')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | || class($self)->any_var(EXCEPTION); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 3 | ▶ | sub fatal { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fatal: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 3 | ▶ | my $class = ref $self || $self; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table66%2/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 3 | my $error = join(BLANK, @_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 70 | ▶ | no strict REFS; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | # set package variable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 3 | ${ $class.PKG.ERROR } = $error; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 3 | ▶ | if (ref $self && reftype $self eq HASH) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $self and builtin::reftype($self) eq "HASH"
MC/DC50%1/2
ref $self and builtin::reftype($self) eq "HASH"
ref $self
builtin::reftype($self) eq "HASH"
Truth table66%2/3
A and B
A= ref $selfB= builtin::reftype($self) eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 2 | $self->{ ERROR } = $error; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 2 | $self->{ DECLINED } = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 3 | require Carp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 3 | Carp::confess("Fatal badger error: ", @_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | #----------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | # messages | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | #----------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 1982 | ▶ | sub message { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
message: called CC=10 SCAR=24.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 1982 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 1982 | ▶ | my $name = shift | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
shift() || $self->fatal('message() called without format name')
MC/DC0%0/2
shift() || $self->fatal('message() called without format name')
shift()
$self->fatal('message() called without format name')
Truth table33%1/3
A || B
A= shift()B= $self->fatal('message() called without format name')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | || $self->fatal("message() called without format name"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 1982 | ▶ | my $ref = $self && reftype $self; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self && builtin::reftype($self)
MC/DC50%1/2
$self && builtin::reftype($self)
$self
builtin::reftype($self)
Truth table66%2/3
A && B
A= $selfB= builtin::reftype($self)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 1982 | my $format; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | # allow $self object to have an internal messages hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 1982 | ▶ | if ($self && $ref && $ref eq HASH && $self->{ messages }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition77%7/9
$self and $ref and $ref eq "HASH" and $self->{"messages"}
$self and $ref and $ref eq "HASH"
$self and $ref
MC/DC50%2/4
$self and $ref and $ref eq "HASH" and $self->{"messages"}
$self
$ref
$ref eq "HASH"
$self->{"messages"}
Truth table60%3/5
A and B and C and D
A= $selfB= $refC= $ref eq "HASH"D= $self->{"messages"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | $format = $self->{ messages }->{ $name } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 1 | ▶ | if reftype $self->{ messages } eq HASH; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 1982 | ▶ | $format = class($self)->hash_value( MESSAGES => $name ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
Badger::Base::class($self)->hash_value('MESSAGES', $name) || $self->fatal("message() called with invalid message type: $name")
MC/DC0%0/2
Badger::Base::class($self)->hash_value('MESSAGES', $name) || $self->fatal("message() called with invalid message type: $name")
Badger::Base::class($self)->hash_value('MESSAGES', $name)
$self->fatal("message() called with invalid message type: $name")
Truth table33%1/3
A || B
A= Badger::Base::class($self)->hash_value('MESSAGES', $name)B= $self->fatal("message() called with invalid message type: $name")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | || $self->fatal("message() called with invalid message type: $name") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | unless defined $format; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 1982 | xprintf($format, @_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 1 | ▶ | sub warn_msg { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
warn_msg: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | # explicitly quantify local message() method in case a subclass decides | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | # to re-implement the message() method to do something else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 1 | $_[0]->warn( message(@_) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 27 | ▶ | sub error_msg { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
error_msg: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 27 | $_[0]->error( message(@_) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | ▶ | sub fatal_msg { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fatal_msg: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | $_[0]->fatal( message(@_) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 24 | ▶ | sub decline_msg { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
decline_msg: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 24 | $_[0]->decline( message(@_) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | ▶ | sub debug_msg { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
debug_msg: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | $_[0]->debug( message(@_) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 1 | ▶ | sub throw_msg { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
throw_msg: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 1 | $self->throw( shift, message($self, @_) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | #----------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | # generate not_implemented() and todo() methods | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | #----------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | class->methods( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 70 | my $name = $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 10 | ▶ | $name => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 10 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 10 | ▶ | my $ref = ref $self || $self; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table33%1/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 10 | my ($pkg, $file, $line, $sub) = caller(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 10 | $sub = (caller(1))[3]; # subroutine the caller was called from | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 10 | $sub =~ s/(.*):://; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 10 | ▶ | my $msg = @_ ? join(BLANK, SPACE, @_) : BLANK; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 10 | return $self->error_msg( $name => "$sub()$msg", "for $ref in $file at line $line" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 140 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | qw( not_implemented todo ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | #----------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | # generate on_warn() and on_error() methods | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | #----------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | class->methods( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 70 | my $on_event = $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 140 | my $ON_EVENT = uc $on_event; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 67 | ▶ | $on_event => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=10 SCAR=23.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 67 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 67 | my $class = class($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 67 | my $list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 67 | ▶ | if (ref $self && reftype $self eq HASH) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $self and builtin::reftype($self) eq "HASH"
MC/DC50%1/2
ref $self and builtin::reftype($self) eq "HASH"
ref $self
builtin::reftype($self) eq "HASH"
Truth table66%2/3
A and B
A= ref $selfB= builtin::reftype($self) eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | # look in $self->{ config }->{ on_xxx } or in $ON_XXX pkg | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | # var for one or more event handlers | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | $list = $self->{ $ON_EVENT } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 62 | ▶ | ||= $self->{ config }->{ $on_event } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%4/6
$self->{$ON_EVENT} ||= $self->{"config"}{$on_event} || $class->list_vars($ON_EVENT)
$self->{'config'}{$on_event} || $class->list_vars($ON_EVENT)
MC/DC0%0/3
$self->{$ON_EVENT} ||= $self->{"config"}{$on_event} || $class->list_vars($ON_EVENT)
$self->{$ON_EVENT}
$self->{'config'}{$on_event}
$class->list_vars($ON_EVENT)
Truth table0%0/4
A ||= B || C
A= $self->{$ON_EVENT}B= $self->{'config'}{$on_event}C= $class->list_vars($ON_EVENT)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | || $class->list_vars($ON_EVENT); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | # careful! the config value might be a single handler | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 62 | ▶ | $list = $self->{ $ON_EVENT } = [$list] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | unless ref $list eq ARRAY; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 62 | $self->debug("got $on_event handlers: ", $self->dump_data_inline($list), "\n") if DEBUG; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | # class method or non-hash objects use pkg vars only | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 5 | $list = $class->var_default($ON_EVENT, []); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 5 | ▶ | $list = $class->var($ON_EVENT, [$list]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | unless ref $list eq ARRAY; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | # Add to the list any extra handlers passed as args. First | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | # argument can be 'before' or 'after' to add remaining args | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | # to start or end of list, otherwise the entire list is replaced. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 67 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 3 | ▶ | if ($_[0] eq before) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 0 | unshift(@$list, @_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | elsif ($_[0] eq after) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 1 | shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 1 | push(@$list, @_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 2 | @$list = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | # push(@$list, @_); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 67 | return $list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 140 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | qw( on_warn on_error ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | #----------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | # internal method to dispatch on_error/on_warning handlers | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | #----------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 10 | ▶ | sub _dispatch_handlers { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dispatch_handlers: called CC=10 SCAR=23.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 10 | my ($self, $type, $handlers, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 10 | $self->debug("_dispatch handlers: ", $self->dump_data_inline($handlers), "\n") if DEBUG; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 10 | foreach (@$handlers) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 12 | my $handler = $_; # don't alias list items | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 12 | $self->debug("dispatch handler: $handler\n") if DEBUG; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 12 | ▶ | if (! ref $handler) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 6 | ▶ | if ($handler eq WARN) { # 'warn' - we make sure that the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 2 | my $msg = join('', @args); # message is newline terminated | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 2 | chomp($msg); # to stop Perl from adding a line | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 2 | CORE::warn $msg, "\n"; # number that'll be wrong. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | elsif ($handler eq NONE) { # NONE/0 - bail out | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 4 | ▶ | $handler = $self->can($handler) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->can($handler) || (return $self->fatal("Invalid on_$type method: $handler"))
MC/DC100%1/1
$self->can($handler) || (return $self->fatal("Invalid on_$type method: $handler"))
$self->can($handler)
Truth table100%2/2
A
A= $self->can($handler)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | || return $self->fatal("Invalid on_$type method: $handler"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 3 | @args = $handler->($self, @args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | elsif (ref $handler eq CODE) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 6 | @args = $handler->(@args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 0 | $self->fatal("Invalid on_$type handler: $handler"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 10 | $self->debug("mid-dispatch args: [", join(', ', @args), "]\n") if DEBUG; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | # bail out if we got an empty list of return values or a single | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | # false value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 10 | ▶ | last if ! @args || @args == 1 && ! $args[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
not @args or @args == 1 and not $args[0]
@args == 1 and not $args[0]
MC/DC33%1/3
not @args or @args == 1 and not $args[0]
not @args
@args == 1
not $args[0]
Truth table50%2/4
not(A) or B and not(C)
A= not @argsB= @args == 1C= not $args[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 8 | $self->debug("returning ", join(', ', @args), "\n") if DEBUG; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 8 | return @args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | #----------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | # Badger::Base::Trial - nomadic object for $object->try operation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | #----------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | package Badger::Base::Trial; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 70 | our $AUTOLOAD; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 348 | ▶ | sub _bind_ { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_bind_: called CC=2 SCAR=8.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 348 | my ($class, $object) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 348 | ▶ | bless \$object, ref $class || $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 696 | ▶ | sub AUTOLOAD { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 696 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 696 | my ($method) = ($AUTOLOAD =~ /([^:]+)$/ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 696 | ▶ | return if $method eq 'DESTROY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | # call method on target object in eval block, and downgrade | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 348 | ▶ | if (wantarray) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 1 | my @result = eval { $$self->$method(@_) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 1 | ▶ | $$self->decline($@) if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 1 | return @result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 347 | my $result = eval { $$self->$method(@_) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 347 | ▶ | $$self->decline($@) if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 347 | return $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | # TODO: catch missing error methods | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 70 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||