blib/lib/Config/Model/Role/WarpMaster.pm

filter: Statementstmt 100% 51 / 51 Branchbran 83.3% 10 / 12 Conditioncond 100% 5 / 5 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 11 / 11 Podpod 100% 4 / 4 totaltotal 97.6% 83 / 85 CC 11 SCAR 11.9
CC
11
Cov
97%
trigger_warp
6.0
unregister
4.1
register
3.0
CRAP 3.3
« blib/lib/Config/Model/TypeConstraints.pm ↑ Summary blib/lib/Config/Model/Role/NodeLoader.pm »
1 #
2 # This file is part of Config-Model
3 #
4 # This software is Copyright (c) 2005-2022 by Dominique Dumont.
5 #
6 # This is free software, licensed under:
7 #
8 # The GNU Lesser General Public License, Version 2.1, February 1999
9 #
10 package Config::Model::Role::WarpMaster 2.169;
11  
12 # ABSTRACT: register and trigger a warped element
13  
14 59 ▶use Mouse::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 59 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 59 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 59 ▶use Mouse::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 59 ▶use Log::Log4perl qw(get_logger :levels);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 59 ▶use Scalar::Util qw/weaken/;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 59 my $logger = get_logger("Warper");
23  
24 has 'warp_these_objects' => (
25 traits => ['Array'],
26 is => 'ro',
27 isa => 'ArrayRef',
28 4326 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
29 59 handles => {
30 _slave_info => 'elements',
31 _add_slave_info => 'push',
32 _delete_slave => 'delete',
33 has_warped_slaves => 'count',
34 # find_slave_idx => 'first_index', not available in Mouse
35 },
36 );
37  
38 505 ▶sub register {
Subroutine register: called CC=3 SCAR=11.0
Pod documented
39 505 my ( $self, $warped, $warper_name ) = @_;
40  
41 505 my $w_name = $warped->name;
42 505 ▶ $logger->debug( $self->get_type . ": " . $self->name, " registered $w_name ($warper_name)" )
Branch: 1 branch
BranchTrueFalseTotal
if $logger->is_debug 4 501 505
43 if $logger->is_debug;
44  
45 # weaken only applies to the passed reference, and there's no way
46 # to duplicate a weak ref. Only a strong ref is created. See
47 # qw(weaken) module for weaken()
48 505 my @tmp = ( $warped, $w_name, $warper_name );
49 505 weaken( $tmp[0] );
50 505 $self->_add_slave_info( \@tmp );
51  
52 505 ▶ return defined $self->{compute} ? 'computed' : 'regular';
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'compute'} ? : 1 504 505
53 }
54  
55 2 ▶sub unregister {
Subroutine unregister: called CC=4 SCAR=14.0
Pod documented
56 2 my ( $self, $w_name ) = @_;
57 2 ▶ $logger->debug( $self->get_type .": " . $self->name, " unregister $w_name" )
Branch: 1 branch
BranchTrueFalseTotal
if $logger->is_debug 0 2 2
58 if $logger->is_debug;
59  
60 2 my $idx = 0;
61 2 foreach my $info ($self->_slave_info) {
62 2 ▶ last if $info->[0] eq $w_name ;
Branch: 1 branch
BranchTrueFalseTotal
if $info->[0] eq $w_name 0 2 2
63 2 $idx++;
64 }
65  
66 2 $self->_delete_slave($idx);
67 2 return;
68 }
69  
70 # And I'm going to warp them ...
71 128 ▶sub trigger_warp {
Subroutine trigger_warp: called CC=6 SCAR=17.9
Pod documented
72 128 my $self = shift;
73 128 my $value = shift;
74 128 ▶ my $str_val = shift // $value // 'undefined';
Condition100%5/5
(shift() // $value) // "undefined"
l!l
1271
shift() // $value
l!l&&r!l&&!r
41231
MC/DC100%2/2
(shift() // $value) // "undefined"
shift() $value
Truth table100%3/3
A // B
A= shift()B= $value
ABresult
1X1
011
000
75  
76 128 foreach my $ref ( $self->_slave_info ) {
77 358 my ( $warped, $w_name, $warp_index ) = @$ref;
78 358 ▶ next unless defined $warped; # $warped is a weak ref and may vanish
Branch: 1 branch
BranchTrueFalseTotal
unless defined $warped 36 322 358
79  
80 # pure warp of object
81 322 ▶ if ($logger->is_debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($logger->is_debug) 3 319 322
82 3 $logger->debug("trigger_warp: ".$self->get_type." ", $self->name,
83 " warps '$w_name' with value <$str_val> ");
84 }
85 322 $warped->trigger( $value, $warp_index );
86 }
87 127 return;
88 }
89  
90 1405 ▶sub get_warped_slaves {
Subroutine get_warped_slaves: called CC=1 SCAR=0.0
Pod documented
91 1405 my $self = shift;
92  
93 # grep is used to clean up weak ref to object that were destroyed
94 1405 return grep { defined $_ } map { $_->[0] } $self->_slave_info;
95 }
96  
97 59 1;
98  
99 __END__
« blib/lib/Config/Model/TypeConstraints.pm ↑ Summary blib/lib/Config/Model/Role/NodeLoader.pm »