| 1 | package SPOPS::ClassFactory; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # $Id: ClassFactory.pm,v 3.6 2004/06/02 00:48:21 lachoy Exp $ | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 18 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 18 | ▶ | use base qw( Exporter ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 18 | ▶ | use Log::Log4perl qw( get_logger ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 18 | ▶ | use Class::ISA; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 18 | ▶ | use Data::Dumper qw( Dumper ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 18 | ▶ | use SPOPS; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 18 | ▶ | use SPOPS::Exception; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 18 | $SPOPS::ClassFactory::VERSION = sprintf("%d.%02d", q$Revision: 3.6 $ =~ /(\d+)\.(\d+)/); | |||||||||||||||||||||||||||
| 15 | 18 | @SPOPS::ClassFactory::EXPORT_OK = qw( OK DONE NOTIFY ERROR RESTART | |||||||||||||||||||||||||||
| 16 | FACTORY_METHOD RULESET_METHOD ); | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 18 | ▶ | use constant OK => 'OK'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 18 | ▶ | use constant DONE => 'DONE'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 18 | ▶ | use constant NOTIFY => 'NOTIFY'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 18 | ▶ | use constant ERROR => 'ERROR'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 18 | ▶ | use constant RESTART => 'RESTART'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 18 | ▶ | use constant FACTORY_METHOD => 'behavior_factory'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 18 | ▶ | use constant RULESET_METHOD => 'ruleset_factory'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 18 | my $log = get_logger(); | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 18 | my %REQ_CLASSES = (); | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 18 | my $PK = '__private__'; # Save typing... | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | # TODO: Export constants with the names of these slots -- the order | ||||||||||||||||||||||||||||
| 33 | # doesn't matter to anyone except us, so we shouldn't need to export | ||||||||||||||||||||||||||||
| 34 | # order and be able to keep the variable a lexical | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 18 | my @SLOTS = qw( | |||||||||||||||||||||||||||
| 37 | manipulate_configuration id_method read_code | ||||||||||||||||||||||||||||
| 38 | fetch_by has_a links_to add_rule | ||||||||||||||||||||||||||||
| 39 | ); | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 18 | my %SLOT_NUM = map { $SLOTS[ $_ ] => $_ } ( 0 .. ( scalar @SLOTS - 1 ) ); | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | ######################################## | ||||||||||||||||||||||||||||
| 45 | # MAIN INTERFACE | ||||||||||||||||||||||||||||
| 46 | ######################################## | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | # TODO: Will $config ever be an object? Also, is 'create' the best | ||||||||||||||||||||||||||||
| 49 | # name? | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | sub create { | ||||||||||||||||||||||||||
|
Subroutine
create: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 52 | 0 | my ( $class, $all_config, $p ) = @_; | |||||||||||||||||||||||||||
| 53 | 0 | ▶ | return [] unless ( ref $all_config eq 'HASH' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 0 | ▶ | $p ||= {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$p ||= {}
MC/DC0%0/1
$p ||= {}
$p
Truth table0%0/2
A
A= $p
| |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | $class->create_all_stubs( $all_config, $p ); | |||||||||||||||||||||||||||
| 57 | 0 | $class->find_all_behavior( $all_config, $p ); | |||||||||||||||||||||||||||
| 58 | 0 | $class->exec_all_behavior( $all_config, $p ); | |||||||||||||||||||||||||||
| 59 | 0 | $class->clean_all_behavior( $all_config, $p ); | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 0 | my $alias_list = $class->get_alias_list( $all_config, $p ); | |||||||||||||||||||||||||||
| 62 | 0 | return [ map { $all_config->{ $_ }->{class} } | |||||||||||||||||||||||||||
| 63 | 0 | grep { defined $all_config->{ $_ }->{class} } | |||||||||||||||||||||||||||
| 64 | 0 | @{ $alias_list } ]; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | ######################################## | ||||||||||||||||||||||||||||
| 69 | # MULTI-CONFIG METHODS | ||||||||||||||||||||||||||||
| 70 | ######################################## | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | # These methods operate on $all_config, a hashref of SPOPS | ||||||||||||||||||||||||||||
| 73 | # configuration hashrefs | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | # First, we need to create the class so we can have an inheritance | ||||||||||||||||||||||||||||
| 77 | # tree to walk -- think of this as the ur-behavior, or the beginning | ||||||||||||||||||||||||||||
| 78 | # of the chicken-and-egg, or... | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 0 | ▶ | sub create_all_stubs { | ||||||||||||||||||||||||||
|
Subroutine
create_all_stubs: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 81 | 0 | my ( $class, $all_config, $p ) = @_; | |||||||||||||||||||||||||||
| 82 | 0 | my $alias_list = $class->get_alias_list( $all_config, $p ); | |||||||||||||||||||||||||||
| 83 | 0 | foreach my $alias ( @{ $alias_list } ) { | |||||||||||||||||||||||||||
| 84 | 0 | my $this_class = $all_config->{ $alias }{class}; | |||||||||||||||||||||||||||
| 85 | 0 | ▶ | $all_config->{ $alias }->{main_alias} ||= $alias; | ||||||||||||||||||||||||||
|
Condition0%0/3
$all_config->{$alias}{"main_alias"} ||= $alias
MC/DC0%0/2
$all_config->{$alias}{"main_alias"} ||= $alias
$all_config->{$alias}{"main_alias"}
$alias
Truth table0%0/3
A ||= B
A= $all_config->{$alias}{"main_alias"}B= $alias
| |||||||||||||||||||||||||||||
| 86 | 0 | my ( $status, $msg ) = $class->create_stub( $all_config->{ $alias } ); | |||||||||||||||||||||||||||
| 87 | 0 | ▶ | if ( $status eq ERROR ) { SPOPS::Exception->throw( $msg ) } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 0 | my ( $cfg_status, $cfg_msg ) = $class->install_configuration( $this_class, $all_config->{ $alias } ); | |||||||||||||||||||||||||||
| 89 | 0 | ▶ | if ( $cfg_status eq ERROR ) { SPOPS::Exception->throw( $cfg_msg ) } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | # Now that the class is created with at least @ISA defined, we can | ||||||||||||||||||||||||||||
| 95 | # walk through @ISA for each class and install all the behaviors | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 0 | ▶ | sub find_all_behavior { | ||||||||||||||||||||||||||
|
Subroutine
find_all_behavior: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 98 | 0 | my ( $class, $all_config, $p ) = @_; | |||||||||||||||||||||||||||
| 99 | 0 | my $alias_list = $class->get_alias_list( $all_config, $p ); | |||||||||||||||||||||||||||
| 100 | 0 | foreach my $alias ( @{ $alias_list } ) { | |||||||||||||||||||||||||||
| 101 | 0 | my $this_class = $all_config->{ $alias }{class}; | |||||||||||||||||||||||||||
| 102 | 0 | my $this_config = $this_class->CONFIG; | |||||||||||||||||||||||||||
| 103 | 0 | $this_config->{ $PK }{behavior_table} = {}; | |||||||||||||||||||||||||||
| 104 | 0 | $this_config->{ $PK }{behavior_run} = {}; | |||||||||||||||||||||||||||
| 105 | 0 | $this_config->{ $PK }{behavior_map} = $class->find_behavior( $this_class ); | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | # Now execute the behavior for each slot-and-alias. Note that we | ||||||||||||||||||||||||||||
| 111 | # cannot do this in reverse order (alias-and-slot) because some later | ||||||||||||||||||||||||||||
| 112 | # slots (particularly the relationship ones) may depend on earlier | ||||||||||||||||||||||||||||
| 113 | # slots being executed for other classes. | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 0 | ▶ | sub exec_all_behavior { | ||||||||||||||||||||||||||
|
Subroutine
exec_all_behavior: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 116 | 0 | my ( $class, $all_config, $p ) = @_; | |||||||||||||||||||||||||||
| 117 | 0 | my $alias_list = $class->get_alias_list( $all_config, $p ); | |||||||||||||||||||||||||||
| 118 | 0 | foreach my $slot_name ( @SLOTS ) { | |||||||||||||||||||||||||||
| 119 | 0 | foreach my $alias ( @{ $alias_list } ) { | |||||||||||||||||||||||||||
| 120 | 0 | my $this_class = $all_config->{ $alias }{class}; | |||||||||||||||||||||||||||
| 121 | 0 | $class->exec_behavior( $slot_name, $this_class ); | |||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | # Remove all evidence of behaviors, tracking, etc. -- nobody should | ||||||||||||||||||||||||||||
| 128 | # need this information once the class has been created. | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 0 | ▶ | sub clean_all_behavior { | ||||||||||||||||||||||||||
|
Subroutine
clean_all_behavior: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 131 | 0 | my ( $class, $all_config, $p ) = @_; | |||||||||||||||||||||||||||
| 132 | 0 | my $alias_list = $class->get_alias_list( $all_config, $p ); | |||||||||||||||||||||||||||
| 133 | 0 | foreach my $alias ( @{ $alias_list } ) { | |||||||||||||||||||||||||||
| 134 | 0 | my $this_class = $all_config->{ $alias }{class}; | |||||||||||||||||||||||||||
| 135 | 0 | delete $this_class->CONFIG->{ $PK }; | |||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | ######################################## | ||||||||||||||||||||||||||||
| 141 | # CREATE CLASS | ||||||||||||||||||||||||||||
| 142 | ######################################## | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | # EVAL'ABLE PACKAGE/SUBROUTINES | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | # Here's our template for a module on the fly. Super easy. | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 18 | my $GENERIC_TEMPLATE = <<'PACKAGE'; | |||||||||||||||||||||||||||
| 149 | @%%CLASS%%::ISA = qw( %%ISA%% ); | ||||||||||||||||||||||||||||
| 150 | $%%CLASS%%::C = {}; | ||||||||||||||||||||||||||||
| 151 | sub %%CLASS%%::CONFIG { return $%%CLASS%%::C; } | ||||||||||||||||||||||||||||
| 152 | PACKAGE | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 0 | ▶ | sub create_stub { | ||||||||||||||||||||||||||
|
Subroutine
create_stub: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 155 | 0 | my ( $class, $config ) = @_; | |||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 0 | my $this_class = $config->{class}; | |||||||||||||||||||||||||||
| 158 | 0 | ▶ | $log->is_debug && | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 159 | $log->debug( "Creating stub ($this_class) with main alias ($config->{main_alias})"); | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | # Create the barest information forming the class; just substitute our | ||||||||||||||||||||||||||||
| 162 | # keywords (currently only the class name) for the items in the | ||||||||||||||||||||||||||||
| 163 | # generic template above. | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 0 | my $module = $GENERIC_TEMPLATE; | |||||||||||||||||||||||||||
| 166 | 0 | $module =~ s/%%CLASS%%/$this_class/g; | |||||||||||||||||||||||||||
| 167 | 0 | my $isa_listing = join( ' ', @{ $config->{isa} } ); | |||||||||||||||||||||||||||
| 168 | 0 | $module =~ s/%%ISA%%/$isa_listing/g; | |||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | 0 | ▶ | $log->is_debug && | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 171 | $log->debug( "Trying to create class with the code:\n$module\n" ); | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | # Capture 'warn' calls that get triggered as a result of warnings, | ||||||||||||||||||||||||||||
| 174 | # redefined subroutines or whatnot; these get dumped to STDERR and | ||||||||||||||||||||||||||||
| 175 | # we want to be as quiet as possible -- or at least control our | ||||||||||||||||||||||||||||
| 176 | # noise! | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | { | ||||||||||||||||||||||||||||
| 179 | 0 | ▶ | local $SIG{__WARN__} = sub { return undef }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 180 | 0 | eval $module; | |||||||||||||||||||||||||||
| 181 | 0 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 182 | 0 | return ( ERROR, "Error creating stub class [$this_class] with " . | |||||||||||||||||||||||||||
| 183 | "code\n$module\nError: $@" ); | ||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||
| 186 | 0 | return $class->require_config_classes( $config ); | |||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | # Just step through @{ $config->{isa} } and 'require' each entry | ||||||||||||||||||||||||||||
| 191 | # unless it's already been; also require everything in | ||||||||||||||||||||||||||||
| 192 | # @{ $config->{rules_from} } | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | 0 | ▶ | sub require_config_classes { | ||||||||||||||||||||||||||
|
Subroutine
require_config_classes: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 195 | 0 | my ( $class, $config ) = @_; | |||||||||||||||||||||||||||
| 196 | 0 | my $this_class = $config->{class}; | |||||||||||||||||||||||||||
| 197 | 0 | ▶ | my $rules_from = $config->{rules_from} || []; | ||||||||||||||||||||||||||
|
Condition0%0/2
$config->{'rules_from'} || []
MC/DC0%0/1
$config->{'rules_from'} || []
$config->{'rules_from'}
Truth table0%0/2
A
A= $config->{'rules_from'}
| |||||||||||||||||||||||||||||
| 198 | 0 | foreach my $req_class ( @{ $config->{isa} }, @{ $rules_from } ) { | |||||||||||||||||||||||||||
| 199 | 0 | ▶ | next unless ( $req_class ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 200 | 0 | ▶ | next if ( $REQ_CLASSES{ $req_class } ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 201 | 0 | eval "require $req_class"; | |||||||||||||||||||||||||||
| 202 | 0 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 203 | 0 | return ( ERROR, "Error requiring class [$req_class] from ISA " . | |||||||||||||||||||||||||||
| 204 | "or 'rules_from' in [$this_class]: $@" ); | ||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||
| 206 | $log->is_debug && | ||||||||||||||||||||||||||||
| 207 | 0 | ▶ | $log->debug( "Class [$req_class] require'd by [$this_class] ok." ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 208 | 0 | $REQ_CLASSES{ $req_class }++; | |||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||
| 210 | 0 | return ( OK, undef ); | |||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | ######################################## | ||||||||||||||||||||||||||||
| 215 | # INSTALL CONFIGURATION | ||||||||||||||||||||||||||||
| 216 | ######################################## | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | # Just take the config from the $all_config (or wherever) and install | ||||||||||||||||||||||||||||
| 219 | # it to the class -- we aren't doing any manipulation or anything, | ||||||||||||||||||||||||||||
| 220 | # just copying over the original config key by key. Manipulation comes later. | ||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | 0 | ▶ | sub install_configuration { | ||||||||||||||||||||||||||
|
Subroutine
install_configuration: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 223 | 0 | my ( $class, $this_class, $config ) = @_; | |||||||||||||||||||||||||||
| 224 | 0 | ▶ | $log->is_info && | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 225 | $log->info( "Installing configuration to class ($this_class)" ); | ||||||||||||||||||||||||||||
| 226 | 0 | ▶ | $log->is_debug && | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 227 | $log->debug( "Config ($this_class)\n", Dumper( $config ) ); | ||||||||||||||||||||||||||||
| 228 | 0 | my $class_config = $this_class->CONFIG; | |||||||||||||||||||||||||||
| 229 | 0 | ▶ | while ( my ( $k, $v ) = each %{ $config } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 230 | 0 | $class_config->{ $k } = $v; | |||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||
| 232 | 0 | return ( OK, undef ); | |||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | ######################################## | ||||||||||||||||||||||||||||
| 237 | # FIND BEHAVIOR | ||||||||||||||||||||||||||||
| 238 | ######################################## | ||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | # Find all the factory method-generators in all members of a class's | ||||||||||||||||||||||||||||
| 241 | # ISA, then run each of the generators and keep track of the slots | ||||||||||||||||||||||||||||
| 242 | # each generator uses (behavior map) | ||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | 0 | ▶ | sub find_behavior { | ||||||||||||||||||||||||||
|
Subroutine
find_behavior: not called CC=13 SCAR=52.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 245 | 0 | my ( $class, $this_class ) = @_; | |||||||||||||||||||||||||||
| 246 | 0 | my $this_config = $this_class->CONFIG; | |||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | # Allow config to specify ClassFactory-only classes in | ||||||||||||||||||||||||||||
| 249 | # 'rules_from' configuration key. | ||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | 0 | ▶ | my $rule_classes = $this_config->{rules_from} || []; | ||||||||||||||||||||||||||
|
Condition0%0/2
$this_config->{'rules_from'} || []
MC/DC0%0/1
$this_config->{'rules_from'} || []
$this_config->{'rules_from'}
Truth table0%0/2
A
A= $this_config->{'rules_from'}
| |||||||||||||||||||||||||||||
| 252 | 0 | my $subs = $class->find_parent_methods( $this_class, $rule_classes, FACTORY_METHOD ); | |||||||||||||||||||||||||||
| 253 | 0 | my %behavior_map = (); | |||||||||||||||||||||||||||
| 254 | 0 | foreach my $sub_info ( @{ $subs } ) { | |||||||||||||||||||||||||||
| 255 | 0 | my $behavior_gen_class = $sub_info->[0]; | |||||||||||||||||||||||||||
| 256 | 0 | my $behavior_gen_sub = $sub_info->[1]; | |||||||||||||||||||||||||||
| 257 | 0 | ▶ | next if ( defined $behavior_map{ $behavior_gen_class } ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | # Execute the behavior factory and map the returned | ||||||||||||||||||||||||||||
| 260 | # information (slot => coderef or slot => \@( coderef )) into | ||||||||||||||||||||||||||||
| 261 | # the class config. | ||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | 0 | ▶ | my $behaviors = $behavior_gen_sub->( $this_class ) || {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
&$behavior_gen_sub($this_class) || {}
MC/DC0%0/1
&$behavior_gen_sub($this_class) || {}
&$behavior_gen_sub($this_class)
Truth table0%0/2
A
A= &$behavior_gen_sub($this_class)
| |||||||||||||||||||||||||||||
| 264 | $log->is_debug && | ||||||||||||||||||||||||||||
| 265 | $log->debug( "Behaviors returned for ($this_class): ", | ||||||||||||||||||||||||||||
| 266 | 0 | ▶ | join( ', ', keys %{ $behaviors } ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 267 | 0 | foreach my $slot_name ( keys %{ $behaviors } ) { | |||||||||||||||||||||||||||
| 268 | 0 | my $typeof = ref $behaviors->{ $slot_name }; | |||||||||||||||||||||||||||
| 269 | 0 | ▶ | next unless ( $typeof eq 'CODE' or $typeof eq 'ARRAY' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$typeof eq "CODE" or $typeof eq "ARRAY"
MC/DC0%0/2
$typeof eq "CODE" or $typeof eq "ARRAY"
$typeof eq "CODE"
$typeof eq "ARRAY"
Truth table0%0/3
A or B
A= $typeof eq "CODE"B= $typeof eq "ARRAY"
| |||||||||||||||||||||||||||||
| 270 | 0 | ▶ | $log->is_debug && | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 271 | $log->debug( "Adding slot behaviors for ($slot_name)" ); | ||||||||||||||||||||||||||||
| 272 | 0 | ▶ | if ( $typeof eq 'CODE' ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 273 | 0 | push @{ $this_config->{ $PK }{behavior_table}{ $slot_name } }, | |||||||||||||||||||||||||||
| 274 | 0 | $behaviors->{ $slot_name }; | |||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||
| 276 | elsif ( $typeof eq 'ARRAY' ) { | ||||||||||||||||||||||||||||
| 277 | 0 | ▶ | next unless ( scalar @{ $behaviors->{ $slot_name } } ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 278 | 0 | push @{ $this_config->{ $PK }{behavior_table}{ $slot_name } }, | |||||||||||||||||||||||||||
| 279 | 0 | @{ $behaviors->{ $slot_name } }; | |||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||
| 281 | 0 | $behavior_map{ $behavior_gen_class }->{ $slot_name }++; | |||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||
| 284 | 0 | return \%behavior_map; | |||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||
| 288 | # Find all instances of method $method supported by classes in the ISA | ||||||||||||||||||||||||||||
| 289 | # of $class as well as in \@added_classes. Hooray for Class::ISA! | ||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||
| 291 | 0 | ▶ | sub find_parent_methods { | ||||||||||||||||||||||||||
|
Subroutine
find_parent_methods: not called CC=8 SCAR=40.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 292 | 0 | my ( $class, $this_class, $added_classes, @method_list ) = @_; | |||||||||||||||||||||||||||
| 293 | 0 | ▶ | return [] unless ( $this_class ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 294 | 0 | ▶ | unless ( ref $added_classes eq 'ARRAY' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 295 | 0 | $added_classes = []; | |||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||
| 297 | 0 | my @all_classes = ( @{ $added_classes }, | |||||||||||||||||||||||||||
| 298 | Class::ISA::self_and_super_path( $this_class ) ); | ||||||||||||||||||||||||||||
| 299 | 0 | my @subs = (); | |||||||||||||||||||||||||||
| 300 | 0 | foreach my $check_class ( @all_classes ) { | |||||||||||||||||||||||||||
| 301 | 18 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 302 | 0 | my $src = \%{ $check_class . '::' }; | |||||||||||||||||||||||||||
| 303 | METHOD: | ||||||||||||||||||||||||||||
| 304 | 0 | foreach my $method ( @method_list ) { | |||||||||||||||||||||||||||
| 305 | 0 | ▶ | if ( defined( $src->{ $method } ) and | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $src->{$method} and defined(my $sub = *{$src->{$method};}{"CODE"})
MC/DC0%0/2
defined $src->{$method} and defined(my $sub = *{$src->{$method};}{"CODE"})
defined $src->{$method}
defined(my $sub = *{$src->{$method};}{"CODE"})
Truth table0%0/3
A and B
A= defined $src->{$method}B= defined(my $sub = *{$src->{$method};}{"CODE"})
| |||||||||||||||||||||||||||||
| 306 | 0 | defined( my $sub = *{ $src->{ $method } }{CODE} ) ) { | |||||||||||||||||||||||||||
| 307 | 0 | push @subs, [ $check_class, $sub ]; | |||||||||||||||||||||||||||
| 308 | 0 | ▶ | $log->is_debug && | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 309 | $log->debug( "($this_class): Found ($method) in class ($check_class)" ); | ||||||||||||||||||||||||||||
| 310 | 0 | last METHOD; | |||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||
| 314 | 0 | return \@subs; | |||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||
| 318 | ######################################## | ||||||||||||||||||||||||||||
| 319 | # EXECUTE BEHAVIOR | ||||||||||||||||||||||||||||
| 320 | ######################################## | ||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||
| 323 | # Execute behavior rules for a particular SPOPS class and slot configuration | ||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||
| 325 | 0 | ▶ | sub exec_behavior { | ||||||||||||||||||||||||||
|
Subroutine
exec_behavior: not called CC=17 SCAR=57.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 326 | 0 | my ( $class, $slot_name, $this_class ) = @_; | |||||||||||||||||||||||||||
| 327 | 0 | my $this_config = $this_class->CONFIG; | |||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||
| 329 | # Grab the behavior list and see how many there are to execute; if | ||||||||||||||||||||||||||||
| 330 | # none, then we're all done with this slot | ||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||
| 332 | 0 | my $behavior_list = $this_config->{ $PK }{behavior_table}{ $slot_name }; | |||||||||||||||||||||||||||
| 333 | 0 | ▶ | return 1 unless ( ref $behavior_list eq 'ARRAY' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 334 | 0 | my $num_behaviors = scalar @{ $behavior_list }; | |||||||||||||||||||||||||||
| 335 | 0 | ▶ | return 1 unless ( $num_behaviors > 0 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 336 | 0 | ▶ | $log->is_debug && | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 337 | $log->debug( "# behaviors in ($this_class)($slot_name): $num_behaviors" ); | ||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||
| 339 | # Cycle through the behaviors for this slot. Note that they are | ||||||||||||||||||||||||||||
| 340 | # currently unordered -- that is, the order shouldn't | ||||||||||||||||||||||||||||
| 341 | # matter. (Whether this is true remains to be seen...) | ||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||
| 343 | BEHAVIOR: | ||||||||||||||||||||||||||||
| 344 | 0 | foreach my $behavior ( @{ $behavior_list } ) { | |||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||
| 346 | 0 | ▶ | $log->is_debug && | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 347 | $log->debug( "Running behavior for slot ($slot_name) and class ($this_class)" ); | ||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||
| 349 | # If this behavior has already been run, then skip it. This | ||||||||||||||||||||||||||||
| 350 | # becomes relevant when we get a RESTART status from one of | ||||||||||||||||||||||||||||
| 351 | # the behaviors (below) | ||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||
| 353 | 0 | ▶ | if ( $this_config->{ $PK }{behavior_run}{ $behavior } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 354 | 0 | ▶ | $log->is_debug && | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 355 | $log->debug( "Skipping behavior, already run." ); | ||||||||||||||||||||||||||||
| 356 | 0 | next BEHAVIOR; | |||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||
| 358 | # Every behavior should return a two-element list with the | ||||||||||||||||||||||||||||
| 359 | # status and (potentially empty) message | ||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||
| 361 | 0 | my ( $status, $msg ) = $behavior->( $this_class ); | |||||||||||||||||||||||||||
| 362 | 0 | ▶ | $log->is_info && | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 363 | $log->info( "Status returned from behavior: ($status)" ); | ||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||
| 365 | 0 | ▶ | if ( $status eq ERROR ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 366 | 0 | SPOPS::Exception->throw( "Cannot run behavior in [$slot_name] [$this_class]: $msg" ); | |||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||
| 369 | # If anything but an error, go ahead and mark this behavior as | ||||||||||||||||||||||||||||
| 370 | # run. Note that we rely on coderefs always stringifying to | ||||||||||||||||||||||||||||
| 371 | # the same memory location. (This is a safe assumption, I think.) | ||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||
| 373 | 0 | $this_config->{ $PK }{behavior_run}{ $behavior }++; | |||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||
| 375 | # A 'DONE' means the behavior has decreed that no more | ||||||||||||||||||||||||||||
| 376 | # processing should be done in this slot | ||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||
| 378 | 0 | ▶ | return 1 if ( $status eq DONE ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||
| 380 | # An 'OK' is normal -- either the behavior declined to do | ||||||||||||||||||||||||||||
| 381 | # anything or did what it was supposed to do without issue | ||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||
| 383 | 0 | ▶ | next BEHAVIOR if ( $status eq OK ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||
| 385 | 0 | ▶ | if ( $status eq NOTIFY ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 386 | 0 | warn join( "\n", "WARNING executing $slot_name for $this_config->{class}", | |||||||||||||||||||||||||||
| 387 | "$msg", | ||||||||||||||||||||||||||||
| 388 | 'Process will continue' ), "\n"; | ||||||||||||||||||||||||||||
| 389 | 0 | next BEHAVIOR; | |||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||
| 392 | # RESTART is a little tricky. A 'RESTART' means that we need | ||||||||||||||||||||||||||||
| 393 | # to re-check this class for new behaviors. If we don't find | ||||||||||||||||||||||||||||
| 394 | # any new ones, no problem. If we do find new ones, then we | ||||||||||||||||||||||||||||
| 395 | # need to then re-run all behavior slots before this one. Note | ||||||||||||||||||||||||||||
| 396 | # that we will *NOT* re-run behaviors that have already been | ||||||||||||||||||||||||||||
| 397 | # run -- we're tracking them in 'behavior_run' | ||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||
| 399 | 0 | ▶ | if ( $status eq RESTART ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 400 | 0 | $class->sync_isa( $this_class ); | |||||||||||||||||||||||||||
| 401 | 0 | my $new_behavior_map = $class->find_behavior( $this_class ); | |||||||||||||||||||||||||||
| 402 | my $behaviors_same = $class->compare_behavior_map( | ||||||||||||||||||||||||||||
| 403 | $new_behavior_map, | ||||||||||||||||||||||||||||
| 404 | 0 | $this_config->{ $PK }{behavior_map} ); | |||||||||||||||||||||||||||
| 405 | 0 | ▶ | next BEHAVIOR if ( $behaviors_same ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 406 | 0 | ▶ | $log->is_debug && | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 407 | $log->debug( "Behaviors changed after receiving RESTART; re-running", | ||||||||||||||||||||||||||||
| 408 | "from slot ($SLOTS[0]) to ($slot_name)" ); | ||||||||||||||||||||||||||||
| 409 | 0 | $this_config->{ $PK }{behavior_map} = $new_behavior_map; | |||||||||||||||||||||||||||
| 410 | 0 | ▶ | for ( my $i = 0; $i <= $SLOT_NUM{ $slot_name }; $i++ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 411 | 0 | $class->exec_behavior( $SLOTS[ $i ], $this_class ); | |||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||
| 415 | 0 | return 1; | |||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||
| 419 | # Sync $this_class::ISA with $this_class->CONFIG->{isa} | ||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||
| 421 | 0 | ▶ | sub sync_isa { | ||||||||||||||||||||||||||
|
Subroutine
sync_isa: not called CC=3 SCAR=21.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 422 | 0 | my ( $class, $this_class ) = @_; | |||||||||||||||||||||||||||
| 423 | 0 | my $config_isa = $this_class->CONFIG->{isa}; | |||||||||||||||||||||||||||
| 424 | 18 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 425 | 0 | @{ $this_class . '::ISA' } = @{ $config_isa }; | |||||||||||||||||||||||||||
| 426 | $log->is_debug && | ||||||||||||||||||||||||||||
| 427 | 0 | ▶ | $log->debug( "ISA for ($this_class) synched, now: ", join( ', ', @{ $config_isa } ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 428 | 0 | my ( $status, $msg ) = $class->require_config_classes( $this_class->CONFIG ); | |||||||||||||||||||||||||||
| 429 | 0 | ▶ | if ( $status eq ERROR ) { SPOPS::Exception->throw( $msg ) } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 430 | 0 | return 1; | |||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||
| 434 | # Return false if the two behavior maps don't compare (in both | ||||||||||||||||||||||||||||
| 435 | # directions), true if they do | ||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||
| 437 | 0 | ▶ | sub compare_behavior_map { | ||||||||||||||||||||||||||
|
Subroutine
compare_behavior_map: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 438 | 0 | my ( $class, $b1, $b2 ) = @_; | |||||||||||||||||||||||||||
| 439 | 0 | ▶ | return undef unless ( $class->_compare_behaviors( $b1, $b2 ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 440 | 0 | ▶ | return undef unless ( $class->_compare_behaviors( $b2, $b1 ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 441 | 0 | return 1; | |||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||
| 445 | # Return false if all classes and slot names of behavior-1 are not in | ||||||||||||||||||||||||||||
| 446 | # behavior-2 | ||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||
| 448 | 0 | ▶ | sub _compare_behaviors { | ||||||||||||||||||||||||||
|
Subroutine
_compare_behaviors: not called CC=11 SCAR=48.8
| |||||||||||||||||||||||||||||
| 449 | 0 | my ( $class, $b1, $b2 ) = @_; | |||||||||||||||||||||||||||
| 450 | 0 | ▶ | return undef unless ( ref $b1 eq 'HASH' and ref $b2 eq 'HASH' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $b1 eq "HASH" and ref $b2 eq "HASH"
MC/DC0%0/2
ref $b1 eq "HASH" and ref $b2 eq "HASH"
ref $b1 eq "HASH"
ref $b2 eq "HASH"
Truth table0%0/3
A and B
A= ref $b1 eq "HASH"B= ref $b2 eq "HASH"
| |||||||||||||||||||||||||||||
| 451 | 0 | foreach my $b1_class ( keys %{ $b1 } ) { | |||||||||||||||||||||||||||
| 452 | 0 | ▶ | return undef unless ( $b2->{ $b1_class } ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 453 | 0 | ▶ | next if ( ! $b1->{ $b1_class } and ! $b2->{ $b1_class } ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$b1->{$b1_class} or $b2->{$b1_class}
MC/DC0%0/2
$b1->{$b1_class} or $b2->{$b1_class}
$b1->{$b1_class}
$b2->{$b1_class}
Truth table0%0/3
A or B
A= $b1->{$b1_class}B= $b2->{$b1_class}
| |||||||||||||||||||||||||||||
| 454 | 0 | ▶ | return undef if ( ref $b1->{ $b1_class } ne 'HASH' or ref $b2->{ $b1_class } ne 'HASH' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $b1->{$b1_class} ne "HASH" or ref $b2->{$b1_class} ne "HASH"
MC/DC0%0/2
ref $b1->{$b1_class} ne "HASH" or ref $b2->{$b1_class} ne "HASH"
ref $b1->{$b1_class} ne "HASH"
ref $b2->{$b1_class} ne "HASH"
Truth table0%0/3
A or B
A= ref $b1->{$b1_class} ne "HASH"B= ref $b2->{$b1_class} ne "HASH"
| |||||||||||||||||||||||||||||
| 455 | 0 | foreach my $b1_slot_name ( keys %{ $b1->{ $b1_class } } ) { | |||||||||||||||||||||||||||
| 456 | 0 | ▶ | return undef unless ( $b2->{ $b1_class }{ $b1_slot_name } ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||
| 459 | 0 | return 1; | |||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||
| 463 | ######################################## | ||||||||||||||||||||||||||||
| 464 | # UTILITY METHODS | ||||||||||||||||||||||||||||
| 465 | ######################################## | ||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||
| 467 | 0 | ▶ | sub get_alias_list { | ||||||||||||||||||||||||||
|
Subroutine
get_alias_list: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 468 | 0 | my ( $class, $all_config, $p ) = @_; | |||||||||||||||||||||||||||
| 469 | return [ grep ! /^_/, | ||||||||||||||||||||||||||||
| 470 | 0 | ( ref $p->{alias_list} eq 'ARRAY' and scalar @{ $p->{alias_list} } ) | |||||||||||||||||||||||||||
| 471 | 0 | ? @{ $p->{alias_list} } | |||||||||||||||||||||||||||
| 472 | 0 | ▶ | : keys %{ $all_config } ]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
ref $p->{"alias_list"} eq "ARRAY" and scalar @{$p->{"alias_list"};}
MC/DC0%0/1
ref $p->{"alias_list"} eq "ARRAY" and scalar @{$p->{"alias_list"};}
ref $p->{"alias_list"} eq "ARRAY"
Truth table0%0/2
A
A= ref $p->{"alias_list"} eq "ARRAY"
| |||||||||||||||||||||||||||||
| 473 | } | ||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||
| 475 | 18 | 1; | |||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||
| 477 | __END__ | ||||||||||||||||||||||||||||