| 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::AnyId 2.169; | ||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 39 | ▶ | use 5.020; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 39 | ▶ | use Mouse; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 39 | with "Config::Model::Role::NodeLoader"; | |||||||||||||||||||||||||||||||||||||||||||||
| 16 | 39 | with "Config::Model::Role::Utils"; | |||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 39 | ▶ | use Config::Model::Exception; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 39 | ▶ | use Config::Model::Warper; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 39 | ▶ | use Carp qw/cluck croak carp/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 39 | ▶ | use Log::Log4perl qw(get_logger :levels); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 39 | ▶ | use Storable qw/dclone/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 39 | ▶ | use Mouse::Util::TypeConstraints; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 39 | ▶ | use Scalar::Util qw/weaken/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 39 | extends qw/Config::Model::AnyThing/; | |||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 39 | ▶ | use feature qw/signatures postderef/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 39 | ▶ | no warnings qw/experimental::signatures experimental::postderef/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 39 | subtype 'KeyArray' => as 'ArrayRef' ; | |||||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | coerce 'KeyArray' => from 'Str' => via { [$_] } ; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 39 | my $logger = get_logger("Tree::Element::Id"); | |||||||||||||||||||||||||||||||||||||||||||||
| 35 | 39 | my $user_logger = get_logger("User"); | |||||||||||||||||||||||||||||||||||||||||||||
| 36 | 39 | my $deep_check_logger = get_logger('DeepCheck'); | |||||||||||||||||||||||||||||||||||||||||||||
| 37 | 39 | my $fix_logger = get_logger("Anything::Fix"); | |||||||||||||||||||||||||||||||||||||||||||||
| 38 | 39 | my $change_logger = get_logger("ChangeTracker"); | |||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 39 | enum 'DataMode' => [qw/preset layered normal/]; | |||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||
| 42 | has data_mode => ( | ||||||||||||||||||||||||||||||||||||||||||||||
| 43 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||
| 44 | isa => 'HashRef[DataMode]', | ||||||||||||||||||||||||||||||||||||||||||||||
| 45 | traits => ['Hash'], | ||||||||||||||||||||||||||||||||||||||||||||||
| 46 | handles => { | ||||||||||||||||||||||||||||||||||||||||||||||
| 47 | get_data_mode => 'get', | ||||||||||||||||||||||||||||||||||||||||||||||
| 48 | set_data_mode => 'set', | ||||||||||||||||||||||||||||||||||||||||||||||
| 49 | delete_data_mode => 'delete', | ||||||||||||||||||||||||||||||||||||||||||||||
| 50 | clear_data_mode => 'clear', | ||||||||||||||||||||||||||||||||||||||||||||||
| 51 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 537 | ▶ | default => sub { {}; } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 39 | ); | |||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | # this is cleared and set by set_properties | ||||||||||||||||||||||||||||||||||||||||||||||
| 56 | has _warpable_check_content_actions => ( | ||||||||||||||||||||||||||||||||||||||||||||||
| 57 | is => 'bare', # no direct accessor | ||||||||||||||||||||||||||||||||||||||||||||||
| 58 | isa => 'ArrayRef[CodeRef]', | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | traits => ['Array'], | ||||||||||||||||||||||||||||||||||||||||||||||
| 60 | handles => { | ||||||||||||||||||||||||||||||||||||||||||||||
| 61 | add_warpable_check_content => 'push', | ||||||||||||||||||||||||||||||||||||||||||||||
| 62 | clear_warpable_check_content => 'clear', | ||||||||||||||||||||||||||||||||||||||||||||||
| 63 | get_all_warpable_content_checks => 'elements', | ||||||||||||||||||||||||||||||||||||||||||||||
| 64 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 537 | ▶ | default => sub { []; } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 39 | ); | |||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||
| 68 | has _check_content_actions => ( | ||||||||||||||||||||||||||||||||||||||||||||||
| 69 | is => 'bare', # no direct accessor | ||||||||||||||||||||||||||||||||||||||||||||||
| 70 | isa => 'ArrayRef[CodeRef]', | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | traits => ['Array'], | ||||||||||||||||||||||||||||||||||||||||||||||
| 72 | handles => { | ||||||||||||||||||||||||||||||||||||||||||||||
| 73 | add_check_content => 'push', | ||||||||||||||||||||||||||||||||||||||||||||||
| 74 | get_all_content_checks => 'elements', | ||||||||||||||||||||||||||||||||||||||||||||||
| 75 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 537 | ▶ | default => sub { []; } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 39 | ); | |||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||
| 79 | # needs_content_check defaults to 1 to trap bad data right after loading | ||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 39 | has needs_content_check => ( is => 'rw', isa => 'Bool', default => 1 ); | |||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 39 | has has_fixes => ( | |||||||||||||||||||||||||||||||||||||||||||||
| 83 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||
| 84 | isa => 'Num', | ||||||||||||||||||||||||||||||||||||||||||||||
| 85 | default => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 86 | traits => ['Number'], | ||||||||||||||||||||||||||||||||||||||||||||||
| 87 | handles => { | ||||||||||||||||||||||||||||||||||||||||||||||
| 88 | inc_fixes => [ add => 1 ], | ||||||||||||||||||||||||||||||||||||||||||||||
| 89 | dec_fixes => [ sub => 1 ], | ||||||||||||||||||||||||||||||||||||||||||||||
| 90 | add_fixes => 'add', | ||||||||||||||||||||||||||||||||||||||||||||||
| 91 | flush_fixes => [ mul => 0 ], | ||||||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 93 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||
| 95 | # Some idea for improvement | ||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||
| 97 | # suggest => 'foo' or '$bar foo' | ||||||||||||||||||||||||||||||||||||||||||||||
| 98 | # creates a method analog to next_id (or next_id but I need to change | ||||||||||||||||||||||||||||||||||||||||||||||
| 99 | # run_user_command) that suggest the next id as foo_<nb> where | ||||||||||||||||||||||||||||||||||||||||||||||
| 100 | # nb is incremented each time, or compute the passed formula | ||||||||||||||||||||||||||||||||||||||||||||||
| 101 | # and performs the same | ||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 39 | my @common_int_params = qw/min_index max_index max_nb auto_create_ids/; | |||||||||||||||||||||||||||||||||||||||||||||
| 104 | 39 | has \@common_int_params => ( is => 'ro', isa => 'Maybe[Int]' ); | |||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 39 | my @common_list_params = qw/allow_keys default_keys auto_create_keys/; | |||||||||||||||||||||||||||||||||||||||||||||
| 107 | has \@common_list_params => ( | ||||||||||||||||||||||||||||||||||||||||||||||
| 108 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||
| 109 | isa => 'KeyArray', | ||||||||||||||||||||||||||||||||||||||||||||||
| 110 | coerce => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 1116 | ▶ | default => sub { []; } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 39 | ); | |||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 39 | my @common_str_params = qw/allow_keys_from allow_keys_matching follow_keys_from | |||||||||||||||||||||||||||||||||||||||||||||
| 115 | migrate_keys_from migrate_values_from | ||||||||||||||||||||||||||||||||||||||||||||||
| 116 | duplicates warn_if_key_match warn_unless_key_match/; | ||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 39 | has \@common_str_params => ( is => 'ro', isa => 'Maybe[Str]' ); | |||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 39 | my @common_params = | |||||||||||||||||||||||||||||||||||||||||||||
| 120 | ( @common_int_params, @common_str_params, @common_list_params ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 39 | my @allowed_warp_params = ( @common_params, qw/level convert/ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 537 | ▶ | around BUILDARGS => sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 537 | my $orig = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 125 | 537 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 126 | 537 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 127 | 537 | my %h = map { ( $_ => $args{$_} ); } grep { defined $args{$_} } @allowed_warp_params; | |||||||||||||||||||||||||||||||||||||||||||||
| 128 | 537 | return $class->$orig( backup => dclone( \%h ), @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 129 | 39 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 39 | has [qw/cargo/] => ( is => 'ro', isa => 'HashRef', required => 1 ); | |||||||||||||||||||||||||||||||||||||||||||||
| 132 | 39 | has warp => ( is => 'ro', isa => 'Maybe[HashRef]' ); | |||||||||||||||||||||||||||||||||||||||||||||
| 133 | 39 | has [qw/morph/] => ( is => 'ro', isa => 'Bool', default => 0 ); | |||||||||||||||||||||||||||||||||||||||||||||
| 134 | 537 | ▶ | has content_warning_list => ( is => 'rw', isa => 'ArrayRef', default => sub { []; } ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 39 | has [qw/cargo_class max_index index_class index_type/] => | |||||||||||||||||||||||||||||||||||||||||||||
| 136 | ( is => 'rw', isa => 'Maybe[Str]' ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 39 | has config_model => ( | |||||||||||||||||||||||||||||||||||||||||||||
| 139 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||
| 140 | isa => 'Config::Model', | ||||||||||||||||||||||||||||||||||||||||||||||
| 141 | weak_ref => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 142 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 143 | builder => '_config_model' | ||||||||||||||||||||||||||||||||||||||||||||||
| 144 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 114 | ▶ | sub _config_model { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_config_model: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 114 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 148 | 114 | return $self->instance->config_model; | |||||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 310 | ▶ | sub config_class_name { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
config_class_name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 310 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 153 | 310 | return $self->cargo->{config_class_name}; | |||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||
| 156 | # used by roles | ||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 570 | ▶ | sub allowed_warp_params { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
allowed_warp_params: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 570 | return @allowed_warp_params; | |||||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 537 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=9 SCAR=26.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 537 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||
| 164 | croak "Missing cargo->type parameter for element " . $self->{element_name} || 'unknown' | ||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 537 | ▶ | unless defined $self->cargo->{type}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
'Missing cargo->type parameter for element ' . $self->{'element_name'} || 'unknown'
MC/DC0%0/1
'Missing cargo->type parameter for element ' . $self->{'element_name'} || 'unknown'
'Missing cargo->type parameter for element ' . $self->{'element_name'}
Truth table0%0/2
A
A= 'Missing cargo->type parameter for element ' . $self->{'element_name'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 537 | ▶ | if ( $self->cargo->{type} eq 'node' and not $self->cargo->{config_class_name} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->cargo->{"type"} eq "node" and not $self->cargo->{"config_class_name"}
MC/DC0%0/2
$self->cargo->{"type"} eq "node" and not $self->cargo->{"config_class_name"}
$self->cargo->{"type"} eq "node"
not $self->cargo->{"config_class_name"}
Truth table66%2/3
A and not(B)
A= $self->cargo->{"type"} eq "node"B= not $self->cargo->{"config_class_name"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | ▶ | croak "Missing cargo->config_class_name parameter for element " | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
'Missing cargo->config_class_name parameter for element ' . $self->element_name || 'unknown'
MC/DC0%0/1
'Missing cargo->config_class_name parameter for element ' . $self->element_name || 'unknown'
'Missing cargo->config_class_name parameter for element ' . $self->element_name
Truth table0%0/2
A
A= 'Missing cargo->config_class_name parameter for element ' . $self->element_name
| |||||||||||||||||||||||||||||||||||||||||||||||
| 169 | . $self->element_name || 'unknown'; | ||||||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 537 | ▶ | if ( $self->{cargo}{type} eq 'hash' or $self->{cargo}{type} eq 'list' ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"cargo"}{"type"} eq "hash" or $self->{"cargo"}{"type"} eq "list"
MC/DC0%0/2
$self->{"cargo"}{"type"} eq "hash" or $self->{"cargo"}{"type"} eq "list"
$self->{"cargo"}{"type"} eq "hash"
$self->{"cargo"}{"type"} eq "list"
Truth table33%1/3
A or B
A= $self->{"cargo"}{"type"} eq "hash"B= $self->{"cargo"}{"type"} eq "list"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | die "$self->{element_name}: using $self->{cargo}{type} will probably not work"; | |||||||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 537 | $self->set_properties(); | |||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 534 | ▶ | if ( defined $self->warp ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 179 | $self->{warper} = Config::Model::Warper->new( | ||||||||||||||||||||||||||||||||||||||||||||||
| 180 | warped_object => $self, | ||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 6 | %{ $self->warp }, | |||||||||||||||||||||||||||||||||||||||||||||
| 182 | allowed => \@allowed_warp_params | ||||||||||||||||||||||||||||||||||||||||||||||
| 183 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 534 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||
| 189 | # this method can be called by the warp mechanism to alter (warp) the | ||||||||||||||||||||||||||||||||||||||||||||||
| 190 | # feature of the Id object. | ||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 570 | ▶ | sub set_properties ($self, %raw_args) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_properties: called CC=21 SCAR=30.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 192 | # mega cleanup | ||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 570 | for ( @allowed_warp_params ) { delete $self->{$_}; } | |||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||
| 195 | # merge data passed to set_properties with data passed to the constructor | ||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 570 | my %args = $self->merge_properties(%raw_args); | |||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||
| 198 | # these are handled by Node or Warper | ||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 570 | for ( qw/level/ ) { delete $args{$_}; } | |||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 570 | $logger->trace( $self->name, " set_properties called with %raw_args" ); | |||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 570 | for ( @common_params ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 204 | 8550 | ▶ | $self->{$_} = delete $args{$_} if defined $args{$_}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 570 | ▶ | $self->set_convert( \%args ) if defined $args{convert}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 570 | $self-> clear_warpable_check_content; | |||||||||||||||||||||||||||||||||||||||||||||
| 210 | 570 | for ( $self-> get_all_content_checks ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | $self-> add_warpable_check_content($_); | |||||||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 570 | for ( qw/duplicates/ ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 214 | 570 | my $method = "check_$_"; | |||||||||||||||||||||||||||||||||||||||||||||
| 215 | 570 | my $weak_self = $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 216 | 570 | weaken($weak_self); # weaken reference loop ($self - check_content - closure - self) | |||||||||||||||||||||||||||||||||||||||||||||
| 217 | 570 | ▶ | $self-> add_check_content( sub { $weak_self->$method(@_);} ) if $self->{$_}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||
| 220 | Config::Model::Exception::Model->throw( | ||||||||||||||||||||||||||||||||||||||||||||||
| 221 | object => $self, | ||||||||||||||||||||||||||||||||||||||||||||||
| 222 | error => "Undefined index_type" | ||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 570 | ▶ | ) unless defined $self->{index_type}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||||||
| 225 | Config::Model::Exception::Model->throw( | ||||||||||||||||||||||||||||||||||||||||||||||
| 226 | object => $self, | ||||||||||||||||||||||||||||||||||||||||||||||
| 227 | error => "Unexpected index_type $self->{index_type}" | ||||||||||||||||||||||||||||||||||||||||||||||
| 228 | ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 229 | unless ( $self->{index_type} eq 'integer' | ||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 570 | ▶ | or $self->{index_type} eq 'string' ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"index_type"} eq "integer" or $self->{"index_type"} eq "string"
MC/DC0%0/2
$self->{"index_type"} eq "integer" or $self->{"index_type"} eq "string"
$self->{"index_type"} eq "integer"
$self->{"index_type"} eq "string"
Truth table66%2/3
A or B
A= $self->{"index_type"} eq "integer"B= $self->{"index_type"} eq "string"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 570 | my @current_idx = $self->_fetch_all_indexes(); | |||||||||||||||||||||||||||||||||||||||||||||
| 233 | 570 | ▶ | if (@current_idx) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 15 | my $first_idx = shift @current_idx; | |||||||||||||||||||||||||||||||||||||||||||||
| 235 | 15 | my $last_idx = pop @current_idx; | |||||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 15 | foreach my $idx ( ( $first_idx, $last_idx ) ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 238 | 29 | my $ok = $self->check_idx($first_idx); | |||||||||||||||||||||||||||||||||||||||||||||
| 239 | 29 | ▶ | next if $ok; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||
| 241 | # here a user input may trigger an exception even if fetch | ||||||||||||||||||||||||||||||||||||||||||||||
| 242 | # or set value check is disabled. That's mostly because, | ||||||||||||||||||||||||||||||||||||||||||||||
| 243 | # we cannot enforce more strict settings without random | ||||||||||||||||||||||||||||||||||||||||||||||
| 244 | # deletion of data. For instance, if a hash contains 5 | ||||||||||||||||||||||||||||||||||||||||||||||
| 245 | # items and the max_nb of items is reduced to 3. Which 2 | ||||||||||||||||||||||||||||||||||||||||||||||
| 246 | # items should we remove ? | ||||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||
| 248 | # Since we cannot choose, we must raise an exception in | ||||||||||||||||||||||||||||||||||||||||||||||
| 249 | # all cases. | ||||||||||||||||||||||||||||||||||||||||||||||
| 250 | Config::Model::Exception::WrongValue->throw( | ||||||||||||||||||||||||||||||||||||||||||||||
| 251 | error => "Error while setting id property:" | ||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 1 | . join( "\n\t", @{ $self->{idx_error_list} } ), | |||||||||||||||||||||||||||||||||||||||||||||
| 253 | object => $self | ||||||||||||||||||||||||||||||||||||||||||||||
| 254 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 569 | $self->auto_create_elements; | |||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 568 | ▶ | if ( defined $self->{duplicates} | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
defined $self->{"duplicates"} and defined $self->{"cargo"} and $self->{"cargo"}{"type"} ne "leaf"
defined $self->{"duplicates"} and defined $self->{"cargo"}
MC/DC66%2/3
defined $self->{"duplicates"} and defined $self->{"cargo"} and $self->{"cargo"}{"type"} ne "leaf"
defined $self->{"duplicates"}
defined $self->{"cargo"}
$self->{"cargo"}{"type"} ne "leaf"
Truth table75%3/4
A and B and C
A= defined $self->{"duplicates"}B= defined $self->{"cargo"}C= $self->{"cargo"}{"type"} ne "leaf"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 261 | and defined $self->{cargo} | ||||||||||||||||||||||||||||||||||||||||||||||
| 262 | and $self->{cargo}{type} ne 'leaf' ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 1 | Config::Model::Exception::Model->throw( | |||||||||||||||||||||||||||||||||||||||||||||
| 264 | object => $self, | ||||||||||||||||||||||||||||||||||||||||||||||
| 265 | error => "Cannot specify 'duplicates' with cargo type '$self->{cargo}{type}'", | ||||||||||||||||||||||||||||||||||||||||||||||
| 266 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 567 | my $ok_dup = 'forbid|suppress|warn|allow'; | |||||||||||||||||||||||||||||||||||||||||||||
| 270 | 567 | ▶ | if ( defined $self->{duplicates} and $self->{duplicates} !~ /^$ok_dup$/ ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $self->{"duplicates"} and not $self->{"duplicates"} =~ /^$ok_dup$/u
MC/DC100%2/2
defined $self->{"duplicates"} and not $self->{"duplicates"} =~ /^$ok_dup$/u
defined $self->{"duplicates"}
not $self->{"duplicates"} =~ /^$ok_dup$/u
Truth table100%3/3
A and not(B)
A= defined $self->{"duplicates"}B= not $self->{"duplicates"} =~ /^$ok_dup$/u
| |||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 1 | Config::Model::Exception::Model->throw( | |||||||||||||||||||||||||||||||||||||||||||||
| 272 | object => $self, | ||||||||||||||||||||||||||||||||||||||||||||||
| 273 | error => "Unexpected 'duplicates' $self->{duplicates} expected $ok_dup", | ||||||||||||||||||||||||||||||||||||||||||||||
| 274 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||||||
| 277 | Config::Model::Exception::Model->throw( | ||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 566 | ▶ | object => $self, | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 279 | error => "Unexpected parameters: " . join( ' ', keys %args ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 280 | ) if scalar keys %args; | ||||||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 566 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | ▶ | sub max { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
max: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | carp $self->name, ": max param is deprecated, use max_index\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | return $self->max_index; | |||||||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | ▶ | sub min { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
min: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | carp $self->name, ": min param is deprecated, use min_index\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | return $self->min_index; | |||||||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 1635 | ▶ | sub cargo_type { goto &get_cargo_type; } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cargo_type: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 2845 | ▶ | sub get_cargo_type { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_cargo_type: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 2845 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||||||
| 302 | #my @ids = $self->fetch_all_indexes ; | ||||||||||||||||||||||||||||||||||||||||||||||
| 303 | # the returned cargo type might be different from collected type | ||||||||||||||||||||||||||||||||||||||||||||||
| 304 | # when collected type is 'warped_node'. | ||||||||||||||||||||||||||||||||||||||||||||||
| 305 | #return @ids ? $self->fetch_with_id($ids[0])->get_cargo_type | ||||||||||||||||||||||||||||||||||||||||||||||
| 306 | # : $self->{cargo_type} ; | ||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 2845 | return $self->{cargo}{type}; | |||||||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 2 | ▶ | sub get_cargo_info { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_cargo_info: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 312 | 2 | my $what = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 313 | 2 | return $self->{cargo}{$what}; | |||||||||||||||||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||||||
| 316 | # internal, does a grab with improved error message | ||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 11 | ▶ | sub safe_typed_grab ($self, %args) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
safe_typed_grab: called CC=5 SCAR=16.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 11 | ▶ | my $param = $args{param} || croak "safe_typed_grab: missing param"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args{'param'} || croak('safe_typed_grab: missing param')
MC/DC0%0/1
$args{'param'} || croak('safe_typed_grab: missing param')
$args{'param'}
Truth table50%1/2
A
A= $args{'param'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 11 | my $res = eval { | |||||||||||||||||||||||||||||||||||||||||||||
| 321 | $self->grab( | ||||||||||||||||||||||||||||||||||||||||||||||
| 322 | step => $self->{$param}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 323 | type => $self->get_type, | ||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 11 | ▶ | check => $args{check} || 'yes', | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args{'check'} || 'yes'
MC/DC100%1/1
$args{'check'} || 'yes'
$args{'check'}
Truth table100%2/2
A
A= $args{'check'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 325 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 326 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 11 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 1 | my $e = $@; | |||||||||||||||||||||||||||||||||||||||||||||
| 330 | 1 | ▶ | my $msg = $e ? $e->full_message : ''; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 1 | Config::Model::Exception::Model->throw( | |||||||||||||||||||||||||||||||||||||||||||||
| 332 | object => $self, | ||||||||||||||||||||||||||||||||||||||||||||||
| 333 | error => "'$param' parameter: " . $msg | ||||||||||||||||||||||||||||||||||||||||||||||
| 334 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 10 | return $res; | |||||||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 835 | ▶ | sub get_default_keys { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_default_keys: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 835 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 835 | ▶ | if ( $self->{follow_keys_from} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 3 | my $followed = $self->safe_typed_grab( param => 'follow_keys_from' ); | |||||||||||||||||||||||||||||||||||||||||||||
| 345 | 2 | my @res = $followed->fetch_all_indexes; | |||||||||||||||||||||||||||||||||||||||||||||
| 346 | 2 | ▶ | return wantarray ? @res : \@res; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 832 | my @res; | |||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 3 | push @res, @{ $self->{default_keys} } | |||||||||||||||||||||||||||||||||||||||||||||
| 352 | 832 | ▶ | if defined $self->{default_keys}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 832 | ▶ | return wantarray ? @res : \@res; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 1647 | ▶ | sub name { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 1647 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 359 | 1647 | return $self->{parent}->name . ' ' . $self->{element_name} . ' id'; | |||||||||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||||||
| 362 | # internal. Handle model declaration arguments | ||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | ▶ | sub handle_args ($self, %args) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
handle_args: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | my $warp_info = delete $args{warp}; | |||||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | for (qw/index_class index_type morph ordered/) { | |||||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | ▶ | $self->{$_} = delete $args{$_} if defined $args{$_}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | ▶ | $self->set_properties(%args) if defined $self->{index_type}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | ▶ | if ( defined $warp_info ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | $self->{warper} = Config::Model::Warper->new( | |||||||||||||||||||||||||||||||||||||||||||||
| 374 | warped_object => $self, | ||||||||||||||||||||||||||||||||||||||||||||||
| 375 | %$warp_info, | ||||||||||||||||||||||||||||||||||||||||||||||
| 376 | allowed => \@allowed_warp_params | ||||||||||||||||||||||||||||||||||||||||||||||
| 377 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 15 | ▶ | sub apply_fixes { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
apply_fixes: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 15 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 385 | 15 | $fix_logger->trace( $self->location . ": apply_fixes called" ); | |||||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 15 | $self->deep_check( fix => 1, logger => $fix_logger ); | |||||||||||||||||||||||||||||||||||||||||||||
| 388 | 15 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||||||
| 391 | my %check_idx_dispatch = | ||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 39 | map { ( $_ => 'check_' . $_ ); } | |||||||||||||||||||||||||||||||||||||||||||||
| 393 | qw/follow_keys_from allow_keys allow_keys_from allow_keys_matching | ||||||||||||||||||||||||||||||||||||||||||||||
| 394 | warn_if_key_match warn_unless_key_match/; | ||||||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 39 | my %mode_move = ( | |||||||||||||||||||||||||||||||||||||||||||||
| 397 | layered => { preset => 1, normal => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 398 | preset => { normal => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 399 | normal => {}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 400 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 1023 | ▶ | around notify_change => sub ($orig, $self, %args) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 1023 | ▶ | if ($change_logger->is_trace) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 22 | ▶ | my @a = map { ( $_ => $args{$_} // '<undef>' ); } sort keys %args; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args{$_} // "<undef>"
MC/DC100%1/1
$args{$_} // "<undef>"
$args{$_}
Truth table100%2/2
A
A= $args{$_}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 22 | $change_logger->trace( "called for ", $self->name, " from ", join( ' ', caller ), | |||||||||||||||||||||||||||||||||||||||||||||
| 406 | " with ", join( ' ', @a ) ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||||||
| 409 | # $idx may be undef if $self has changed, not necessarily its content | ||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 1023 | my $idx = $args{index}; | |||||||||||||||||||||||||||||||||||||||||||||
| 411 | 1023 | ▶ | if ( defined $idx ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||||||
| 413 | # use $idx to trigger move from layered->preset->normal | ||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 712 | my $imode = $self->instance->get_data_mode; | |||||||||||||||||||||||||||||||||||||||||||||
| 415 | 712 | ▶ | my $old_mode = $self->get_data_mode($idx) || 'normal'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->get_data_mode($idx) || 'normal'
MC/DC100%1/1
$self->get_data_mode($idx) || 'normal'
$self->get_data_mode($idx)
Truth table100%2/2
A
A= $self->get_data_mode($idx)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 712 | ▶ | $self->set_data_mode( $idx, $imode ) if $mode_move{$old_mode}{$imode}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 1023 | ▶ | return if $self->instance->initial_load and not $args{really}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->instance->initial_load and not $args{"really"}
MC/DC50%1/2
$self->instance->initial_load and not $args{"really"}
$self->instance->initial_load
not $args{"really"}
Truth table66%2/3
A and not(B)
A= $self->instance->initial_loadB= not $args{"really"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 1011 | $self-> needs_content_check(1); | |||||||||||||||||||||||||||||||||||||||||||||
| 422 | 1011 | $self->$orig(%args); | |||||||||||||||||||||||||||||||||||||||||||||
| 423 | 1011 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 424 | 39 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||||||
| 426 | # the number of checks is becoming confusing. We have | ||||||||||||||||||||||||||||||||||||||||||||||
| 427 | # - check_idx to check whether an index is fine. This is called when creating | ||||||||||||||||||||||||||||||||||||||||||||||
| 428 | # a new index | ||||||||||||||||||||||||||||||||||||||||||||||
| 429 | # - check_or_fix_content: a more expensive check that runs all content checker registered | ||||||||||||||||||||||||||||||||||||||||||||||
| 430 | # in this object. By default, none. A plain AnyId can contains a duplicated_content | ||||||||||||||||||||||||||||||||||||||||||||||
| 431 | # checker if configured | ||||||||||||||||||||||||||||||||||||||||||||||
| 432 | # - a deep_check (for lack of a better name): a also expensive check that involve index | ||||||||||||||||||||||||||||||||||||||||||||||
| 433 | # versus other part of the config tree. By default, no check is done. This is currently | ||||||||||||||||||||||||||||||||||||||||||||||
| 434 | # used only by DPkg model which check if the index value is used elsewhere | ||||||||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||||||
| 436 | # Using plain check in this class is avoided because it's too generic, but a polymorphic | ||||||||||||||||||||||||||||||||||||||||||||||
| 437 | # entry point is still needed, oh well... | ||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 1 | ▶ | sub check { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 439 | # since check is not used when creating an index, but called explicitly | ||||||||||||||||||||||||||||||||||||||||||||||
| 440 | # so it can be forwarded to deep_check. | ||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 1 | goto &deep_check; # backward compat | |||||||||||||||||||||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 21 | ▶ | sub deep_check ($self, @args) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
deep_check: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 21 | $deep_check_logger->trace("called on ".$self->name); | |||||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 21 | for ( $self->fetch_all_indexes() ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 448 | 66 | $self->check_idx(@args, index => $_); | |||||||||||||||||||||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 21 | $self->check_or_fix_content(@args, logger => $deep_check_logger); | |||||||||||||||||||||||||||||||||||||||||||||
| 452 | 21 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||||||||
| 455 | # check globally the list or hash, called by apply_fix or deep_check | ||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 367 | ▶ | sub check_or_fix_content ($self, %args) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_or_fix_content: called CC=15 SCAR=27.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 367 | ▶ | my $silent = $args{silent} || 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args{'silent'} || 0
MC/DC0%0/1
$args{'silent'} || 0
$args{'silent'}
Truth table50%1/2
A
A= $args{'silent'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 367 | ▶ | my $apply_fix = $args{fix} || 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args{'fix'} || 0
MC/DC100%1/1
$args{'fix'} || 0
$args{'fix'}
Truth table100%2/2
A
A= $args{'fix'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 367 | ▶ | my $local_logger = $args{logger} || $logger; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$args{'logger'} || $logger
MC/DC0%0/2
$args{'logger'} || $logger
$args{'logger'}
$logger
Truth table66%2/3
A || B
A= $args{'logger'}B= $logger
| |||||||||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 367 | ▶ | if ( $apply_fix or $self-> needs_content_check ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$apply_fix or $self->needs_content_check
MC/DC100%2/2
$apply_fix or $self->needs_content_check
$apply_fix
$self->needs_content_check
Truth table100%3/3
A or B
A= $apply_fixB= $self->needs_content_check
| |||||||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 248 | $local_logger->trace( "Running check_content on ",$self->location ); | |||||||||||||||||||||||||||||||||||||||||||||
| 464 | # need to keep track to update GUI | ||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 248 | $self-> flush_fixes; # reset before check | |||||||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 248 | my @error; | |||||||||||||||||||||||||||||||||||||||||||||
| 468 | my @warn; | ||||||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 248 | foreach my $sub ( $self-> get_all_content_checks ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 471 | 11 | $sub->( \@error, \@warn, $apply_fix ); | |||||||||||||||||||||||||||||||||||||||||||||
| 472 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 248 | my $nb = $self->fetch_size; | |||||||||||||||||||||||||||||||||||||||||||||
| 475 | push @error, "Too many items ($nb) limit $self->{max_nb}, " | ||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 248 | ▶ | if defined $self->{max_nb} and $nb > $self->{max_nb}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self->{"max_nb"} and $nb > $self->{"max_nb"}
MC/DC0%0/2
defined $self->{"max_nb"} and $nb > $self->{"max_nb"}
defined $self->{"max_nb"}
$nb > $self->{"max_nb"}
Truth table33%1/3
A and B
A= defined $self->{"max_nb"}B= $nb > $self->{"max_nb"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 248 | ▶ | if (not $silent) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 248 | for ( @warn ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 480 | 3 | $user_logger->warn( "Warning in '" . $self->location_short . "': $_" ) | |||||||||||||||||||||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 248 | $self->{content_warning_list} = \@warn; | |||||||||||||||||||||||||||||||||||||||||||||
| 486 | 248 | $self->{content_error_list} = \@error; | |||||||||||||||||||||||||||||||||||||||||||||
| 487 | 248 | $self-> needs_content_check(0); | |||||||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 248 | ▶ | return scalar @error ? 0 : 1; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 490 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 491 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 119 | ▶ | $local_logger->debug( $self->location, " has not changed, actual check skipped" ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 493 | if $local_logger->is_debug; | ||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 119 | ▶ | my $err = $self->{content_error_list} // []; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"content_error_list"} // []
MC/DC0%0/1
$self->{"content_error_list"} // []
$self->{"content_error_list"}
Truth table50%1/2
A
A= $self->{"content_error_list"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 119 | ▶ | return scalar @$err ? 0 : 1; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 496 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 497 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||||||||||
| 499 | # internal function to check the validity of the index. Called when creating a new | ||||||||||||||||||||||||||||||||||||||||||||||
| 500 | # index or when set_properties is called (init or during warp) | ||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 1099 | ▶ | sub check_idx ($self, @args) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_idx: called CC=24 SCAR=32.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 1099 | my %args = _resolve_arg_shortcut(\@args, 'index'); | |||||||||||||||||||||||||||||||||||||||||||||
| 503 | 1099 | my $idx = $args{index}; | |||||||||||||||||||||||||||||||||||||||||||||
| 504 | 1099 | ▶ | my $silent = $args{silent} || 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args{'silent'} || 0
MC/DC0%0/1
$args{'silent'} || 0
$args{'silent'}
Truth table50%1/2
A
A= $args{'silent'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 1099 | ▶ | my $check = $args{check} || 'yes'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args{'check'} || 'yes'
MC/DC100%1/1
$args{'check'} || 'yes'
$args{'check'}
Truth table100%2/2
A
A= $args{'check'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 1099 | ▶ | my $apply_fix = $args{fix} // ($check eq 'fix' ? 1 : 0); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$args{"fix"} // ($check eq "fix" ? 1 : 0)
MC/DC100%1/1
$args{"fix"} // ($check eq "fix" ? 1 : 0)
$args{"fix"}
Truth table100%2/2
A
A= $args{"fix"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 1099 | ▶ | Config::Model::Exception::Internal->throw( | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 509 | object => $self, | ||||||||||||||||||||||||||||||||||||||||||||||
| 510 | error => "check_idx method: key or index is not defined" | ||||||||||||||||||||||||||||||||||||||||||||||
| 511 | ) unless defined $idx; | ||||||||||||||||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 1099 | my @error; | |||||||||||||||||||||||||||||||||||||||||||||
| 514 | my @warn; | ||||||||||||||||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 1099 | foreach my $key_check_name ( keys %check_idx_dispatch ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 517 | 6594 | ▶ | next unless $self->{$key_check_name}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 10 | my $method = $check_idx_dispatch{$key_check_name}; | |||||||||||||||||||||||||||||||||||||||||||||
| 519 | 10 | $self->$method( $idx, \@error, \@warn, $apply_fix ); | |||||||||||||||||||||||||||||||||||||||||||||
| 520 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 1099 | my $nb = $self->fetch_size; | |||||||||||||||||||||||||||||||||||||||||||||
| 523 | 1099 | my $new_nb = $nb; | |||||||||||||||||||||||||||||||||||||||||||||
| 524 | 1099 | ▶ | $new_nb++ unless $self->_exists($idx); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 1099 | ▶ | if ( $idx eq '' ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 1 | push @error, "Index is empty"; | |||||||||||||||||||||||||||||||||||||||||||||
| 528 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 529 | ▶ | elsif ( $self->{index_type} eq 'integer' and $idx =~ /\D/ ) { | |||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"index_type"} eq "integer" and $idx =~ /\D/u
MC/DC0%0/2
$self->{"index_type"} eq "integer" and $idx =~ /\D/u
$self->{"index_type"} eq "integer"
$idx =~ /\D/u
Truth table66%2/3
A and B
A= $self->{"index_type"} eq "integer"B= $idx =~ /\D/u
| |||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 0 | push @error, "Index is not integer ($idx)"; | |||||||||||||||||||||||||||||||||||||||||||||
| 531 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 532 | ▶ | elsif ( defined $self->{max_index} and $idx > $self->{max_index} ) { | |||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
defined $self->{"max_index"} and $idx > $self->{"max_index"}
MC/DC100%2/2
defined $self->{"max_index"} and $idx > $self->{"max_index"}
defined $self->{"max_index"}
$idx > $self->{"max_index"}
Truth table100%3/3
A and B
A= defined $self->{"max_index"}B= $idx > $self->{"max_index"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 2 | push @error, "Index $idx > max_index limit $self->{max_index}"; | |||||||||||||||||||||||||||||||||||||||||||||
| 534 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 535 | ▶ | elsif ( defined $self->{min_index} and $idx < $self->{min_index} ) { | |||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
defined $self->{"min_index"} and $idx < $self->{"min_index"}
MC/DC100%2/2
defined $self->{"min_index"} and $idx < $self->{"min_index"}
defined $self->{"min_index"}
$idx < $self->{"min_index"}
Truth table100%3/3
A and B
A= defined $self->{"min_index"}B= $idx < $self->{"min_index"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 1 | push @error, "Index $idx < min_index limit $self->{min_index}"; | |||||||||||||||||||||||||||||||||||||||||||||
| 537 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||||||||||||
| 539 | push @error, "Too many items ($new_nb) limit $self->{max_nb}, " . "rejected id '$idx'" | ||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 1099 | ▶ | if defined $self->{max_nb} and $new_nb > $self->{max_nb}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $self->{"max_nb"} and $new_nb > $self->{"max_nb"}
MC/DC100%2/2
defined $self->{"max_nb"} and $new_nb > $self->{"max_nb"}
defined $self->{"max_nb"}
$new_nb > $self->{"max_nb"}
Truth table100%3/3
A and B
A= defined $self->{"max_nb"}B= $new_nb > $self->{"max_nb"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 1099 | ▶ | if ( scalar @error ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 13 | my @a = $self->_fetch_all_indexes; | |||||||||||||||||||||||||||||||||||||||||||||
| 544 | 13 | push @error, "Item ids are '" . join( ',', @a ) . "'", $self->warp_error; | |||||||||||||||||||||||||||||||||||||||||||||
| 545 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 1099 | $self->{idx_error_list} = \@error; | |||||||||||||||||||||||||||||||||||||||||||||
| 548 | 1099 | $self->{warning_hash}{$idx} = \@warn; | |||||||||||||||||||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 1099 | ▶ | if (@warn and not $silent and $check ne 'no') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
@warn and not $silent and $check ne "no"
@warn and not $silent
MC/DC33%1/3
@warn and not $silent and $check ne "no"
@warn
not $silent
$check ne "no"
Truth table50%2/4
A and not(B) and C
A= @warnB= not $silentC= $check ne "no"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 3 | for (@warn) { | |||||||||||||||||||||||||||||||||||||||||||||
| 552 | 3 | $user_logger->warn( "Warning in '" . $self->location_short . "': $_" ); | |||||||||||||||||||||||||||||||||||||||||||||
| 553 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 554 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 1099 | ▶ | return scalar @error ? 0 : 1; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 557 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||||||||||||||||
| 559 | #internal | ||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 1 | ▶ | sub check_follow_keys_from { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_follow_keys_from: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 1 | my ( $self, $idx, $error ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 1 | my $followed = $self->safe_typed_grab( param => 'follow_keys_from' ); | |||||||||||||||||||||||||||||||||||||||||||||
| 564 | 1 | ▶ | return if $followed->exists($idx); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 1 | push @$error, | |||||||||||||||||||||||||||||||||||||||||||||
| 567 | "key '" . $self->shorten_idx($idx) . "' does not exists in followed object '" | ||||||||||||||||||||||||||||||||||||||||||||||
| 568 | . $followed->name | ||||||||||||||||||||||||||||||||||||||||||||||
| 569 | . "'. Expected '" | ||||||||||||||||||||||||||||||||||||||||||||||
| 570 | . join( "', '", $followed->fetch_all_indexes ) . "'"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 572 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||||||||||||||||||||
| 574 | #internal | ||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 2 | ▶ | sub check_allow_keys { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_allow_keys: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 2 | my ( $self, $idx, $error ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 2 | my $ok = grep { $_ eq $idx } @{ $self->{allow_keys} }; | |||||||||||||||||||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||||||||||||||||||||
| 580 | push @$error, | ||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 2 | ▶ | "Unexpected key '" . $self->shorten_idx($idx) . "'. Expected '" . join( "', '", @{ $self->{allow_keys} } ) . "'" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 582 | unless $ok; | ||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 584 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||||||||||||||||
| 586 | #internal | ||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 2 | ▶ | sub check_allow_keys_matching { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_allow_keys_matching: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 2 | my ( $self, $idx, $error ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 589 | 2 | my $match = $self->{allow_keys_matching}; | |||||||||||||||||||||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 2 | ▶ | push @$error, "Unexpected key '" . $self->shorten_idx($idx) . "'. Key must match $match" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 592 | unless $idx =~ /$match/; | ||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 594 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||||||||||||||||||||
| 596 | #internal | ||||||||||||||||||||||||||||||||||||||||||||||
| 597 | 2 | ▶ | sub check_allow_keys_from { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_allow_keys_from: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 2 | my ( $self, $idx, $error ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 599 | |||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 2 | my $from = $self->safe_typed_grab( param => 'allow_keys_from' ); | |||||||||||||||||||||||||||||||||||||||||||||
| 601 | 2 | my $ok = grep { $_ eq $idx } $from->fetch_all_indexes; | |||||||||||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 2 | ▶ | return if $ok; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||||||||||||||||
| 605 | 1 | push @$error, | |||||||||||||||||||||||||||||||||||||||||||||
| 606 | "key '" . $self->shorten_idx($idx) . "' does not exists in '" | ||||||||||||||||||||||||||||||||||||||||||||||
| 607 | . $from->name | ||||||||||||||||||||||||||||||||||||||||||||||
| 608 | . "'. Expected '" | ||||||||||||||||||||||||||||||||||||||||||||||
| 609 | . join( "', '", $from->fetch_all_indexes ) . "'"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 611 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||||||||||||||||||||
| 613 | 2 | ▶ | sub check_warn_if_key_match { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_warn_if_key_match: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 614 | 2 | my ( $self, $idx, $error, $warn ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 615 | 2 | my $re = $self->{warn_if_key_match}; | |||||||||||||||||||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||||||||||||||||||||
| 617 | 2 | ▶ | push @$warn, "key '" . $self->shorten_idx($idx) . "' should not match $re\n" if $idx =~ /$re/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 618 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 619 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 620 | |||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 1 | ▶ | sub check_warn_unless_key_match { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_warn_unless_key_match: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 1 | my ( $self, $idx, $error, $warn ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 623 | 1 | my $re = $self->{warn_unless_key_match}; | |||||||||||||||||||||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 1 | ▶ | push @$warn, "key '" . $self->shorten_idx($idx) . "' should match $re\n" unless $idx =~ /$re/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 626 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 627 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||||||||||||||||||||
| 629 | 9 | ▶ | sub check_duplicates { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_duplicates: called CC=13 SCAR=25.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 630 | 9 | my ( $self, $error, $warn, $apply_fix, $silent ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 631 | |||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 9 | my $dup = $self->{duplicates}; | |||||||||||||||||||||||||||||||||||||||||||||
| 633 | 9 | ▶ | return if $dup eq 'allow'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 634 | |||||||||||||||||||||||||||||||||||||||||||||||
| 635 | 9 | $logger->trace("check_duplicates called"); | |||||||||||||||||||||||||||||||||||||||||||||
| 636 | 9 | my %h; | |||||||||||||||||||||||||||||||||||||||||||||
| 637 | my @issues; | ||||||||||||||||||||||||||||||||||||||||||||||
| 638 | 9 | my @to_delete; | |||||||||||||||||||||||||||||||||||||||||||||
| 639 | 9 | foreach my $i ( $self->fetch_all_indexes ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 640 | 29 | my $v = $self->fetch_with_id( index => $i, check => 'no' )->fetch; | |||||||||||||||||||||||||||||||||||||||||||||
| 641 | 29 | ▶ | next unless $v; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 642 | 28 | ▶ | $h{$v} = 0 unless defined $h{$v}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 643 | 28 | $h{$v}++; | |||||||||||||||||||||||||||||||||||||||||||||
| 644 | 28 | ▶ | if ( $h{$v} > 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 645 | 10 | $logger->info(qq!got $h{$v} duplicates key "$i" value "$v"!); | |||||||||||||||||||||||||||||||||||||||||||||
| 646 | 10 | push @to_delete, $i; | |||||||||||||||||||||||||||||||||||||||||||||
| 647 | 10 | push @issues, qq!$i:"$v"!; | |||||||||||||||||||||||||||||||||||||||||||||
| 648 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 649 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 650 | |||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 9 | ▶ | return unless @issues; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 652 | |||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 6 | ▶ | if ($apply_fix) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 654 | 2 | $logger->info("Fixing duplicates @issues, removing @to_delete"); | |||||||||||||||||||||||||||||||||||||||||||||
| 655 | 2 | for (reverse @to_delete) { $self->remove($_) } | |||||||||||||||||||||||||||||||||||||||||||||
| 656 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 657 | elsif ( $dup eq 'forbid' ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 658 | 1 | $logger->info("Found forbidden duplicates @issues"); | |||||||||||||||||||||||||||||||||||||||||||||
| 659 | 1 | push @$error, "Forbidden duplicates value @issues"; | |||||||||||||||||||||||||||||||||||||||||||||
| 660 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 661 | elsif ( $dup eq 'warn' ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 662 | 2 | $logger->info("warning condition: found duplicate @issues"); | |||||||||||||||||||||||||||||||||||||||||||||
| 663 | 2 | push @$warn, "Duplicated value: @issues"; | |||||||||||||||||||||||||||||||||||||||||||||
| 664 | 2 | $self->add_fixes( scalar @issues); | |||||||||||||||||||||||||||||||||||||||||||||
| 665 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 666 | elsif ( $dup eq 'suppress' ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 667 | 1 | $logger->info("suppressing duplicates @issues"); | |||||||||||||||||||||||||||||||||||||||||||||
| 668 | 1 | for (reverse @to_delete) { $self->remove($_) } | |||||||||||||||||||||||||||||||||||||||||||||
| 669 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 670 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 671 | 0 | die "Internal error: duplicates is $dup"; | |||||||||||||||||||||||||||||||||||||||||||||
| 672 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 673 | 6 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 674 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 675 | |||||||||||||||||||||||||||||||||||||||||||||||
| 676 | 3501 | ▶ | sub fetch_with_id ($self, @args) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fetch_with_id: called CC=10 SCAR=23.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 677 | 3501 | my %args = _resolve_arg_shortcut(\@args, 'index'); | |||||||||||||||||||||||||||||||||||||||||||||
| 678 | 3501 | my $check = $self->_check_check( $args{check} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 679 | 3501 | my $idx = $args{index}; | |||||||||||||||||||||||||||||||||||||||||||||
| 680 | |||||||||||||||||||||||||||||||||||||||||||||||
| 681 | 3501 | ▶ | $logger->trace( $self->name, " called for idx $idx" ) if $logger->is_trace; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 682 | |||||||||||||||||||||||||||||||||||||||||||||||
| 683 | $idx = $self->{convert_sub}($idx) | ||||||||||||||||||||||||||||||||||||||||||||||
| 684 | 3501 | ▶ | if ( defined $self->{convert_sub} and defined $idx ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $self->{"convert_sub"} and defined $idx
MC/DC50%1/2
defined $self->{"convert_sub"} and defined $idx
defined $self->{"convert_sub"}
defined $idx
Truth table66%2/3
A and B
A= defined $self->{"convert_sub"}B= defined $idx
| |||||||||||||||||||||||||||||||||||||||||||||||
| 685 | |||||||||||||||||||||||||||||||||||||||||||||||
| 686 | # try migration only once | ||||||||||||||||||||||||||||||||||||||||||||||
| 687 | 3501 | ▶ | $self->_migrate unless $self->{migration_done}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 688 | |||||||||||||||||||||||||||||||||||||||||||||||
| 689 | 3501 | my $ok = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 690 | |||||||||||||||||||||||||||||||||||||||||||||||
| 691 | # check index only if it's unknown | ||||||||||||||||||||||||||||||||||||||||||||||
| 692 | 3501 | ▶ | $ok = $self->check_idx( index => $idx, check => $check ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->_defined($idx) or $check eq "no"
MC/DC100%2/2
$self->_defined($idx) or $check eq "no"
$self->_defined($idx)
$check eq "no"
Truth table100%3/3
A or B
A= $self->_defined($idx)B= $check eq "no"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 693 | unless $self->_defined($idx) | ||||||||||||||||||||||||||||||||||||||||||||||
| 694 | or $check eq 'no'; | ||||||||||||||||||||||||||||||||||||||||||||||
| 695 | |||||||||||||||||||||||||||||||||||||||||||||||
| 696 | 3501 | ▶ | if ( $ok or $check eq 'no' ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$ok or $check eq "no"
MC/DC50%1/2
$ok or $check eq "no"
$ok
$check eq "no"
Truth table66%2/3
A or B
A= $okB= $check eq "no"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 697 | 3489 | ▶ | $self->auto_vivify($idx) unless $self->_defined($idx); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 698 | 3488 | return $self->_fetch_with_id($idx); | |||||||||||||||||||||||||||||||||||||||||||||
| 699 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 700 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 701 | Config::Model::Exception::WrongValue->throw( | ||||||||||||||||||||||||||||||||||||||||||||||
| 702 | 12 | error => join( "\n\t", @{ $self->{idx_error_list} } ), | |||||||||||||||||||||||||||||||||||||||||||||
| 703 | object => $self | ||||||||||||||||||||||||||||||||||||||||||||||
| 704 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 705 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 706 | |||||||||||||||||||||||||||||||||||||||||||||||
| 707 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 708 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 709 | |||||||||||||||||||||||||||||||||||||||||||||||
| 710 | 3 | ▶ | sub get ($self, @args) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get: called CC=10 SCAR=27.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 711 | 3 | my %args = _resolve_arg_shortcut(\@args, 'path'); | |||||||||||||||||||||||||||||||||||||||||||||
| 712 | 3 | my $path = delete $args{path}; | |||||||||||||||||||||||||||||||||||||||||||||
| 713 | 3 | my $autoadd = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 714 | 3 | ▶ | $autoadd = $args{autoadd} if defined $args{autoadd}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 715 | 3 | ▶ | my $get_obj = delete $args{get_obj} || 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
delete $args{'get_obj'} || 0
MC/DC100%1/1
delete $args{'get_obj'} || 0
delete $args{'get_obj'}
Truth table100%2/2
A
A= delete $args{'get_obj'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 716 | 3 | $path =~ s!^/!!; | |||||||||||||||||||||||||||||||||||||||||||||
| 717 | 3 | my ( $item, $new_path ) = split m!/!, $path, 2; | |||||||||||||||||||||||||||||||||||||||||||||
| 718 | |||||||||||||||||||||||||||||||||||||||||||||||
| 719 | 3 | my $dcm = $args{dir_char_mockup}; | |||||||||||||||||||||||||||||||||||||||||||||
| 720 | |||||||||||||||||||||||||||||||||||||||||||||||
| 721 | # $item =~ s($dcm)(/)g if $dcm ; | ||||||||||||||||||||||||||||||||||||||||||||||
| 722 | 3 | ▶ | if ($dcm) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 723 | 0 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||
| 724 | 0 | my $i = index( $item, $dcm ); | |||||||||||||||||||||||||||||||||||||||||||||
| 725 | 0 | ▶ | last if $i == -1; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 726 | 0 | substr $item, $i, length($dcm), '/'; | |||||||||||||||||||||||||||||||||||||||||||||
| 727 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 728 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 729 | |||||||||||||||||||||||||||||||||||||||||||||||
| 730 | 3 | ▶ | return unless ( $self->exists($item) or $autoadd ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->exists($item) or $autoadd
MC/DC0%0/2
$self->exists($item) or $autoadd
$self->exists($item)
$autoadd
Truth table33%1/3
A or B
A= $self->exists($item)B= $autoadd
| |||||||||||||||||||||||||||||||||||||||||||||||
| 731 | |||||||||||||||||||||||||||||||||||||||||||||||
| 732 | 3 | $logger->trace("get: path $path, item $item"); | |||||||||||||||||||||||||||||||||||||||||||||
| 733 | |||||||||||||||||||||||||||||||||||||||||||||||
| 734 | 3 | my $obj = $self->fetch_with_id( index => $item, %args ); | |||||||||||||||||||||||||||||||||||||||||||||
| 735 | 3 | ▶ | return $obj if ( ( $get_obj or $obj->get_type ne 'leaf' ) and not defined $new_path ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$get_obj || $obj->get_type ne "leaf" and not defined $new_path
$get_obj or $obj->get_type ne "leaf"
MC/DC0%0/3
$get_obj || $obj->get_type ne "leaf" and not defined $new_path
$get_obj
$obj->get_type ne "leaf"
not defined $new_path
Truth table40%2/5
A or B and not(C)
A= $get_objB= $obj->get_type ne "leaf"C= not defined $new_path
| |||||||||||||||||||||||||||||||||||||||||||||||
| 736 | 3 | return $obj->get( path => $new_path, get_obj => $get_obj, %args ); | |||||||||||||||||||||||||||||||||||||||||||||
| 737 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 738 | |||||||||||||||||||||||||||||||||||||||||||||||
| 739 | 1 | ▶ | sub set ($self, $path, @args) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 740 | 1 | $path =~ s!^/!!; | |||||||||||||||||||||||||||||||||||||||||||||
| 741 | 1 | my ( $item, $new_path ) = split m!/!, $path, 2; | |||||||||||||||||||||||||||||||||||||||||||||
| 742 | 1 | return $self->fetch_with_id($item)->set( $new_path, @args ); | |||||||||||||||||||||||||||||||||||||||||||||
| 743 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 744 | |||||||||||||||||||||||||||||||||||||||||||||||
| 745 | 16 | ▶ | sub copy ( $self, $from, $to ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
copy: called CC=5 SCAR=16.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 746 | |||||||||||||||||||||||||||||||||||||||||||||||
| 747 | 16 | ▶ | Config::Model::Exception::User->throw( | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 748 | object => $self, | ||||||||||||||||||||||||||||||||||||||||||||||
| 749 | message => "move: unknow from key $from" | ||||||||||||||||||||||||||||||||||||||||||||||
| 750 | ) unless $self->exists($from); | ||||||||||||||||||||||||||||||||||||||||||||||
| 751 | |||||||||||||||||||||||||||||||||||||||||||||||
| 752 | 15 | my $from_obj = $self->fetch_with_id($from); | |||||||||||||||||||||||||||||||||||||||||||||
| 753 | 15 | my $ok = $self->check_idx($to); | |||||||||||||||||||||||||||||||||||||||||||||
| 754 | |||||||||||||||||||||||||||||||||||||||||||||||
| 755 | 15 | ▶ | if ( $ok && $self->{cargo}{type} eq 'leaf' ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$ok and $self->{"cargo"}{"type"} eq "leaf"
MC/DC50%1/2
$ok and $self->{"cargo"}{"type"} eq "leaf"
$ok
$self->{"cargo"}{"type"} eq "leaf"
Truth table66%2/3
A and B
A= $okB= $self->{"cargo"}{"type"} eq "leaf"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 756 | 8 | $logger->trace( "AnyId: copy leaf value from " . $self->name . " $from to $to" ); | |||||||||||||||||||||||||||||||||||||||||||||
| 757 | 8 | return $self->fetch_with_id($to)->store( $from_obj->fetch() ); | |||||||||||||||||||||||||||||||||||||||||||||
| 758 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 759 | elsif ($ok) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 760 | |||||||||||||||||||||||||||||||||||||||||||||||
| 761 | # node object | ||||||||||||||||||||||||||||||||||||||||||||||
| 762 | 7 | $logger->trace( "AnyId: deep copy node from " . $self->name ); | |||||||||||||||||||||||||||||||||||||||||||||
| 763 | 7 | my $target = $self->fetch_with_id($to); | |||||||||||||||||||||||||||||||||||||||||||||
| 764 | 7 | $logger->trace( "AnyId: deep copy node to " . $target->name ); | |||||||||||||||||||||||||||||||||||||||||||||
| 765 | 7 | return $target->copy_from($from_obj); | |||||||||||||||||||||||||||||||||||||||||||||
| 766 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 767 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 768 | Config::Model::Exception::WrongValue->throw( | ||||||||||||||||||||||||||||||||||||||||||||||
| 769 | 0 | error => join( "\n\t", @{ $self->{idx_error_list} } ), | |||||||||||||||||||||||||||||||||||||||||||||
| 770 | object => $self | ||||||||||||||||||||||||||||||||||||||||||||||
| 771 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 772 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 773 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 774 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 775 | |||||||||||||||||||||||||||||||||||||||||||||||
| 776 | 48 | ▶ | sub fetch_all { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fetch_all: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 777 | 48 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 778 | 48 | my @keys = $self->fetch_all_indexes; | |||||||||||||||||||||||||||||||||||||||||||||
| 779 | 48 | return map { $self->fetch_with_id($_); } @keys; | |||||||||||||||||||||||||||||||||||||||||||||
| 780 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 781 | |||||||||||||||||||||||||||||||||||||||||||||||
| 782 | 0 | ▶ | sub fetch_size { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fetch_size: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 783 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 784 | 0 | return scalar $self->fetch_all_indexes; | |||||||||||||||||||||||||||||||||||||||||||||
| 785 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 786 | |||||||||||||||||||||||||||||||||||||||||||||||
| 787 | 1 | ▶ | sub fetch ($self, @args) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fetch: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 788 | 1 | return join(',', $self->fetch_all_values(@args) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 789 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 790 | |||||||||||||||||||||||||||||||||||||||||||||||
| 791 | 671 | ▶ | sub fetch_value ($self, @args) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fetch_value: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 792 | 671 | my %args = _resolve_arg_shortcut(\@args, 'idx'); | |||||||||||||||||||||||||||||||||||||||||||||
| 793 | 671 | return $self->_fetch_value(%args, sub => 'fetch'); | |||||||||||||||||||||||||||||||||||||||||||||
| 794 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 795 | |||||||||||||||||||||||||||||||||||||||||||||||
| 796 | 19 | ▶ | sub fetch_summary ($self, @args) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fetch_summary: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 797 | 19 | my %args = _resolve_arg_shortcut(\@args, 'idx'); | |||||||||||||||||||||||||||||||||||||||||||||
| 798 | 19 | return $self->_fetch_value(%args, sub => 'fetch_summary'); | |||||||||||||||||||||||||||||||||||||||||||||
| 799 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 800 | |||||||||||||||||||||||||||||||||||||||||||||||
| 801 | 690 | ▶ | sub _fetch_value ($self, %args) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fetch_value: called CC=2 SCAR=7.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 802 | 690 | my $check = $self->_check_check( $args{check} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 803 | 690 | my $sub = delete $args{sub}; | |||||||||||||||||||||||||||||||||||||||||||||
| 804 | |||||||||||||||||||||||||||||||||||||||||||||||
| 805 | 690 | ▶ | if ( $self->{cargo}{type} eq 'leaf' ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 806 | 690 | return $self->fetch_with_id($args{idx})->$sub( check => $check, mode => $args{mode} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 807 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 808 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 809 | Config::Model::Exception::WrongType->throw( | ||||||||||||||||||||||||||||||||||||||||||||||
| 810 | object => $self, | ||||||||||||||||||||||||||||||||||||||||||||||
| 811 | function => 'fetch_values', | ||||||||||||||||||||||||||||||||||||||||||||||
| 812 | got_type => $self->{cargo}{type}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 813 | 0 | expected_type => 'leaf', | |||||||||||||||||||||||||||||||||||||||||||||
| 814 | info => "with index $args{idx}", | ||||||||||||||||||||||||||||||||||||||||||||||
| 815 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 816 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 817 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 818 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 819 | |||||||||||||||||||||||||||||||||||||||||||||||
| 820 | 359 | ▶ | sub fetch_all_values ($self, @args) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fetch_all_values: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 821 | 359 | my %args = _resolve_arg_shortcut(\@args, 'mode'); | |||||||||||||||||||||||||||||||||||||||||||||
| 822 | 359 | my $mode = $args{mode}; | |||||||||||||||||||||||||||||||||||||||||||||
| 823 | 359 | my $check = $self->_check_check( $args{check} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 824 | |||||||||||||||||||||||||||||||||||||||||||||||
| 825 | 359 | my @keys = $self->fetch_all_indexes; | |||||||||||||||||||||||||||||||||||||||||||||
| 826 | |||||||||||||||||||||||||||||||||||||||||||||||
| 827 | # verify content restrictions applied to List (e.g. no duplicate values) | ||||||||||||||||||||||||||||||||||||||||||||||
| 828 | 359 | ▶ | my $ok = $check eq 'no' ? 1 : $self->check_or_fix_content(); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 829 | |||||||||||||||||||||||||||||||||||||||||||||||
| 830 | 359 | ▶ | if ( $ok or $check eq 'no' ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$ok or $check eq "no"
MC/DC50%1/2
$ok or $check eq "no"
$ok
$check eq "no"
Truth table66%2/3
A or B
A= $okB= $check eq "no"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 831 | 671 | return grep { defined $_ } | |||||||||||||||||||||||||||||||||||||||||||||
| 832 | 357 | map { $self->fetch_value(idx => $_, check => $check, mode => $mode ); } @keys; | |||||||||||||||||||||||||||||||||||||||||||||
| 833 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 834 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 835 | Config::Model::Exception::WrongValue->throw( | ||||||||||||||||||||||||||||||||||||||||||||||
| 836 | 2 | error => join( "\n\t", @{ $self->{content_error_list} } ), | |||||||||||||||||||||||||||||||||||||||||||||
| 837 | object => $self | ||||||||||||||||||||||||||||||||||||||||||||||
| 838 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 839 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 840 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 841 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 842 | |||||||||||||||||||||||||||||||||||||||||||||||
| 843 | 2116 | ▶ | sub fetch_all_indexes { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fetch_all_indexes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 844 | 2116 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 845 | 2116 | $self->create_default; # will check itself if creation is necessary | |||||||||||||||||||||||||||||||||||||||||||||
| 846 | 2116 | $self->_migrate; | |||||||||||||||||||||||||||||||||||||||||||||
| 847 | 2116 | return $self->_fetch_all_indexes; | |||||||||||||||||||||||||||||||||||||||||||||
| 848 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 849 | |||||||||||||||||||||||||||||||||||||||||||||||
| 850 | # TODO: remove in 2027 | ||||||||||||||||||||||||||||||||||||||||||||||
| 851 | 0 | ▶ | sub get_all_indexes { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_all_indexes: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 852 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 853 | 0 | croak "get_all_indexes is obsolete. use fetch_all_indexes"; | |||||||||||||||||||||||||||||||||||||||||||||
| 854 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 855 | |||||||||||||||||||||||||||||||||||||||||||||||
| 856 | 0 | ▶ | sub children { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
children: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 857 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 858 | 0 | return $self->fetch_all_indexes; | |||||||||||||||||||||||||||||||||||||||||||||
| 859 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 860 | |||||||||||||||||||||||||||||||||||||||||||||||
| 861 | 2 | ▶ | sub has_data { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has_data: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 862 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 863 | 2 | return $self->fetch_size ; | |||||||||||||||||||||||||||||||||||||||||||||
| 864 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 865 | |||||||||||||||||||||||||||||||||||||||||||||||
| 866 | # auto vivify must create according to cargo}{type | ||||||||||||||||||||||||||||||||||||||||||||||
| 867 | # node -> Node or user class | ||||||||||||||||||||||||||||||||||||||||||||||
| 868 | # leaf -> Value or user class | ||||||||||||||||||||||||||||||||||||||||||||||
| 869 | |||||||||||||||||||||||||||||||||||||||||||||||
| 870 | # warped node cannot be used. Same effect can be achieved by warping | ||||||||||||||||||||||||||||||||||||||||||||||
| 871 | # cargo_args | ||||||||||||||||||||||||||||||||||||||||||||||
| 872 | |||||||||||||||||||||||||||||||||||||||||||||||
| 873 | 39 | my %element_default_class = ( | |||||||||||||||||||||||||||||||||||||||||||||
| 874 | warped_node => 'WarpedNode', | ||||||||||||||||||||||||||||||||||||||||||||||
| 875 | node => 'Node', | ||||||||||||||||||||||||||||||||||||||||||||||
| 876 | leaf => 'Value', | ||||||||||||||||||||||||||||||||||||||||||||||
| 877 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 878 | |||||||||||||||||||||||||||||||||||||||||||||||
| 879 | 39 | my %can_override_class = ( | |||||||||||||||||||||||||||||||||||||||||||||
| 880 | node => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 881 | leaf => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 882 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 883 | |||||||||||||||||||||||||||||||||||||||||||||||
| 884 | #internal | ||||||||||||||||||||||||||||||||||||||||||||||
| 885 | 954 | ▶ | sub auto_vivify { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
auto_vivify: called CC=8 SCAR=21.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 886 | 954 | my ( $self, $idx ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 887 | 954 | my %cargo_args = %{ $self->cargo }; | |||||||||||||||||||||||||||||||||||||||||||||
| 888 | 954 | my $override_class = delete $cargo_args{class}; # to override class in cargo | |||||||||||||||||||||||||||||||||||||||||||||
| 889 | |||||||||||||||||||||||||||||||||||||||||||||||
| 890 | 954 | my $cargo_type = delete $cargo_args{type}; | |||||||||||||||||||||||||||||||||||||||||||||
| 891 | |||||||||||||||||||||||||||||||||||||||||||||||
| 892 | 954 | ▶ | unless (defined $element_default_class{$cargo_type}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 893 | 0 | my $msg = sprintf("unknown '%s' cargo type in cargo_args. Expected %s", | |||||||||||||||||||||||||||||||||||||||||||||
| 894 | $cargo_type, join( ' or ', keys %element_default_class )); | ||||||||||||||||||||||||||||||||||||||||||||||
| 895 | 0 | Config::Model::Exception::Model->throw(object => $self, message => $msg); | |||||||||||||||||||||||||||||||||||||||||||||
| 896 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 897 | |||||||||||||||||||||||||||||||||||||||||||||||
| 898 | 954 | my $el_class = 'Config::Model::' . $element_default_class{$cargo_type}; | |||||||||||||||||||||||||||||||||||||||||||||
| 899 | |||||||||||||||||||||||||||||||||||||||||||||||
| 900 | 954 | ▶ | if ( defined $override_class ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 901 | Config::Model::Exception::Model->throw( | ||||||||||||||||||||||||||||||||||||||||||||||
| 902 | object => $self, | ||||||||||||||||||||||||||||||||||||||||||||||
| 903 | message => "$cargo_type class cannot be overidden by '$override_class'" | ||||||||||||||||||||||||||||||||||||||||||||||
| 904 | 39 | ▶ | ) unless $can_override_class{$cargo_type}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 905 | 39 | $el_class = $override_class; | |||||||||||||||||||||||||||||||||||||||||||||
| 906 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 907 | |||||||||||||||||||||||||||||||||||||||||||||||
| 908 | 954 | foreach my $parm (qw/default upstream_default/) { | |||||||||||||||||||||||||||||||||||||||||||||
| 909 | 1907 | ▶ | if ($cargo_args{$parm}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 910 | 1 | my $type = $self->get_type; | |||||||||||||||||||||||||||||||||||||||||||||
| 911 | 1 | Config::Model::Exception::Model->throw( | |||||||||||||||||||||||||||||||||||||||||||||
| 912 | object => $self, | ||||||||||||||||||||||||||||||||||||||||||||||
| 913 | message => "Setting $parm value in a $type does not make sense." | ||||||||||||||||||||||||||||||||||||||||||||||
| 914 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 915 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 916 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 917 | |||||||||||||||||||||||||||||||||||||||||||||||
| 918 | 953 | ▶ | if ($self->{default_with_init}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 919 | 0 | Config::Model::Exception::Model->throw( | |||||||||||||||||||||||||||||||||||||||||||||
| 920 | object => $self, | ||||||||||||||||||||||||||||||||||||||||||||||
| 921 | message => "default_with_init is obsolete" | ||||||||||||||||||||||||||||||||||||||||||||||
| 922 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 923 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 924 | |||||||||||||||||||||||||||||||||||||||||||||||
| 925 | my @common_args = ( | ||||||||||||||||||||||||||||||||||||||||||||||
| 926 | element_name => $self->{element_name}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 927 | index_value => $idx, | ||||||||||||||||||||||||||||||||||||||||||||||
| 928 | instance => $self->{instance}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 929 | 953 | parent => $self->parent, | |||||||||||||||||||||||||||||||||||||||||||||
| 930 | container => $self, | ||||||||||||||||||||||||||||||||||||||||||||||
| 931 | %cargo_args, | ||||||||||||||||||||||||||||||||||||||||||||||
| 932 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 933 | |||||||||||||||||||||||||||||||||||||||||||||||
| 934 | 953 | my $item; | |||||||||||||||||||||||||||||||||||||||||||||
| 935 | |||||||||||||||||||||||||||||||||||||||||||||||
| 936 | # check parameters passed by the user | ||||||||||||||||||||||||||||||||||||||||||||||
| 937 | 953 | ▶ | if ( $cargo_type eq 'node' ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 938 | 300 | $item = $self->load_node( @common_args, config_class_name => $self->config_class_name ); | |||||||||||||||||||||||||||||||||||||||||||||
| 939 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 940 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 941 | 653 | Mouse::Util::load_class($el_class); | |||||||||||||||||||||||||||||||||||||||||||||
| 942 | 653 | $item = $el_class->new(@common_args); | |||||||||||||||||||||||||||||||||||||||||||||
| 943 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 944 | |||||||||||||||||||||||||||||||||||||||||||||||
| 945 | 953 | my $imode = $self->instance->get_data_mode; | |||||||||||||||||||||||||||||||||||||||||||||
| 946 | 953 | $self->set_data_mode( $idx, $imode ); | |||||||||||||||||||||||||||||||||||||||||||||
| 947 | |||||||||||||||||||||||||||||||||||||||||||||||
| 948 | 953 | $self->_store( $idx, $item ); | |||||||||||||||||||||||||||||||||||||||||||||
| 949 | 953 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 950 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 951 | |||||||||||||||||||||||||||||||||||||||||||||||
| 952 | ## no critic (Subroutines::ProhibitBuiltinHomonyms) | ||||||||||||||||||||||||||||||||||||||||||||||
| 953 | 0 | ▶ | sub defined { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
defined: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 954 | 0 | my ( $self, $idx ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 955 | |||||||||||||||||||||||||||||||||||||||||||||||
| 956 | 0 | return $self->_defined($idx); | |||||||||||||||||||||||||||||||||||||||||||||
| 957 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 958 | |||||||||||||||||||||||||||||||||||||||||||||||
| 959 | ## no critic (Subroutines::ProhibitBuiltinHomonyms) | ||||||||||||||||||||||||||||||||||||||||||||||
| 960 | 65 | ▶ | sub exists { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
exists: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 961 | 65 | my ( $self, $idx ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 962 | |||||||||||||||||||||||||||||||||||||||||||||||
| 963 | 65 | return $self->_exists($idx); | |||||||||||||||||||||||||||||||||||||||||||||
| 964 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 965 | |||||||||||||||||||||||||||||||||||||||||||||||
| 966 | ## no critic (Subroutines::ProhibitBuiltinHomonyms) | ||||||||||||||||||||||||||||||||||||||||||||||
| 967 | 54 | ▶ | sub delete { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delete: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 968 | 54 | my ( $self, $idx ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 969 | |||||||||||||||||||||||||||||||||||||||||||||||
| 970 | 54 | delete $self->{warning_hash}{$idx}; | |||||||||||||||||||||||||||||||||||||||||||||
| 971 | 54 | my $ret = $self->_delete($idx); | |||||||||||||||||||||||||||||||||||||||||||||
| 972 | # notification is not needed if the value was already delete or missing | ||||||||||||||||||||||||||||||||||||||||||||||
| 973 | 54 | ▶ | $self->notify_change( note => "deleted entry $idx" ) if defined $ret; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 974 | 54 | return $ret; | |||||||||||||||||||||||||||||||||||||||||||||
| 975 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 976 | |||||||||||||||||||||||||||||||||||||||||||||||
| 977 | 24 | ▶ | sub clear { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clear: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 978 | 24 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 979 | |||||||||||||||||||||||||||||||||||||||||||||||
| 980 | 24 | $self->{warning_hash} = {}; | |||||||||||||||||||||||||||||||||||||||||||||
| 981 | 24 | $self->_clear; | |||||||||||||||||||||||||||||||||||||||||||||
| 982 | 24 | $self->clear_data_mode; | |||||||||||||||||||||||||||||||||||||||||||||
| 983 | 24 | $self->notify_change( note => "cleared all entries" ); | |||||||||||||||||||||||||||||||||||||||||||||
| 984 | 24 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 985 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 986 | |||||||||||||||||||||||||||||||||||||||||||||||
| 987 | 0 | ▶ | sub clear_values { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clear_values: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 988 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 989 | 0 | carp "clear_values deprecated"; | |||||||||||||||||||||||||||||||||||||||||||||
| 990 | |||||||||||||||||||||||||||||||||||||||||||||||
| 991 | 0 | my $ct = $self->get_cargo_type; | |||||||||||||||||||||||||||||||||||||||||||||
| 992 | 0 | ▶ | Config::Model::Exception::User->throw( | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 993 | object => $self, | ||||||||||||||||||||||||||||||||||||||||||||||
| 994 | message => "clear_values() called on non leaf cargo type: '$ct'" | ||||||||||||||||||||||||||||||||||||||||||||||
| 995 | ) if $ct ne 'leaf'; | ||||||||||||||||||||||||||||||||||||||||||||||
| 996 | |||||||||||||||||||||||||||||||||||||||||||||||
| 997 | # this will trigger a notify_change | ||||||||||||||||||||||||||||||||||||||||||||||
| 998 | 0 | for ( $self->fetch_all_indexes ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 999 | 0 | $self->fetch_with_id($_)->store(undef); | |||||||||||||||||||||||||||||||||||||||||||||
| 1000 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1001 | 0 | $self->notify_change( note => "cleared all values" ); | |||||||||||||||||||||||||||||||||||||||||||||
| 1002 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 1003 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1004 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1005 | 1 | ▶ | sub warning_msg { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
warning_msg: called CC=4 SCAR=15.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1006 | 1 | my ( $self, $idx ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 1007 | 1 | my $list ; | |||||||||||||||||||||||||||||||||||||||||||||
| 1008 | 1 | ▶ | if ( defined $idx ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1009 | 0 | $list = $self->{warning_hash}{$idx} ; | |||||||||||||||||||||||||||||||||||||||||||||
| 1010 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1011 | 1 | elsif ( @{ $self->{content_warning_list} } ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 1012 | 1 | $list = $self->{content_warning_list} ; | |||||||||||||||||||||||||||||||||||||||||||||
| 1013 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1014 | 1 | ▶ | return $list ? join( "\n", @$list ) : ''; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1015 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1016 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1017 | 60 | ▶ | sub has_warning { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has_warning: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1018 | 60 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 1019 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1020 | 60 | return @{ $self->{content_warning_list} }; | |||||||||||||||||||||||||||||||||||||||||||||
| 1021 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1022 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1023 | 0 | ▶ | sub error_msg { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
error_msg: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1024 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 1025 | 0 | my @list; | |||||||||||||||||||||||||||||||||||||||||||||
| 1026 | 0 | for (qw/idx_error_list content_error_list/) { | |||||||||||||||||||||||||||||||||||||||||||||
| 1027 | 0 | ▶ | push @list, @{ $self->{$_} } if $self->{$_}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1028 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1029 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1030 | 0 | ▶ | return unless @list; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1031 | 0 | ▶ | return wantarray ? @list : join( "\n\t", @list ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 1032 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 1033 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1034 | 39 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||||||||||||||||||
| 1035 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1036 | 39 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 1037 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1038 | # ABSTRACT: Base class for hash or list element | ||||||||||||||||||||||||||||||||||||||||||||||
| 1039 | |||||||||||||||||||||||||||||||||||||||||||||||
| 1040 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||