| 1 | #!/usr/bin/perl | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # $Id$ | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # $Author$ | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # $HeadURL$ | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # $Date$ | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # $Revision$ | ||||||||||||||||||||||||||||||||||||||||||
| 7 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | { | ||||||||||||||||||||||||||||||||||||||||||
| 10 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 11 | ## OOP::Perlish::Class: a Base class for creating Objects that conform to all common OOP | ||||||||||||||||||||||||||||||||||||||||||
| 12 | ## practices, Multiple-Inheritance, Mix-in, Generational-Inheritance, Overriding, | ||||||||||||||||||||||||||||||||||||||||||
| 13 | ## Overloading, Accessor validation, input mutation, singletons, Multitons, etc, etc | ||||||||||||||||||||||||||||||||||||||||||
| 14 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | package OOP::Perlish::Class; | ||||||||||||||||||||||||||||||||||||||||||
| 17 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 7 | our $VERSION = '0.45.0'; | |||||||||||||||||||||||||||||||||||||||||
| 20 | 7 | ▶ | use OOP::Perlish::Class::Accessor; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 7 | ▶ | use Tie::IxHash; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 7 | ▶ | use Exporter; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 7 | ▶ | use IO::Handle; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 7 | ▶ | use constant OOP_PERLISH_CLASS_EMITLEVEL_FATAL => 0; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 7 | ▶ | use constant OOP_PERLISH_CLASS_EMITLEVEL_ERROR => 1; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 7 | ▶ | use constant OOP_PERLISH_CLASS_EMITLEVEL_WARNING => 2; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 7 | ▶ | use constant OOP_PERLISH_CLASS_EMITLEVEL_INFO => 3; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 7 | ▶ | use constant OOP_PERLISH_CLASS_EMITLEVEL_VERBOSE => 4; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 7 | ▶ | use constant OOP_PERLISH_CLASS_EMITLEVEL_DEBUG0 => 5; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 7 | ▶ | use constant OOP_PERLISH_CLASS_EMITLEVEL_DEBUG1 => 6; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 7 | ▶ | use constant OOP_PERLISH_CLASS_EMITLEVEL_DEBUG2 => 7; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 7 | ▶ | use Carp qw(carp croak confess cluck); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 7 | our @EXPORT_TAGS = ( | |||||||||||||||||||||||||||||||||||||||||
| 37 | 'emitlevels' => [ | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 'OOP_PERLISH_CLASS_EMITLEVEL_FATAL', 'OOP_PERLISH_CLASS_EMITLEVEL_ERROR', | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 'OOP_PERLISH_CLASS_EMITLEVEL_WARNING', 'OOP_PERLISH_CLASS_EMITLEVEL_INFO', | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 'OOP_PERLISH_CLASS_EMITLEVEL_VERBOSE', 'OOP_PERLISH_CLASS_EMITLEVEL_DEBUG0', | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 'OOP_PERLISH_CLASS_EMITLEVEL_DEBUG1', 'OOP_PERLISH_CLASS_EMITLEVEL_DEBUG2' | ||||||||||||||||||||||||||||||||||||||||||
| 42 | ], | ||||||||||||||||||||||||||||||||||||||||||
| 43 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 7 | our @EXPORT_OK = ( | |||||||||||||||||||||||||||||||||||||||||
| 46 | 'OOP_PERLISH_CLASS_EMITLEVEL_FATAL', 'OOP_PERLISH_CLASS_EMITLEVEL_ERROR', | ||||||||||||||||||||||||||||||||||||||||||
| 47 | 'OOP_PERLISH_CLASS_EMITLEVEL_WARNING', 'OOP_PERLISH_CLASS_EMITLEVEL_INFO', | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 'OOP_PERLISH_CLASS_EMITLEVEL_VERBOSE', 'OOP_PERLISH_CLASS_EMITLEVEL_DEBUG0', | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 'OOP_PERLISH_CLASS_EMITLEVEL_DEBUG1', 'OOP_PERLISH_CLASS_EMITLEVEL_DEBUG2' | ||||||||||||||||||||||||||||||||||||||||||
| 50 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 53 | ## We still use Exporter's import, but we need to clean it up first | ||||||||||||||||||||||||||||||||||||||||||
| 54 | ## doing this via export_fail doesn't work because exporter must see 'our @EXPORT_FAIL' | ||||||||||||||||||||||||||||||||||||||||||
| 55 | ## in the namespace of package being imported; and subclasses would not normally have | ||||||||||||||||||||||||||||||||||||||||||
| 56 | ## re-defined that again and again and again; optionally, we'd @EXPORT = qw(@EXPORT <...>) | ||||||||||||||||||||||||||||||||||||||||||
| 57 | ## which would result in every module cascading the exports down all the way to users | ||||||||||||||||||||||||||||||||||||||||||
| 58 | ## of the object (not just inheritors) which would suck. | ||||||||||||||||||||||||||||||||||||||||||
| 59 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 60 | sub import | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 27 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=8 SCAR=34.1
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 27 | my ( $proto, @tags ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 63 | 27 | ▶ | my $class = ref($proto) || $proto; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 27 | ▶ | if( bless( {}, $class )->isa(__PACKAGE__) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 27 | $class->____OOP_PERLISH_CLASS_DERIVED_CLASSES()->{$class} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 27 | ▶ | return unless(@tags); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | my %non_import_flags; | |||||||||||||||||||||||||||||||||||||||||
| 72 | ## XXX: Hash slice assignment for LUT | ||||||||||||||||||||||||||||||||||||||||||
| 73 | @non_import_flags{ | ||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | '_emitlevel:error', '_emitlevel:warning', '_emitlevel:info', '_emitlevel:verbose', | |||||||||||||||||||||||||||||||||||||||||
| 75 | '_emitlevel:debug', '_emitlevel:debug1', '_emitlevel:debug2' | ||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||
| 77 | = undef; | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | for my $tag (@tags) { | |||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | for my $setter_tag ( keys %non_import_flags ) { | |||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | $tag =~ m/ ^ \Q$setter_tag\E $ /gsmx && do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | my ( $static_method, $argument ) = split( ':', $tag ); | |||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | if( bless( {}, $class )->can($static_method) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | $class->$static_method($argument); | |||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | @tags = grep { !exists( $non_import_flags{$_} ) } @tags; | |||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | return Exporter::import(@tags); | |||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 95 | ## Create a new instance of this class; should not require overloading in derived classes. | ||||||||||||||||||||||||||||||||||||||||||
| 96 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 97 | sub new | ||||||||||||||||||||||||||||||||||||||||||
| 98 | 150 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=6 SCAR=18.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 150 | my ( $proto, @opts ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | ## support either ...( foo => 'bar' ); or ...( { foo => 'bar' } ); | ||||||||||||||||||||||||||||||||||||||||||
| 102 | my %opts = | ||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | ( @opts == 1 ) ? ( ( ref( $opts[0] ) eq 'HASH' ) ? %{ $opts[0] } : () ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | : ( scalar @opts % 2 == 0 ) ? @opts | ||||||||||||||||||||||||||||||||||||||||||
| 105 | : confess('Invalid number or type of arguments to constructor'); | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 150 | ▶ | my $class = ref($proto) || $proto; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 150 | my $self = {}; | |||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | # obtain the @ISA for whomever inherited us | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 7 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 150 | @{ $self->{____CLASS_ISA} } = @{ $class . '::ISA' }; | |||||||||||||||||||||||||||||||||||||||||
| 113 | 7 | ▶ | use strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | #for my $parent_class ( @{ $self->{____CLASS_ISA} } ) { | ||||||||||||||||||||||||||||||||||||||||||
| 116 | # bless( $self, $parent_class ); | ||||||||||||||||||||||||||||||||||||||||||
| 117 | #} | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | 150 | bless( $self, $class ); ## Bless so we can call _all_isa | |||||||||||||||||||||||||||||||||||||||||
| 120 | 150 | for my $parent_class ( $self->_all_isa() ) { | |||||||||||||||||||||||||||||||||||||||||
| 121 | 357 | bless( $self, $parent_class ); | |||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||
| 123 | 150 | bless( $self, $class ); ## Bless back into this class last so we deref correctly | |||||||||||||||||||||||||||||||||||||||||
| 124 | 150 | $self = $self->____initialize_object(%opts); | |||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | 138 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 130 | ## Get an immutable copy of the underlying data | ||||||||||||||||||||||||||||||||||||||||||
| 131 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 132 | sub get(@) | ||||||||||||||||||||||||||||||||||||||||||
| 133 | 62 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | 62 | my ( $self, $field ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | 62 | $self->____OOP_PERLISH_CLASS_ACCESSORS()->{$field}->self($self); | |||||||||||||||||||||||||||||||||||||||||
| 137 | 62 | return $self->____OOP_PERLISH_CLASS_ACCESSORS()->{$field}->value(); | |||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 141 | ## Set (and validate) an immutable copy, return the validated data. | ||||||||||||||||||||||||||||||||||||||||||
| 142 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 143 | sub set(@) ## no critic (AmbiguousNames) | ||||||||||||||||||||||||||||||||||||||||||
| 144 | 57 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | 57 | my ( $self, $field, @values ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | 57 | $self->____OOP_PERLISH_CLASS_ACCESSORS()->{$field}->self($self); | |||||||||||||||||||||||||||||||||||||||||
| 148 | 57 | return $self->____OOP_PERLISH_CLASS_ACCESSORS()->{$field}->value(@values); | |||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 152 | ## return true if the value has been set before (even if set to undef) | ||||||||||||||||||||||||||||||||||||||||||
| 153 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 154 | sub is_set(@) | ||||||||||||||||||||||||||||||||||||||||||
| 155 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_set: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | ## use critic | ||||||||||||||||||||||||||||||||||||||||||
| 157 | 1 | my ( $self, $field ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | 1 | $self->____OOP_PERLISH_CLASS_ACCESSORS()->{$field}->self($self); | |||||||||||||||||||||||||||||||||||||||||
| 160 | ### Accessors uses -1, 0, and 1, but we make this boolean for Class | ||||||||||||||||||||||||||||||||||||||||||
| 161 | 1 | return ( $self->____OOP_PERLISH_CLASS_ACCESSORS()->{$field}->is_set() > 0 ); | |||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 165 | ## emit an error | ||||||||||||||||||||||||||||||||||||||||||
| 166 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 167 | sub error(@) | ||||||||||||||||||||||||||||||||||||||||||
| 168 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
error: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 169 | 1 | my ( $self, @msgs ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | 1 | return $self->_emit( 'ERROR', OOP_PERLISH_CLASS_EMITLEVEL_ERROR, @msgs ); | |||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 175 | ## emit a warning | ||||||||||||||||||||||||||||||||||||||||||
| 176 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 177 | sub warning(@) | ||||||||||||||||||||||||||||||||||||||||||
| 178 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
warning: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 179 | 1 | my ( $self, @msgs ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | 1 | return $self->_emit( 'WARNING', OOP_PERLISH_CLASS_EMITLEVEL_WARNING, @msgs ); | |||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 185 | ## emit info | ||||||||||||||||||||||||||||||||||||||||||
| 186 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 187 | sub info(@) | ||||||||||||||||||||||||||||||||||||||||||
| 188 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
info: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | 1 | my ( $self, @msgs ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||
| 191 | 1 | return $self->_emit( 'INFO', OOP_PERLISH_CLASS_EMITLEVEL_INFO, @msgs ); | |||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 195 | ## emit something verbose | ||||||||||||||||||||||||||||||||||||||||||
| 196 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 197 | sub verbose(@) | ||||||||||||||||||||||||||||||||||||||||||
| 198 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
verbose: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | 1 | my ( $self, @msgs ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | 1 | return $self->_emit( 'VERBOSE', OOP_PERLISH_CLASS_EMITLEVEL_VERBOSE, @msgs ); | |||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||
| 204 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 205 | ## emit debugging info | ||||||||||||||||||||||||||||||||||||||||||
| 206 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 207 | sub debug(@) | ||||||||||||||||||||||||||||||||||||||||||
| 208 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
debug: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 209 | 2 | my ( $self, @msgs ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||
| 211 | 2 | return $self->_emit( 'DEBUG0', OOP_PERLISH_CLASS_EMITLEVEL_DEBUG0, @msgs ); | |||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||
| 214 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 215 | ## emit more obscure debugging info | ||||||||||||||||||||||||||||||||||||||||||
| 216 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 217 | sub debug1(@) | ||||||||||||||||||||||||||||||||||||||||||
| 218 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
debug1: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | 1 | my ( $self, @msgs ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||
| 221 | 1 | return $self->_emit( 'DEBUG1', OOP_PERLISH_CLASS_EMITLEVEL_DEBUG1, @msgs ); | |||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 225 | ## emit the most obscure debugging info | ||||||||||||||||||||||||||||||||||||||||||
| 226 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 227 | sub debug2(@) | ||||||||||||||||||||||||||||||||||||||||||
| 228 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
debug2: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 229 | 1 | my ( $self, @msgs ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | 1 | return $self->_emit( 'DEBUG2', OOP_PERLISH_CLASS_EMITLEVEL_DEBUG2, @msgs ); | |||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 235 | ## croak with the specified message | ||||||||||||||||||||||||||||||||||||||||||
| 236 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 237 | sub fatal(@) | ||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fatal: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | my ( $self, @msgs ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | ▶ | if( $self->_emitlevel() >= OOP_PERLISH_CLASS_EMITLEVEL_FATAL ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | ▶ | croak( map { my $l = defined($_) ? $_ : 'undef'; chomp($l); $l =~ s/^/FATAL: /gms; $l . $/ } @msgs ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||
| 247 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 248 | ## Stub of a _preinit; note that init must return true or object initialization will fail | ||||||||||||||||||||||||||||||||||||||||||
| 249 | ## This method does object initialization _before_ accessors have been set | ||||||||||||||||||||||||||||||||||||||||||
| 250 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 251 | 136 | ▶ | sub _preinit(@) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_preinit: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 252 | 136 | my ($self, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 253 | 136 | $self->_all_SUPER('_preinit', @args); | |||||||||||||||||||||||||||||||||||||||||
| 254 | 136 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||
| 257 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 258 | ## Stub of an _init; note that init must return true or object initialization will fail | ||||||||||||||||||||||||||||||||||||||||||
| 259 | ## This method does object initialization _after_ accessors have been set | ||||||||||||||||||||||||||||||||||||||||||
| 260 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 261 | 131 | ▶ | sub _init(@) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_init: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 262 | 131 | my ($self, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 263 | 131 | $self->_all_SUPER('_init', @args); | |||||||||||||||||||||||||||||||||||||||||
| 264 | 131 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||
| 267 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 268 | ## name of the class which we use for accessors; overload if you want to use a different | ||||||||||||||||||||||||||||||||||||||||||
| 269 | ## class | ||||||||||||||||||||||||||||||||||||||||||
| 270 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 271 | sub _accessor_class_name(@) | ||||||||||||||||||||||||||||||||||||||||||
| 272 | 17 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_accessor_class_name: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 273 | 17 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 274 | 17 | return qw(OOP::Perlish::Class::Accessor); | |||||||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||
| 277 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 278 | ## emit error, warning, info, verbose, debug, debug1, and debug2 messages; overload to | ||||||||||||||||||||||||||||||||||||||||||
| 279 | ## change the way you emit | ||||||||||||||||||||||||||||||||||||||||||
| 280 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 281 | sub _emit(@) | ||||||||||||||||||||||||||||||||||||||||||
| 282 | 8 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_emit: called CC=4 SCAR=14.2
| |||||||||||||||||||||||||||||||||||||||||||
| 283 | 8 | my ( $self, $prefix, $level, @msgs ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||
| 285 | 8 | ▶ | if(@msgs) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 286 | 8 | ▶ | if( $self->_emitlevel() >= $level ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 287 | 7 | ▶ | STDERR->print( map { my $l = defined($_) ? $_ : 'undef'; chomp($l); $l =~ s/^/$prefix: /gms; $l . $/ } @msgs ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||
| 289 | 8 | push( @{ $self->{ '___' . $prefix } }, @msgs ); | |||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||
| 291 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | return @{ $self->{ '___' . $prefix } }; | |||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||||
| 294 | 8 | return; | |||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||
| 297 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 298 | ## return a list of all methods that this object ->can() in order of: | ||||||||||||||||||||||||||||||||||||||||||
| 299 | ## ( | ||||||||||||||||||||||||||||||||||||||||||
| 300 | ## methods defined in furthest-ancestors, | ||||||||||||||||||||||||||||||||||||||||||
| 301 | ## methods defined nearer-ancestors | ||||||||||||||||||||||||||||||||||||||||||
| 302 | ## methods defined in this-class | ||||||||||||||||||||||||||||||||||||||||||
| 303 | ## ) | ||||||||||||||||||||||||||||||||||||||||||
| 304 | ## now memoized, as this becomes a substantial performance hit otherwise. | ||||||||||||||||||||||||||||||||||||||||||
| 305 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 306 | sub _all_methods(@) | ||||||||||||||||||||||||||||||||||||||||||
| 307 | 176 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_all_methods: called CC=7 SCAR=19.6
| |||||||||||||||||||||||||||||||||||||||||||
| 308 | 176 | my ( $self, $class ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 309 | 176 | ▶ | $class ||= ref($self) || $self; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%3/6
$class ||= ref $self || $self
ref $self || $self
MC/DC0%0/3
$class ||= ref $self || $self
$class
ref $self
$self
Truth table0%0/4
A ||= B || C
A= $classB= ref $selfC= $self
| |||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||
| 311 | 176 | our %____oop_perlish_class_all_methods; | |||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||
| 313 | 176 | ▶ | unless(exists($____oop_perlish_class_all_methods{$class})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 314 | 31 | my %all_methods = (); | |||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||
| 316 | ### preserve order so that methods defined in hiarchies are preserved in the order they | ||||||||||||||||||||||||||||||||||||||||||
| 317 | ### occur | ||||||||||||||||||||||||||||||||||||||||||
| 318 | 31 | tie %all_methods, q(Tie::IxHash); | |||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | for my $parent_class ( $self->_all_isa($class) ) { | |||||||||||||||||||||||||||||||||||||||||
| 321 | 7 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 322 | 81 | for my $symbol ( keys %{ '::' . $parent_class . '::' } ) { | |||||||||||||||||||||||||||||||||||||||||
| 323 | 3512 | ▶ | $all_methods{$symbol} = 1 if( bless( {}, $class )->can($symbol) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||
| 325 | 7 | ▶ | use strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||
| 328 | ### Reverse the order of methods found, so that for meta-programming iteration, we run | ||||||||||||||||||||||||||||||||||||||||||
| 329 | ### the methods defined in top-level derived classes last (so they can override | ||||||||||||||||||||||||||||||||||||||||||
| 330 | ### inherited methods return values and such) | ||||||||||||||||||||||||||||||||||||||||||
| 331 | 31 | $____oop_perlish_class_all_methods{$class} = [ reverse keys %all_methods ]; | |||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||
| 334 | 176 | return( @{ $____oop_perlish_class_all_methods{$class} } ); | |||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||
| 337 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 338 | ## return a list of all-classes that we derive from, in order of: | ||||||||||||||||||||||||||||||||||||||||||
| 339 | ## ( | ||||||||||||||||||||||||||||||||||||||||||
| 340 | ## self | ||||||||||||||||||||||||||||||||||||||||||
| 341 | ## parents | ||||||||||||||||||||||||||||||||||||||||||
| 342 | ## parents of parents | ||||||||||||||||||||||||||||||||||||||||||
| 343 | ## <...> | ||||||||||||||||||||||||||||||||||||||||||
| 344 | ## furthest-ancestor | ||||||||||||||||||||||||||||||||||||||||||
| 345 | ## ) | ||||||||||||||||||||||||||||||||||||||||||
| 346 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 347 | sub _all_isa(@) | ||||||||||||||||||||||||||||||||||||||||||
| 348 | 403 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_all_isa: called CC=6 SCAR=18.3
| |||||||||||||||||||||||||||||||||||||||||||
| 349 | 403 | my ( $self, $class ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 350 | 403 | ▶ | $class ||= ref($self) || $self; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%3/6
$class ||= ref $self || $self
ref $self || $self
MC/DC0%0/3
$class ||= ref $self || $self
$class
ref $self
$self
Truth table0%0/4
A ||= B || C
A= $classB= ref $selfC= $self
| |||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||
| 352 | 403 | ▶ | $self->{____isa_hash} = {} unless( exists( $self->{____isa_hash} ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 353 | 152 | tie %{ $self->{____isa_hash}->{$class} }, q(Tie::IxHash) | |||||||||||||||||||||||||||||||||||||||||
| 354 | 403 | ▶ | unless( exists( $self->{____isa_hash}->{$class} ) && defined( $self->{____isa_hash}->{$class} ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $self->{"____isa_hash"}{$class} and defined $self->{"____isa_hash"}{$class}
MC/DC50%1/2
exists $self->{"____isa_hash"}{$class} and defined $self->{"____isa_hash"}{$class}
exists $self->{"____isa_hash"}{$class}
defined $self->{"____isa_hash"}{$class}
Truth table66%2/3
A and B
A= exists $self->{"____isa_hash"}{$class}B= defined $self->{"____isa_hash"}{$class}
| |||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||
| 356 | 403 | $self->____recurse_isa($class); | |||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||
| 358 | 403 | return keys %{ $self->{____isa_hash}->{$class} }; | |||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||
| 362 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 363 | ## run a method in all immediate members of @ISA | ||||||||||||||||||||||||||||||||||||||||||
| 364 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 365 | sub _all_SUPER | ||||||||||||||||||||||||||||||||||||||||||
| 366 | 267 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_all_SUPER: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 367 | 267 | my ($self, $method, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 368 | 267 | my $root_class = __PACKAGE__; | |||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||
| 370 | 267 | for my $parent_class ( grep { !/^\Q$root_class\E$/ } @{ $self->{____CLASS_ISA} } ) { | |||||||||||||||||||||||||||||||||||||||||
| 371 | 62 | ▶ | if($parent_class->can($method)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 372 | 7 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 373 | 60 | my $sub = *{ $parent_class . '::' . $method }; | |||||||||||||||||||||||||||||||||||||||||
| 374 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 375 | 60 | ▶ | if(*{ $sub }{CODE}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | $sub->($self, @args); | |||||||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||
| 383 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 384 | ## DO NOT USE UNLESS YOU KNOW WHAT YOU ARE DOING! | ||||||||||||||||||||||||||||||||||||||||||
| 385 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 386 | ## Returns a reference to underlying storage; bypassing validation, untainting, etc. | ||||||||||||||||||||||||||||||||||||||||||
| 387 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 388 | sub _get_mutable_reference(@) | ||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_mutable_reference: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | my ( $self, $name ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | ▶ | if( $self->can($name) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | $self->$name(); ### Do some internal plumbing to make sure that a reference exists if it can exist. | |||||||||||||||||||||||||||||||||||||||||
| 394 | 0 | return $self->{___fields}->{$name}->{_Value}; ### should always be a reference to something if it exists | |||||||||||||||||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||
| 398 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 399 | ## Set per-instance emit-level via accessor, or per-class emit-level via static | ||||||||||||||||||||||||||||||||||||||||||
| 400 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 401 | sub _emitlevel(@) | ||||||||||||||||||||||||||||||||||||||||||
| 402 | 15 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_emitlevel: called CC=11 SCAR=26.4
| |||||||||||||||||||||||||||||||||||||||||||
| 403 | 15 | my ( $self, $level ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 404 | 15 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||
| 406 | 7 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 407 | 15 | ▶ | my $instance_storage = \$self->{___fields}->{'_emitlevel'}->{_Value} if( ref($self) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 408 | 15 | my $class_storage = \${ '::' . $class . '::_OOP_PERLISH_CLASS_EMITLEVEL' }; | |||||||||||||||||||||||||||||||||||||||||
| 409 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||
| 411 | 15 | ▶ | my $storage = ( ref($self) ) ? $instance_storage : $class_storage; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||
| 413 | 15 | ▶ | if($level) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 414 | 7 | ▶ | $level =~ m/\D/ && do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | my %level_map = ( | |||||||||||||||||||||||||||||||||||||||||
| 416 | 'fatal' => OOP_PERLISH_CLASS_EMITLEVEL_FATAL, | ||||||||||||||||||||||||||||||||||||||||||
| 417 | 'error' => OOP_PERLISH_CLASS_EMITLEVEL_ERROR, | ||||||||||||||||||||||||||||||||||||||||||
| 418 | 'warning' => OOP_PERLISH_CLASS_EMITLEVEL_WARNING, | ||||||||||||||||||||||||||||||||||||||||||
| 419 | 'info' => OOP_PERLISH_CLASS_EMITLEVEL_INFO, | ||||||||||||||||||||||||||||||||||||||||||
| 420 | 'verbose' => OOP_PERLISH_CLASS_EMITLEVEL_VERBOSE, | ||||||||||||||||||||||||||||||||||||||||||
| 421 | 'debug' => OOP_PERLISH_CLASS_EMITLEVEL_DEBUG0, | ||||||||||||||||||||||||||||||||||||||||||
| 422 | 'debug1' => OOP_PERLISH_CLASS_EMITLEVEL_DEBUG1, | ||||||||||||||||||||||||||||||||||||||||||
| 423 | 'debug2' => OOP_PERLISH_CLASS_EMITLEVEL_DEBUG2 | ||||||||||||||||||||||||||||||||||||||||||
| 424 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 425 | 0 | ▶ | if( exists( $level_map{ lc($level) } ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | $level = $level_map{ lc($level) }; | |||||||||||||||||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||||||||||||||||
| 428 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | $self->error('invalid level set; cannot set emitlevel'); | |||||||||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||||||||||
| 431 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||
| 433 | 7 | ▶ | return unless( $level =~ m/^\d+$/ ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 434 | 7 | ${$storage} = $level; | |||||||||||||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||||||||||||
| 436 | 15 | ▶ | $level = ${$storage} || ${$class_storage} || $main::_OOP_PERLISH_CLASS_EMITLEVEL || 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition75%6/8
${$storage;} || ${$class_storage;} || $main::_OOP_PERLISH_CLASS_EMITLEVEL || 0
${$storage;} or ${$class_storage;} or $main::_OOP_PERLISH_CLASS_EMITLEVEL
${$storage;} or ${$class_storage;}
MC/DC33%1/3
${$storage;} || ${$class_storage;} || $main::_OOP_PERLISH_CLASS_EMITLEVEL || 0
${$storage;}
${$class_storage;}
$main::_OOP_PERLISH_CLASS_EMITLEVEL
Truth table50%2/4
A or B or C
A= ${$storage;}B= ${$class_storage;}C= $main::_OOP_PERLISH_CLASS_EMITLEVEL
| |||||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||
| 438 | 15 | return $level; | |||||||||||||||||||||||||||||||||||||||||
| 439 | } | ||||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||
| 441 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 442 | ## set accessors, usually called like 'BEGIN { __PACKAGE__->_accessor(...) }' as the first | ||||||||||||||||||||||||||||||||||||||||||
| 443 | ## section of any derived class. | ||||||||||||||||||||||||||||||||||||||||||
| 444 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 445 | sub _accessors(@) | ||||||||||||||||||||||||||||||||||||||||||
| 446 | 17 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_accessors: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||
| 447 | 17 | my ( $self, %accessors ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||||
| 449 | 17 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||
| 451 | 17 | my $accessor_class = $self->_accessor_class_name(); | |||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||
| 453 | 0 | for my $field ( keys %accessors ) { | |||||||||||||||||||||||||||||||||||||||||
| 454 | 21 | my %opts = %{ $accessors{$field} }; | |||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||
| 456 | 21 | $self->____OOP_PERLISH_CLASS_ACCESSORS()->{$field} = $accessor_class->new( %opts, name => $field ); | |||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||
| 458 | ### Symbol table manipulation; creates a method named for the $field in the package's namespace | ||||||||||||||||||||||||||||||||||||||||||
| 459 | ### The actual method is created via closure in ____oop_perlish_class_accessor_factory(); | ||||||||||||||||||||||||||||||||||||||||||
| 460 | 7 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 461 | 21 | *{ '::' . $class . '::' . $field } = $self->____oop_perlish_class_accessor_factory($field); | |||||||||||||||||||||||||||||||||||||||||
| 462 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 463 | } | ||||||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||||||
| 465 | 17 | return; | |||||||||||||||||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||
| 468 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 469 | ## Handle the magic constuctor argument | ||||||||||||||||||||||||||||||||||||||||||
| 470 | ## '_____oop_perlish_class__defer__required__fields__validation', set the key value pair | ||||||||||||||||||||||||||||||||||||||||||
| 471 | ## 'defer_required_fields' to when we see that arg passed to a constructor (and its true) | ||||||||||||||||||||||||||||||||||||||||||
| 472 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 473 | #sub _magic_constructor_arg_handler_defer_required(@) | ||||||||||||||||||||||||||||||||||||||||||
| 474 | #{ | ||||||||||||||||||||||||||||||||||||||||||
| 475 | # my ( $self, $opts ) = @_; | ||||||||||||||||||||||||||||||||||||||||||
| 476 | # | ||||||||||||||||||||||||||||||||||||||||||
| 477 | # my $key = 'defer_required_fields'; | ||||||||||||||||||||||||||||||||||||||||||
| 478 | # my $defer_required_fields; | ||||||||||||||||||||||||||||||||||||||||||
| 479 | # | ||||||||||||||||||||||||||||||||||||||||||
| 480 | # if( exists( $opts->{_____oop_perlish_class__defer__required__fields__validation} ) ) { | ||||||||||||||||||||||||||||||||||||||||||
| 481 | # $defer_required_fields = $opts->{_____oop_perlish_class__defer__required__fields__validation}; | ||||||||||||||||||||||||||||||||||||||||||
| 482 | # delete $opts->{_____oop_perlish_class__defer__required__fields__validation}; | ||||||||||||||||||||||||||||||||||||||||||
| 483 | # } | ||||||||||||||||||||||||||||||||||||||||||
| 484 | # return ( $key, $defer_required_fields ); | ||||||||||||||||||||||||||||||||||||||||||
| 485 | #} | ||||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||
| 487 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 488 | ## List all classes which are derived from a given base class (or the class $self was | ||||||||||||||||||||||||||||||||||||||||||
| 489 | ## instanced from) | ||||||||||||||||||||||||||||||||||||||||||
| 490 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 491 | sub _derived_classes | ||||||||||||||||||||||||||||||||||||||||||
| 492 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_derived_classes: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 493 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 494 | 0 | ▶ | my $class = ref($self) || $self; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table0%0/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||
| 496 | my @derived_classes = | ||||||||||||||||||||||||||||||||||||||||||
| 497 | 0 | ▶ | grep { bless( {}, $_ )->isa($class) && $_ ne $class } keys %{ $self->____OOP_PERLISH_CLASS_DERIVED_CLASSES() }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
bless({}, $_)->isa($class) && $_ ne $class
MC/DC0%0/2
bless({}, $_)->isa($class) && $_ ne $class
bless({}, $_)->isa($class)
$_ ne $class
Truth table0%0/3
A && B
A= bless({}, $_)->isa($class)B= $_ ne $class
| |||||||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||||||
| 499 | 0 | return (@derived_classes); | |||||||||||||||||||||||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||
| 502 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 503 | ## return an accessor subroutine reference | ||||||||||||||||||||||||||||||||||||||||||
| 504 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 505 | sub ____oop_perlish_class_accessor_factory(@) | ||||||||||||||||||||||||||||||||||||||||||
| 506 | 21 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
____oop_perlish_class_accessor_factory: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 507 | 21 | my ( $class, $key ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||
| 509 | 119 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 510 | 119 | my ( $self, @values ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||||||||||||
| 512 | 119 | ▶ | return $self->set( $key, @values ) if(@values); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 513 | 62 | return $self->get($key); | |||||||||||||||||||||||||||||||||||||||||
| 514 | 21 | }; | |||||||||||||||||||||||||||||||||||||||||
| 515 | } | ||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||
| 517 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 518 | ## recurse @ISA of every class we inherit from | ||||||||||||||||||||||||||||||||||||||||||
| 519 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 520 | sub ____recurse_isa(@) | ||||||||||||||||||||||||||||||||||||||||||
| 521 | 765 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
____recurse_isa: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 522 | 765 | my ( $self, $class, @traverse_isa ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 523 | 765 | unshift( @traverse_isa, $class ); | |||||||||||||||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||||||||||||||||
| 525 | 765 | my @parent_isa = (); | |||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||||
| 527 | 0 | for my $parent_class ( grep { !exists( $self->{____isa_hash}->{$class}->{$_} ) } @traverse_isa ) { | |||||||||||||||||||||||||||||||||||||||||
| 528 | 362 | $self->{____isa_hash}->{$class}->{$parent_class} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 529 | 362 | push( @parent_isa, $parent_class ); | |||||||||||||||||||||||||||||||||||||||||
| 530 | 7 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 531 | 362 | push( @parent_isa, $self->____recurse_isa( $class, @{ $parent_class . '::ISA' } ) ); | |||||||||||||||||||||||||||||||||||||||||
| 532 | 7 | ▶ | use strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 533 | } | ||||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||
| 535 | 765 | return @parent_isa; | |||||||||||||||||||||||||||||||||||||||||
| 536 | } | ||||||||||||||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||||||||||||||
| 538 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 539 | ## return a static reference to a hash of accessors for this class; must work for all | ||||||||||||||||||||||||||||||||||||||||||
| 540 | ## derived classes | ||||||||||||||||||||||||||||||||||||||||||
| 541 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 542 | sub ____OOP_PERLISH_CLASS_ACCESSORS | ||||||||||||||||||||||||||||||||||||||||||
| 543 | 901 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
____OOP_PERLISH_CLASS_ACCESSORS: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 544 | 901 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 545 | 901 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 546 | 901 | our $____OOP_PERLISH_CLASS_ACCESSORS; | |||||||||||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||||||||||||
| 548 | 901 | ▶ | $____OOP_PERLISH_CLASS_ACCESSORS = {} unless( defined($____OOP_PERLISH_CLASS_ACCESSORS) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 549 | 901 | ▶ | $____OOP_PERLISH_CLASS_ACCESSORS->{$class} = {} unless( exists( $____OOP_PERLISH_CLASS_ACCESSORS->{$class} ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||
| 551 | 901 | return $____OOP_PERLISH_CLASS_ACCESSORS->{$class}; | |||||||||||||||||||||||||||||||||||||||||
| 552 | } | ||||||||||||||||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||||||||||||||||
| 554 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 555 | ## Keep a list of all classes that derive from OOP::Perlish::Class; used in the utility | ||||||||||||||||||||||||||||||||||||||||||
| 556 | ## method '_derived_classes' to return all children of a given class. | ||||||||||||||||||||||||||||||||||||||||||
| 557 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 558 | sub ____OOP_PERLISH_CLASS_DERIVED_CLASSES | ||||||||||||||||||||||||||||||||||||||||||
| 559 | 27 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
____OOP_PERLISH_CLASS_DERIVED_CLASSES: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 560 | 27 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 561 | 27 | our $____OOP_PERLISH_CLASS_DERIVED_CLASSES; | |||||||||||||||||||||||||||||||||||||||||
| 562 | 27 | ▶ | $____OOP_PERLISH_CLASS_DERIVED_CLASSES = {} unless( defined($____OOP_PERLISH_CLASS_DERIVED_CLASSES) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||||||||||||
| 564 | 27 | return $____OOP_PERLISH_CLASS_DERIVED_CLASSES; | |||||||||||||||||||||||||||||||||||||||||
| 565 | } | ||||||||||||||||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||||||||||||||||
| 567 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 568 | ## return a static reference to an array of required fields for this class; must work for | ||||||||||||||||||||||||||||||||||||||||||
| 569 | ## all derived classes | ||||||||||||||||||||||||||||||||||||||||||
| 570 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 571 | sub ____OOP_PERLISH_CLASS_REQUIRED_FIELDS | ||||||||||||||||||||||||||||||||||||||||||
| 572 | 570 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
____OOP_PERLISH_CLASS_REQUIRED_FIELDS: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||
| 573 | 570 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 574 | 570 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 575 | 570 | our $____OOP_PERLISH_CLASS_REQUIRED_FIELDS; | |||||||||||||||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||||||||||||||||
| 577 | 570 | ▶ | $____OOP_PERLISH_CLASS_REQUIRED_FIELDS = {} unless( defined($____OOP_PERLISH_CLASS_REQUIRED_FIELDS) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 578 | 570 | ▶ | $____OOP_PERLISH_CLASS_REQUIRED_FIELDS->{$class} = [] unless( exists( $____OOP_PERLISH_CLASS_REQUIRED_FIELDS->{$class} ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||||||||||||||||
| 580 | 570 | return $____OOP_PERLISH_CLASS_REQUIRED_FIELDS->{$class}; | |||||||||||||||||||||||||||||||||||||||||
| 581 | } | ||||||||||||||||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||||||||||||||||
| 583 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 584 | ## object construction, typically it shouldn't be necessary to overload this directly, | ||||||||||||||||||||||||||||||||||||||||||
| 585 | ## instead overload one or more of the things it calls | ||||||||||||||||||||||||||||||||||||||||||
| 586 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 587 | sub ____initialize_object(@) | ||||||||||||||||||||||||||||||||||||||||||
| 588 | 150 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
____initialize_object: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||
| 589 | 150 | my ( $self, %opts ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||||||||||||||||
| 591 | 150 | my %magic = $self->____process_magic_arguments( \%opts ); | |||||||||||||||||||||||||||||||||||||||||
| 592 | 150 | ▶ | if( exists( $magic{'return'} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 593 | 7 | my @ret = @{ $magic{'return'} }; | |||||||||||||||||||||||||||||||||||||||||
| 594 | 7 | ▶ | return @ret if( scalar @ret > 1 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 595 | 7 | return ( $ret[0] ); | |||||||||||||||||||||||||||||||||||||||||
| 596 | } | ||||||||||||||||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||||||||||||||||
| 598 | ### Grab our version of %opts from $self->{____oop_perlish_class_opts}, or initialize it if its not been set. | ||||||||||||||||||||||||||||||||||||||||||
| 599 | 143 | %{ $self->{____oop_perlish_class_opts} } = %opts; | |||||||||||||||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||||||||||||||||
| 601 | 143 | $self->____inherit_accessors(); | |||||||||||||||||||||||||||||||||||||||||
| 602 | 143 | $self->____pre_validate_opts(); #unless( $magic{defer_required_fields} ); | |||||||||||||||||||||||||||||||||||||||||
| 603 | ### XXX: unnessessary, and annoying XXX $self->____inherit_constructed_refs(); | ||||||||||||||||||||||||||||||||||||||||||
| 604 | ### XXX: Might want to make a for (@ISA) { $_::_init(@_); } or similar for multiple_inheritance considerations. | ||||||||||||||||||||||||||||||||||||||||||
| 605 | 138 | $self->____initialize_required_fields();# unless( $magic{defer_required_fields} ); | |||||||||||||||||||||||||||||||||||||||||
| 606 | 136 | ▶ | return unless( $self->_preinit() ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 607 | 136 | $self->____initialize_non_required_fields(); | |||||||||||||||||||||||||||||||||||||||||
| 608 | 131 | ▶ | return unless( $self->_init() ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 609 | 131 | $self->{__initialized} = 1; # unless($magic{defer_required_fields}); | |||||||||||||||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||||||||||||||||
| 611 | 131 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 612 | } | ||||||||||||||||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||||||||||||||||
| 614 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 615 | ## Run any method named _magic_constructor_arg_handler* and collect its return tuple into a | ||||||||||||||||||||||||||||||||||||||||||
| 616 | ## hash called %magic which will be referenced in ____initialize_object; or may mutate | ||||||||||||||||||||||||||||||||||||||||||
| 617 | ## $self, or do any of a dozen other things. | ||||||||||||||||||||||||||||||||||||||||||
| 618 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 619 | ## The key 'return' is considered magical and sacred; if you return in your tuple | ||||||||||||||||||||||||||||||||||||||||||
| 620 | ## 'return => foo' the constructor will immediately, and before any other initialization | ||||||||||||||||||||||||||||||||||||||||||
| 621 | ## completes, return the thing you said to return; usually a blessed reference to something; | ||||||||||||||||||||||||||||||||||||||||||
| 622 | ## be it a singleton, multiton, another object, acme-time-bomb ala wiley coyote, etc. | ||||||||||||||||||||||||||||||||||||||||||
| 623 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 624 | ## Your method will be passed a reference to the options passed to the constructor; and may | ||||||||||||||||||||||||||||||||||||||||||
| 625 | ## (usually should) delete the magical key you are interested in, so that it is not | ||||||||||||||||||||||||||||||||||||||||||
| 626 | ## considered an accessor later. | ||||||||||||||||||||||||||||||||||||||||||
| 627 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 628 | ## This could have been done via attributes, but then it suffers from all the annoyances of | ||||||||||||||||||||||||||||||||||||||||||
| 629 | ## having to be seen prior to CHECK blocks running, yada yada... | ||||||||||||||||||||||||||||||||||||||||||
| 630 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 631 | sub ____process_magic_arguments(@) | ||||||||||||||||||||||||||||||||||||||||||
| 632 | 150 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
____process_magic_arguments: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 633 | 150 | my ( $self, $opts ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 634 | |||||||||||||||||||||||||||||||||||||||||||
| 635 | 150 | my %magic = (); | |||||||||||||||||||||||||||||||||||||||||
| 636 | |||||||||||||||||||||||||||||||||||||||||||
| 637 | 150 | for( $self->_all_methods() ) { | |||||||||||||||||||||||||||||||||||||||||
| 638 | 11569 | ▶ | m/^_magic_constructor_arg_handler/ && do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 639 | 10 | my $method = $_; | |||||||||||||||||||||||||||||||||||||||||
| 640 | 10 | my ( $key, $value ) = $self->$method($opts); | |||||||||||||||||||||||||||||||||||||||||
| 641 | 10 | ▶ | $magic{$key} = $value if( $key && $value ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$key and $value
MC/DC50%1/2
$key and $value
$key
$value
Truth table66%2/3
A and B
A= $keyB= $value
| |||||||||||||||||||||||||||||||||||||||||||
| 642 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 643 | } | ||||||||||||||||||||||||||||||||||||||||||
| 644 | |||||||||||||||||||||||||||||||||||||||||||
| 645 | 150 | return %magic; | |||||||||||||||||||||||||||||||||||||||||
| 646 | } | ||||||||||||||||||||||||||||||||||||||||||
| 647 | |||||||||||||||||||||||||||||||||||||||||||
| 648 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 649 | ## verify that we have our required fields, even if they don't have real values but have | ||||||||||||||||||||||||||||||||||||||||||
| 650 | ## defaults instead (a default AND required field would be odd, but is supported) | ||||||||||||||||||||||||||||||||||||||||||
| 651 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 652 | sub ____pre_validate_opts(@) | ||||||||||||||||||||||||||||||||||||||||||
| 653 | 142 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
____pre_validate_opts: called CC=5 SCAR=16.3
| |||||||||||||||||||||||||||||||||||||||||||
| 654 | 142 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 655 | |||||||||||||||||||||||||||||||||||||||||||
| 656 | 142 | my @required_fields = $self->____identify_required_fields(); | |||||||||||||||||||||||||||||||||||||||||
| 657 | |||||||||||||||||||||||||||||||||||||||||||
| 658 | 142 | for(@required_fields) { | |||||||||||||||||||||||||||||||||||||||||
| 659 | confess("Missing required field $_") | ||||||||||||||||||||||||||||||||||||||||||
| 660 | unless( | ||||||||||||||||||||||||||||||||||||||||||
| 661 | exists( $self->{____oop_perlish_class_opts}->{$_} ) | ||||||||||||||||||||||||||||||||||||||||||
| 662 | || ( exists( $self->____OOP_PERLISH_CLASS_ACCESSORS()->{$_} ) | ||||||||||||||||||||||||||||||||||||||||||
| 663 | 199 | ▶ | && $self->____OOP_PERLISH_CLASS_ACCESSORS()->{$_}->default_is_set() ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
exists $self->{"____oop_perlish_class_opts"}{$_} or exists $self->____OOP_PERLISH_CLASS_ACCESSORS->{$_} and $self->____OOP_PERLISH_CLASS_ACCESSORS->{$_}->default_is_set
exists $self->____OOP_PERLISH_CLASS_ACCESSORS->{$_} and $self->____OOP_PERLISH_CLASS_ACCESSORS->{$_}->default_is_set
MC/DC33%1/3
exists $self->{"____oop_perlish_class_opts"}{$_} or exists $self->____OOP_PERLISH_CLASS_ACCESSORS->{$_} and $self->____OOP_PERLISH_CLASS_ACCESSORS->{$_}->default_is_set
exists $self->{"____oop_perlish_class_opts"}{$_}
exists $self->____OOP_PERLISH_CLASS_ACCESSORS->{$_}
$self->____OOP_PERLISH_CLASS_ACCESSORS->{$_}->default_is_set
Truth table75%3/4
A or B and C
A= exists $self->{"____oop_perlish_class_opts"}{$_}B= exists $self->____OOP_PERLISH_CLASS_ACCESSORS->{$_}C= $self->____OOP_PERLISH_CLASS_ACCESSORS->{$_}->default_is_set
| |||||||||||||||||||||||||||||||||||||||||||
| 664 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 665 | } | ||||||||||||||||||||||||||||||||||||||||||
| 666 | 138 | return; | |||||||||||||||||||||||||||||||||||||||||
| 667 | } | ||||||||||||||||||||||||||||||||||||||||||
| 668 | |||||||||||||||||||||||||||||||||||||||||||
| 669 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 670 | ## obtain the names and references to every accessor in our inheritance | ||||||||||||||||||||||||||||||||||||||||||
| 671 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 672 | sub ____inherit_accessors(@) | ||||||||||||||||||||||||||||||||||||||||||
| 673 | 51 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
____inherit_accessors: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||
| 674 | 51 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 675 | |||||||||||||||||||||||||||||||||||||||||||
| 676 | ### Protect overloaded accessors by identifying those in our top-level namespace | ||||||||||||||||||||||||||||||||||||||||||
| 677 | ### This cascaded up through the inheritance tree | ||||||||||||||||||||||||||||||||||||||||||
| 678 | 51 | my %top_accessors = (); | |||||||||||||||||||||||||||||||||||||||||
| 679 | 51 | ▶ | if( scalar( keys %{ $self->____OOP_PERLISH_CLASS_ACCESSORS() } ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 680 | # XXX: Hash slice assignment | ||||||||||||||||||||||||||||||||||||||||||
| 681 | 32 | @top_accessors{ keys %{ $self->____OOP_PERLISH_CLASS_ACCESSORS() } } = | |||||||||||||||||||||||||||||||||||||||||
| 682 | 32 | ( (1) x ( ( scalar keys %{ $self->____OOP_PERLISH_CLASS_ACCESSORS() } ) ) ); | |||||||||||||||||||||||||||||||||||||||||
| 683 | } | ||||||||||||||||||||||||||||||||||||||||||
| 684 | |||||||||||||||||||||||||||||||||||||||||||
| 685 | ### Assimilate inherited accessor references | ||||||||||||||||||||||||||||||||||||||||||
| 686 | #for my $parent_class ( @{ $self->{____CLASS_ISA} } ) { | ||||||||||||||||||||||||||||||||||||||||||
| 687 | 51 | for my $parent_class ( $self->_all_isa() ) { | |||||||||||||||||||||||||||||||||||||||||
| 688 | 148 | ▶ | if( $parent_class && bless( {}, $parent_class )->can('____OOP_PERLISH_CLASS_ACCESSORS') ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$parent_class and bless({}, $parent_class)->can("____OOP_PERLISH_CLASS_ACCESSORS")
MC/DC50%1/2
$parent_class and bless({}, $parent_class)->can("____OOP_PERLISH_CLASS_ACCESSORS")
$parent_class
bless({}, $parent_class)->can("____OOP_PERLISH_CLASS_ACCESSORS")
Truth table66%2/3
A and B
A= $parent_classB= bless({}, $parent_class)->can("____OOP_PERLISH_CLASS_ACCESSORS")
| |||||||||||||||||||||||||||||||||||||||||||
| 689 | 147 | ▶ | while( my ( $k, $v ) = each %{ $parent_class->____OOP_PERLISH_CLASS_ACCESSORS() } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 690 | 89 | ▶ | $self->____OOP_PERLISH_CLASS_ACCESSORS()->{$k} = $v unless( exists( $top_accessors{$k} ) ); #protect overloading | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 691 | } | ||||||||||||||||||||||||||||||||||||||||||
| 692 | } | ||||||||||||||||||||||||||||||||||||||||||
| 693 | } | ||||||||||||||||||||||||||||||||||||||||||
| 694 | 51 | return; | |||||||||||||||||||||||||||||||||||||||||
| 695 | } | ||||||||||||||||||||||||||||||||||||||||||
| 696 | |||||||||||||||||||||||||||||||||||||||||||
| 697 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 698 | ## run constructors of every class we derive from, and assimilate their %{ $self } hash into | ||||||||||||||||||||||||||||||||||||||||||
| 699 | ## our own. | ||||||||||||||||||||||||||||||||||||||||||
| 700 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 701 | ## FIXME: We only support deriving from blessed-hashref classes. | ||||||||||||||||||||||||||||||||||||||||||
| 702 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 703 | sub ____inherit_constructed_refs | ||||||||||||||||||||||||||||||||||||||||||
| 704 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
____inherit_constructed_refs: not called CC=12 SCAR=50.5
| |||||||||||||||||||||||||||||||||||||||||||
| 705 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 706 | |||||||||||||||||||||||||||||||||||||||||||
| 707 | 0 | for my $parent_class ( @{ $self->{____CLASS_ISA} } ) { | |||||||||||||||||||||||||||||||||||||||||
| 708 | 0 | ▶ | next if( $parent_class eq __PACKAGE__ ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 709 | 0 | my $tclass = bless( {}, $parent_class ); | |||||||||||||||||||||||||||||||||||||||||
| 710 | 0 | my $this; | |||||||||||||||||||||||||||||||||||||||||
| 711 | 0 | ▶ | if( $tclass->isa(__PACKAGE__) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 712 | 0 | $this = $parent_class->new( _____oop_perlish_class__defer__required__fields__validation => 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 713 | } | ||||||||||||||||||||||||||||||||||||||||||
| 714 | elsif( $tclass->can('new') ) { | ||||||||||||||||||||||||||||||||||||||||||
| 715 | 0 | $this = $parent_class->new(); | |||||||||||||||||||||||||||||||||||||||||
| 716 | } | ||||||||||||||||||||||||||||||||||||||||||
| 717 | ### FIXME: cleanly handle non-hashref ancestors... | ||||||||||||||||||||||||||||||||||||||||||
| 718 | 0 | ▶ | if( $this && $this->isa('HASH') ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$this and $this->isa("HASH")
MC/DC0%0/2
$this and $this->isa("HASH")
$this
$this->isa("HASH")
Truth table0%0/3
A and B
A= $thisB= $this->isa("HASH")
| |||||||||||||||||||||||||||||||||||||||||||
| 719 | 0 | ▶ | while( my ( $key, $val ) = each %{$this} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 720 | 0 | ▶ | $self->{$key} = $val unless( exists( $self->{$key} ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 721 | } | ||||||||||||||||||||||||||||||||||||||||||
| 722 | 0 | ▶ | if( exists( $this->{___fields} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 723 | 0 | ▶ | while( my ( $key, $val ) = each %{ $this->{___fields} } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 724 | 0 | ▶ | $self->$key( $val->{_Value} ) unless( exists( $self->{___fields}->{$key} ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 725 | } | ||||||||||||||||||||||||||||||||||||||||||
| 726 | } | ||||||||||||||||||||||||||||||||||||||||||
| 727 | } | ||||||||||||||||||||||||||||||||||||||||||
| 728 | } | ||||||||||||||||||||||||||||||||||||||||||
| 729 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 730 | } | ||||||||||||||||||||||||||||||||||||||||||
| 731 | |||||||||||||||||||||||||||||||||||||||||||
| 732 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 733 | ## figure out what fields are required for all derived ancestor classes and ourself. | ||||||||||||||||||||||||||||||||||||||||||
| 734 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 735 | sub ____identify_required_fields(@) | ||||||||||||||||||||||||||||||||||||||||||
| 736 | 552 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
____identify_required_fields: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||
| 737 | 552 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 738 | |||||||||||||||||||||||||||||||||||||||||||
| 739 | 552 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 740 | |||||||||||||||||||||||||||||||||||||||||||
| 741 | 552 | ▶ | if( !defined( $self->{____oop_perlish_class_required_fields} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 742 | 142 | my %required_fields = (); | |||||||||||||||||||||||||||||||||||||||||
| 743 | |||||||||||||||||||||||||||||||||||||||||||
| 744 | ### Obtain REQUIRED_FIELDS static from derived class. Assign it via hashslice | ||||||||||||||||||||||||||||||||||||||||||
| 745 | 142 | @required_fields{ @{ $class->____OOP_PERLISH_CLASS_REQUIRED_FIELDS() } } = @{ $class->____OOP_PERLISH_CLASS_REQUIRED_FIELDS() }; | |||||||||||||||||||||||||||||||||||||||||
| 746 | |||||||||||||||||||||||||||||||||||||||||||
| 747 | 142 | ▶ | while( my ( $name, $field ) = each %{ $self->____OOP_PERLISH_CLASS_ACCESSORS() } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 748 | 62 | ▶ | $required_fields{$name} = $name if( $field->required() ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 749 | } | ||||||||||||||||||||||||||||||||||||||||||
| 750 | |||||||||||||||||||||||||||||||||||||||||||
| 751 | # FIXME: Does not cascade beyond @ISA, should traverse inheritance tree and ensure that all required fields are | ||||||||||||||||||||||||||||||||||||||||||
| 752 | # provided for any hiararchy. ... does cascade via new, but only to ancesters who conform with us. unsure how to fix | ||||||||||||||||||||||||||||||||||||||||||
| 753 | #for my $parent_class ( @{ $self->{____CLASS_ISA} } ) { | ||||||||||||||||||||||||||||||||||||||||||
| 754 | 142 | for my $parent_class ( $self->_all_isa() ) { | |||||||||||||||||||||||||||||||||||||||||
| 755 | 328 | ▶ | if( bless( {}, $parent_class )->can('____OOP_PERLISH_CLASS_REQUIRED_FIELDS') ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 756 | 327 | @required_fields{ @{ $parent_class->____OOP_PERLISH_CLASS_REQUIRED_FIELDS() } } = | |||||||||||||||||||||||||||||||||||||||||
| 757 | 327 | @{ $parent_class->____OOP_PERLISH_CLASS_REQUIRED_FIELDS() }; | |||||||||||||||||||||||||||||||||||||||||
| 758 | } | ||||||||||||||||||||||||||||||||||||||||||
| 759 | } | ||||||||||||||||||||||||||||||||||||||||||
| 760 | |||||||||||||||||||||||||||||||||||||||||||
| 761 | 142 | @{ $self->{____oop_perlish_class_required_fields} } = keys %required_fields; | |||||||||||||||||||||||||||||||||||||||||
| 762 | } | ||||||||||||||||||||||||||||||||||||||||||
| 763 | 552 | return @{ $self->{____oop_perlish_class_required_fields} }; | |||||||||||||||||||||||||||||||||||||||||
| 764 | } | ||||||||||||||||||||||||||||||||||||||||||
| 765 | |||||||||||||||||||||||||||||||||||||||||||
| 766 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 767 | ## setup required fields, using their accessors | ||||||||||||||||||||||||||||||||||||||||||
| 768 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 769 | sub ____initialize_required_fields(@) | ||||||||||||||||||||||||||||||||||||||||||
| 770 | 138 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
____initialize_required_fields: called CC=6 SCAR=18.8
| |||||||||||||||||||||||||||||||||||||||||||
| 771 | 138 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 772 | |||||||||||||||||||||||||||||||||||||||||||
| 773 | 138 | my @required_fields = $self->____identify_required_fields(); | |||||||||||||||||||||||||||||||||||||||||
| 774 | |||||||||||||||||||||||||||||||||||||||||||
| 775 | 138 | for my $method (@required_fields) { | |||||||||||||||||||||||||||||||||||||||||
| 776 | $self->$method( $self->{____oop_perlish_class_opts}->{$method} ) | ||||||||||||||||||||||||||||||||||||||||||
| 777 | 194 | ▶ | if( exists( $self->{____oop_perlish_class_opts}->{$method} ) && defined( $self->{____oop_perlish_class_opts}->{$method} ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $self->{"____oop_perlish_class_opts"}{$method} and defined $self->{"____oop_perlish_class_opts"}{$method}
MC/DC0%0/2
exists $self->{"____oop_perlish_class_opts"}{$method} and defined $self->{"____oop_perlish_class_opts"}{$method}
exists $self->{"____oop_perlish_class_opts"}{$method}
defined $self->{"____oop_perlish_class_opts"}{$method}
Truth table33%1/3
A and B
A= exists $self->{"____oop_perlish_class_opts"}{$method}B= defined $self->{"____oop_perlish_class_opts"}{$method}
| |||||||||||||||||||||||||||||||||||||||||||
| 778 | 193 | ▶ | croak("Invalid required attribute for $method") unless( $self->$method() || $self->is_set($method) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->$method or $self->is_set($method)
MC/DC50%1/2
$self->$method or $self->is_set($method)
$self->$method
$self->is_set($method)
Truth table66%2/3
A or B
A= $self->$methodB= $self->is_set($method)
| |||||||||||||||||||||||||||||||||||||||||||
| 779 | } | ||||||||||||||||||||||||||||||||||||||||||
| 780 | 136 | return; | |||||||||||||||||||||||||||||||||||||||||
| 781 | } | ||||||||||||||||||||||||||||||||||||||||||
| 782 | |||||||||||||||||||||||||||||||||||||||||||
| 783 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 784 | ## setup non-required-fields, using their accessors | ||||||||||||||||||||||||||||||||||||||||||
| 785 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 786 | sub ____initialize_non_required_fields(@) | ||||||||||||||||||||||||||||||||||||||||||
| 787 | 136 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
____initialize_non_required_fields: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 788 | 136 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 789 | |||||||||||||||||||||||||||||||||||||||||||
| 790 | ### XXX: Hash slice assignment | ||||||||||||||||||||||||||||||||||||||||||
| 791 | 136 | my %required_fields_lut; | |||||||||||||||||||||||||||||||||||||||||
| 792 | 136 | @required_fields_lut{ $self->____identify_required_fields() } = $self->____identify_required_fields(); | |||||||||||||||||||||||||||||||||||||||||
| 793 | |||||||||||||||||||||||||||||||||||||||||||
| 794 | my %opts = | ||||||||||||||||||||||||||||||||||||||||||
| 795 | 109 | map { ( $_ => $self->{____oop_perlish_class_opts}->{$_} ) } | |||||||||||||||||||||||||||||||||||||||||
| 796 | 136 | grep { !exists( $required_fields_lut{$_} ) } keys %{ $self->{____oop_perlish_class_opts} }; | |||||||||||||||||||||||||||||||||||||||||
| 797 | |||||||||||||||||||||||||||||||||||||||||||
| 798 | # prepopulate accessors so that calls that cascade will have values assigned | ||||||||||||||||||||||||||||||||||||||||||
| 799 | # Set everything by accessor that we ->can() | ||||||||||||||||||||||||||||||||||||||||||
| 800 | 136 | ▶ | while( my ( $method, $value ) = each %opts ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 801 | 109 | ▶ | $self->$method($value) if( $self->can($method) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 802 | } | ||||||||||||||||||||||||||||||||||||||||||
| 803 | |||||||||||||||||||||||||||||||||||||||||||
| 804 | 136 | $self->____validate_defaults(); | |||||||||||||||||||||||||||||||||||||||||
| 805 | |||||||||||||||||||||||||||||||||||||||||||
| 806 | # reset all accessors for actually set values, re-running cascades where applicable... | ||||||||||||||||||||||||||||||||||||||||||
| 807 | # there must be a better way, but this works | ||||||||||||||||||||||||||||||||||||||||||
| 808 | 131 | ▶ | while( my ( $method, $value ) = each %opts ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 809 | 109 | ▶ | $self->$method($value) if( $self->can($method) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 810 | } | ||||||||||||||||||||||||||||||||||||||||||
| 811 | 131 | return; | |||||||||||||||||||||||||||||||||||||||||
| 812 | } | ||||||||||||||||||||||||||||||||||||||||||
| 813 | |||||||||||||||||||||||||||||||||||||||||||
| 814 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 815 | ## verify all default values are valid for the class | ||||||||||||||||||||||||||||||||||||||||||
| 816 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 817 | ## FIXME: make this static | ||||||||||||||||||||||||||||||||||||||||||
| 818 | ############################################################################################ | ||||||||||||||||||||||||||||||||||||||||||
| 819 | sub ____validate_defaults(@) | ||||||||||||||||||||||||||||||||||||||||||
| 820 | 136 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
____validate_defaults: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 821 | 136 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 822 | |||||||||||||||||||||||||||||||||||||||||||
| 823 | 136 | for my $field ( keys %{ $self->____OOP_PERLISH_CLASS_ACCESSORS() } ) { | |||||||||||||||||||||||||||||||||||||||||
| 824 | 59 | $self->____OOP_PERLISH_CLASS_ACCESSORS()->{$field}->self($self); | |||||||||||||||||||||||||||||||||||||||||
| 825 | 59 | $self->____OOP_PERLISH_CLASS_ACCESSORS()->{$field}->__validate_default(); | |||||||||||||||||||||||||||||||||||||||||
| 826 | } | ||||||||||||||||||||||||||||||||||||||||||
| 827 | 131 | return; | |||||||||||||||||||||||||||||||||||||||||
| 828 | } | ||||||||||||||||||||||||||||||||||||||||||
| 829 | } | ||||||||||||||||||||||||||||||||||||||||||
| 830 | 7 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 831 | __END__ | ||||||||||||||||||||||||||||||||||||||||||