| 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::ListId 2.169; | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 29 | ▶ | use 5.20.0; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 29 | ▶ | use Mouse; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 29 | ▶ | use Config::Model::Exception; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 29 | ▶ | use Log::Log4perl qw(get_logger :levels); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 29 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 29 | extends qw/Config::Model::AnyId/; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 29 | with "Config::Model::Role::Grab"; | |||||||||||||||||||||||||||
| 22 | 29 | with "Config::Model::Role::ComputeFunction"; | |||||||||||||||||||||||||||
| 23 | 29 | with "Config::Model::Role::Utils"; | |||||||||||||||||||||||||||
| 24 | # this requires backup method from Config::Model::AnyThing | ||||||||||||||||||||||||||||
| 25 | 29 | with "Config::Model::Role::WarpSubject"; | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 29 | ▶ | use feature qw/postderef signatures/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | 29 | ▶ | no warnings qw/experimental::signatures experimental::postderef/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 29 | my $logger = get_logger("Tree::Element::Id::List"); | |||||||||||||||||||||||||||
| 31 | 29 | my $user_logger = get_logger("User"); | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | has data => ( | ||||||||||||||||||||||||||||
| 34 | is => 'rw', | ||||||||||||||||||||||||||||
| 35 | isa => 'ArrayRef', | ||||||||||||||||||||||||||||
| 36 | 290 | ▶ | default => sub { []; }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 37 | 29 | traits => ['Array'], | |||||||||||||||||||||||||||
| 38 | handles => { | ||||||||||||||||||||||||||||
| 39 | _sort_data => 'sort_in_place', | ||||||||||||||||||||||||||||
| 40 | _all_data => 'elements', | ||||||||||||||||||||||||||||
| 41 | _splice_data => 'splice', | ||||||||||||||||||||||||||||
| 42 | } ); | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | # compatibility with HashId | ||||||||||||||||||||||||||||
| 45 | 29 | has index_type => ( is => 'ro', isa => 'Str', default => 'integer' ); | |||||||||||||||||||||||||||
| 46 | 29 | has auto_create_ids => ( is => 'rw' ); | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 287 | ▶ | sub BUILD { | ||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=4 SCAR=14.9
Pod
documented
| |||||||||||||||||||||||||||||
| 49 | 287 | my $self = shift; | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 287 | foreach my $wrong (qw/max_nb min_index default_keys/) { | |||||||||||||||||||||||||||
| 52 | Config::Model::Exception::Model->throw( | ||||||||||||||||||||||||||||
| 53 | object => $self, | ||||||||||||||||||||||||||||
| 54 | error => "Cannot use $wrong with " . $self->get_type . " element" | ||||||||||||||||||||||||||||
| 55 | 861 | ▶ | ) if defined $self->{$wrong}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 287 | ▶ | if ( delete $self->{migrate_keys_from} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 0 | $user_logger->warn( | |||||||||||||||||||||||||||
| 60 | $self->name, "Using migrate_keys_from with ", | ||||||||||||||||||||||||||||
| 61 | "list element is obsolete and ignored. Use migrate_values_from" | ||||||||||||||||||||||||||||
| 62 | ); | ||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | # Supply the mandatory parameter | ||||||||||||||||||||||||||||
| 66 | 287 | return $self; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 290 | ▶ | sub set_properties ($self, @args) { | ||||||||||||||||||||||||||
|
Subroutine
set_properties: called CC=4 SCAR=15.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 290 | $self->SUPER::set_properties(@args); | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | # remove unwanted items | ||||||||||||||||||||||||||||
| 74 | 287 | my $data = $self->{data}; | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 287 | ▶ | return unless defined $self->{max_index}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | # delete entries that no longer fit the constraints imposed by the | ||||||||||||||||||||||||||||
| 79 | # warp mechanism | ||||||||||||||||||||||||||||
| 80 | 1 | foreach my $k ( 0 .. $#{$data} ) { | |||||||||||||||||||||||||||
| 81 | 0 | ▶ | next unless $k > $self->{max_index}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 0 | $logger->trace( "set_properties: ", $self->name, " deleting index $k" ); | |||||||||||||||||||||||||||
| 83 | 0 | delete $data->[$k]; | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | 1 | return; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 1546 | ▶ | sub _migrate { | ||||||||||||||||||||||||||
|
Subroutine
_migrate: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||
| 89 | 1546 | my $self = shift; | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 1546 | ▶ | return if $self->{migration_done}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | # migration must be done *after* initial load to make sure that all data | ||||||||||||||||||||||||||||
| 94 | # were retrieved from the file before migration. | ||||||||||||||||||||||||||||
| 95 | 495 | ▶ | return if $self->instance->initial_load; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 281 | $self->{migration_done} = 1; | |||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 281 | ▶ | if ( $self->{migrate_values_from} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | 2 | my $followed = $self->safe_typed_grab( param => 'migrate_values_from', check => 'no' ); | |||||||||||||||||||||||||||
| 101 | 2 | ▶ | $logger->debug( $self->name, " migrate values from ", $followed->name ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | if $logger->is_debug; | ||||||||||||||||||||||||||||
| 103 | 2 | my $idx = $self->fetch_size; | |||||||||||||||||||||||||||
| 104 | 2 | foreach my $item ( $followed->fetch_all_indexes ) { | |||||||||||||||||||||||||||
| 105 | 5 | my $data = $followed->fetch_with_id($item)->dump_as_data( check => 'no' ); | |||||||||||||||||||||||||||
| 106 | 5 | $self->fetch_with_id( $idx++ )->load_data($data); | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | 281 | return; | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 765 | ▶ | sub get_type { | ||||||||||||||||||||||||||
|
Subroutine
get_type: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 113 | 765 | my $self = shift; | |||||||||||||||||||||||||||
| 114 | 765 | return 'list'; | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 2 | ▶ | sub get_info { | ||||||||||||||||||||||||||
|
Subroutine
get_info: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||
| 118 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 2 | my @items = ( | |||||||||||||||||||||||||||
| 121 | 'type: ' . $self->get_type, | ||||||||||||||||||||||||||||
| 122 | 'index: ' . $self->index_type, | ||||||||||||||||||||||||||||
| 123 | 'cargo: ' . $self->cargo_type, | ||||||||||||||||||||||||||||
| 124 | ); | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 2 | ▶ | if ( $self->cargo_type eq 'node' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | 1 | push @items, "cargo class: " . $self->config_class_name; | |||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 2 | ▶ | if ( $self->cargo_type eq 'leaf' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | 1 | ▶ | push @items, "leaf value type: " . ( $self->get_cargo_info('value_type') || '' ); | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->get_cargo_info('value_type') || ''
MC/DC0%0/1
$self->get_cargo_info('value_type') || ''
$self->get_cargo_info('value_type')
Truth table50%1/2
A
A= $self->get_cargo_info('value_type')
| |||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 2 | foreach my $what (qw/min_index max_index/) { | |||||||||||||||||||||||||||
| 135 | 4 | my $v = $self->$what(); | |||||||||||||||||||||||||||
| 136 | 4 | my $str = $what; | |||||||||||||||||||||||||||
| 137 | 4 | $str =~ s/_/ /g; | |||||||||||||||||||||||||||
| 138 | 4 | ▶ | push @items, "$str: $v" if defined $v; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 2 | return @items; | |||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | # important: return the actual size (not taking into account auto-created stuff) | ||||||||||||||||||||||||||||
| 145 | 921 | ▶ | sub fetch_size { | ||||||||||||||||||||||||||
|
Subroutine
fetch_size: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 146 | 921 | my $self = shift; | |||||||||||||||||||||||||||
| 147 | 921 | return scalar @{ $self->{data} }; | |||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 1515 | ▶ | sub _fetch_all_indexes { | ||||||||||||||||||||||||||
|
Subroutine
_fetch_all_indexes: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 151 | 1515 | my $self = shift; | |||||||||||||||||||||||||||
| 152 | 1515 | my $data = $self->{data}; | |||||||||||||||||||||||||||
| 153 | 1515 | ▶ | return scalar @$data ? ( 0 .. $#$data ) : (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | # fetch without any check | ||||||||||||||||||||||||||||
| 157 | 2241 | ▶ | sub _fetch_with_id { | ||||||||||||||||||||||||||
|
Subroutine
_fetch_with_id: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 158 | 2241 | my ( $self, $idx ) = @_; | |||||||||||||||||||||||||||
| 159 | 2241 | return $self->{data}[$idx]; | |||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 4 | ▶ | sub fetch_gist ($self) { | ||||||||||||||||||||||||||
|
Subroutine
fetch_gist: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 163 | my @v = map { | ||||||||||||||||||||||||||||
| 164 | 4 | $self->fetch_with_id($_)->fetch_gist | |||||||||||||||||||||||||||
| 165 | } $self->fetch_all_indexes(check => 'no'); | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | 4 | my $str = join(",", @v); | |||||||||||||||||||||||||||
| 168 | 4 | ▶ | $str = substr( $str, 0, 15 ) . '...' if length($str) > 15; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 169 | 4 | return $str; | |||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 79 | ▶ | sub load { | ||||||||||||||||||||||||||
|
Subroutine
load: called CC=8 SCAR=20.9
Pod
documented
| |||||||||||||||||||||||||||||
| 173 | 79 | my ( $self, $string, %args ) = @_; | |||||||||||||||||||||||||||
| 174 | 79 | my $check = $self->_check_check( $args{check} ); # I write too many checks. | |||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | 79 | my @set; | |||||||||||||||||||||||||||
| 177 | 79 | my $cmd = $string; | |||||||||||||||||||||||||||
| 178 | 79 | $logger->debug( "load: ", $self->name, " called with ->$string<-" ); | |||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 79 | my $regex = qr/^( | |||||||||||||||||||||||||||
| 181 | (?: | ||||||||||||||||||||||||||||
| 182 | "(?: \\" | [^"] )*?" # quoted string | ||||||||||||||||||||||||||||
| 183 | ) | ||||||||||||||||||||||||||||
| 184 | | | ||||||||||||||||||||||||||||
| 185 | [^,]+ # plain string delimited by comma | ||||||||||||||||||||||||||||
| 186 | ) | ||||||||||||||||||||||||||||
| 187 | /x; | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | 79 | ▶ | while ( length($string) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 190 | 229 | ▶ | $string =~ s/$regex// or last; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 191 | 227 | my $tmp = $1; | |||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | # cleanup quoted string: remove surrounding quotes and escapes | ||||||||||||||||||||||||||||
| 194 | 227 | ▶ | $tmp =~ s/^"|"$//g if defined $tmp; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 195 | 227 | ▶ | $tmp =~ s/\\"/"/g if defined $tmp; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 196 | 227 | push @set, $tmp; | |||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | 227 | ▶ | last unless length($string); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||
| 200 | continue { | ||||||||||||||||||||||||||||
| 201 | 150 | ▶ | $string =~ s/^,// or last; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | 79 | ▶ | if ( length($string) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 205 | 2 | Config::Model::Exception::Load->throw( | |||||||||||||||||||||||||||
| 206 | object => $self, | ||||||||||||||||||||||||||||
| 207 | command => $cmd, | ||||||||||||||||||||||||||||
| 208 | message => "unexpected load command '$cmd', left '$cmd'" | ||||||||||||||||||||||||||||
| 209 | ); | ||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | 77 | $self->store_set(\@set, check => $check); | |||||||||||||||||||||||||||
| 213 | 76 | return; | |||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | 112 | ▶ | sub store_set ($self, @raw_args) { | ||||||||||||||||||||||||||
|
Subroutine
store_set: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||
| 217 | 112 | my (@v, %args); | |||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | 112 | ▶ | if (ref $raw_args[0] eq 'ARRAY') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 220 | 78 | @v = shift(@raw_args)->@*; | |||||||||||||||||||||||||||
| 221 | 78 | %args = @raw_args; | |||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||
| 223 | else { | ||||||||||||||||||||||||||||
| 224 | 34 | @v = @raw_args; | |||||||||||||||||||||||||||
| 225 | 34 | %args = ( check => 'yes' ); | |||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | 112 | ▶ | if ($logger->is_debug) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 229 | 3 | ▶ | $logger->debug($self->name, " store_set called with ".map {"«$_» "} map { $_ // "<undef>" } @v); | ||||||||||||||||||||||||||
|
Condition50%1/2
$_ // "<undef>"
MC/DC0%0/1
$_ // "<undef>"
$_
Truth table50%1/2
A
A= $_
| |||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | 112 | ▶ | my @comments = @{ $args{comment} || [] }; | ||||||||||||||||||||||||||
|
Condition50%1/2
$args{'comment'} || []
MC/DC0%0/1
$args{'comment'} || []
$args{'comment'}
Truth table50%1/2
A
A= $args{'comment'}
| |||||||||||||||||||||||||||||
| 233 | 112 | my $idx = 0; | |||||||||||||||||||||||||||
| 234 | 112 | foreach my $value (@v) { | |||||||||||||||||||||||||||
| 235 | 327 | my $v_obj = $self->fetch_with_id( $idx++ ); | |||||||||||||||||||||||||||
| 236 | 327 | $v_obj->store( %args, value => $value ); | |||||||||||||||||||||||||||
| 237 | 326 | ▶ | $v_obj->annotation( shift @comments ) if @comments; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | # and delete unused items | ||||||||||||||||||||||||||||
| 241 | 111 | $self->_prune_above_idx($idx); | |||||||||||||||||||||||||||
| 242 | 111 | return; | |||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | 184 | ▶ | sub _prune_above_idx { | ||||||||||||||||||||||||||
|
Subroutine
_prune_above_idx: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 246 | 184 | my ($self, $idx) = @_; | |||||||||||||||||||||||||||
| 247 | # and delete unused items | ||||||||||||||||||||||||||||
| 248 | 184 | my $ref = $self->{data}; | |||||||||||||||||||||||||||
| 249 | 184 | ▶ | while (scalar @$ref > $idx) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 250 | 39 | $logger->debug($self->name, " pruning idx ", $#$ref); | |||||||||||||||||||||||||||
| 251 | 39 | $self->delete($#$ref); | |||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||
| 253 | 184 | return; | |||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | # store without any check | ||||||||||||||||||||||||||||
| 257 | 554 | ▶ | sub _store { | ||||||||||||||||||||||||||
|
Subroutine
_store: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 258 | 554 | my ( $self, $idx, $value ) = @_; | |||||||||||||||||||||||||||
| 259 | 554 | return $self->{data}[$idx] = $value; | |||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | 4483 | ▶ | sub _defined { | ||||||||||||||||||||||||||
|
Subroutine
_defined: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||
| 263 | 4483 | my ( $self, $key ) = @_; | |||||||||||||||||||||||||||
| 264 | 4483 | ▶ | croak "argument '$key' is not numeric" unless $key =~ /^\d+$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 265 | 4483 | return defined $self->{data}[$key]; | |||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | 633 | ▶ | sub _exists { | ||||||||||||||||||||||||||
|
Subroutine
_exists: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 269 | 633 | my ( $self, $idx ) = @_; | |||||||||||||||||||||||||||
| 270 | 633 | return exists $self->{data}[$idx]; | |||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||
| 273 | 45 | ▶ | sub _delete { | ||||||||||||||||||||||||||
|
Subroutine
_delete: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 274 | 45 | my ( $self, $idx ) = @_; | |||||||||||||||||||||||||||
| 275 | 45 | return delete $self->{data}[$idx]; | |||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||
| 278 | 16 | ▶ | sub _clear ($self) { | ||||||||||||||||||||||||||
|
Subroutine
_clear: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 279 | 16 | $self->{data} = []; | |||||||||||||||||||||||||||
| 280 | 16 | return; | |||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||
| 283 | 2 | ▶ | sub move ($self, $from, $to, %args) { | ||||||||||||||||||||||||||
|
Subroutine
move: called CC=4 SCAR=16.0
Pod
documented
| |||||||||||||||||||||||||||||
| 284 | 2 | my $check = $self->_check_check( $args{check} ); | |||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||
| 286 | 2 | my $moved = $self->fetch_with_id($from); | |||||||||||||||||||||||||||
| 287 | 2 | $self->_delete($from); | |||||||||||||||||||||||||||
| 288 | 2 | delete $self->{warning_hash}{$from}; | |||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | 2 | my $ok = $self->check_idx($to); | |||||||||||||||||||||||||||
| 291 | 2 | ▶ | if ( $ok or $check eq 'no' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$ok or $check eq "no"
MC/DC0%0/2
$ok or $check eq "no"
$ok
$check eq "no"
Truth table33%1/3
A or B
A= $okB= $check eq "no"
| |||||||||||||||||||||||||||||
| 292 | 2 | $self->_store( $to, $moved ); | |||||||||||||||||||||||||||
| 293 | 2 | $moved->index_value($to); | |||||||||||||||||||||||||||
| 294 | 2 | $self->notify_change( note => "moved from index $from to $to" ); | |||||||||||||||||||||||||||
| 295 | 2 | my $imode = $self->instance->get_data_mode; | |||||||||||||||||||||||||||
| 296 | 2 | $self->set_data_mode( $to, $imode ); | |||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||
| 298 | else { | ||||||||||||||||||||||||||||
| 299 | # restore moved item where it came from | ||||||||||||||||||||||||||||
| 300 | 0 | $self->_store( $from, $moved ); | |||||||||||||||||||||||||||
| 301 | 0 | ▶ | if ( $check ne 'skip' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 302 | Config::Model::Exception::WrongValue->throw( | ||||||||||||||||||||||||||||
| 303 | 0 | error => join( "\n\t", @{ $self->{error} } ), | |||||||||||||||||||||||||||
| 304 | object => $self | ||||||||||||||||||||||||||||
| 305 | ); | ||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||
| 308 | 2 | return; | |||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||
| 311 | # list only methods | ||||||||||||||||||||||||||||
| 312 | ## no critic (Subroutines::ProhibitBuiltinHomonyms) | ||||||||||||||||||||||||||||
| 313 | 22 | ▶ | sub push ($self, @args) { | ||||||||||||||||||||||||||
|
Subroutine
push: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 314 | 22 | $self->_assert_leaf_cargo; | |||||||||||||||||||||||||||
| 315 | 22 | my $idx = $self->fetch_size; | |||||||||||||||||||||||||||
| 316 | 22 | map { $self->fetch_with_id( $idx++ )->store($_); } @args; | |||||||||||||||||||||||||||
| 317 | 22 | return; | |||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||
| 320 | # list only methods | ||||||||||||||||||||||||||||
| 321 | 2 | ▶ | sub push_x ($self, %args) { | ||||||||||||||||||||||||||
|
Subroutine
push_x: called CC=9 SCAR=22.3
Pod
documented
| |||||||||||||||||||||||||||||
| 322 | 2 | $self->_assert_leaf_cargo; | |||||||||||||||||||||||||||
| 323 | 2 | ▶ | my $check = delete $args{check} || 'yes'; | ||||||||||||||||||||||||||
|
Condition50%1/2
delete $args{'check'} || 'yes'
MC/DC0%0/1
delete $args{'check'} || 'yes'
delete $args{'check'}
Truth table50%1/2
A
A= delete $args{'check'}
| |||||||||||||||||||||||||||||
| 324 | 2 | ▶ | my $v_arg = delete $args{values} || delete $args{value}; | ||||||||||||||||||||||||||
|
Condition33%1/3
delete $args{'values'} || delete $args{'value'}
MC/DC0%0/2
delete $args{'values'} || delete $args{'value'}
delete $args{'values'}
delete $args{'value'}
Truth table33%1/3
A || B
A= delete $args{'values'}B= delete $args{'value'}
| |||||||||||||||||||||||||||||
| 325 | 2 | ▶ | my @v = ref($v_arg) ? @$v_arg : ($v_arg); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 326 | 2 | my $anno = delete $args{annotation}; | |||||||||||||||||||||||||||
| 327 | 2 | ▶ | my @a = ref($anno) ? @$anno : $anno ? ($anno) : (); | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||
| 329 | 2 | ▶ | croak( "push_x: unexpected parameter ", join( ' ', keys %args ) ) if %args; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||
| 331 | 2 | my $idx = $self->fetch_size; | |||||||||||||||||||||||||||
| 332 | 2 | ▶ | while (@v) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 333 | 3 | my $val = shift @v; | |||||||||||||||||||||||||||
| 334 | 3 | my $obj = $self->fetch_with_id( $idx++ ); | |||||||||||||||||||||||||||
| 335 | 3 | $obj->store($val); | |||||||||||||||||||||||||||
| 336 | 3 | ▶ | $obj->annotation( shift @a ) if @a; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||
| 338 | 2 | return; | |||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||
| 341 | 3 | ▶ | sub unshift ($self, @args) { | ||||||||||||||||||||||||||
|
Subroutine
unshift: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 342 | 3 | $self->insert_at(0, @args); | |||||||||||||||||||||||||||
| 343 | 3 | return; | |||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||
| 346 | 22 | ▶ | sub insert_at ($self, $idx, @args) { | ||||||||||||||||||||||||||
|
Subroutine
insert_at: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 347 | 22 | $self->_assert_leaf_cargo; | |||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||
| 349 | # check if max_idx is respected | ||||||||||||||||||||||||||||
| 350 | 22 | $self->check_idx( $self->fetch_size + scalar @args ); | |||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||
| 352 | # make room at the beginning of the array | ||||||||||||||||||||||||||||
| 353 | 22 | $self->_splice_data( $idx, 0, (undef) x scalar @args ); | |||||||||||||||||||||||||||
| 354 | 22 | my $i = $idx; | |||||||||||||||||||||||||||
| 355 | 22 | map { $self->fetch_with_id( $i++ )->store($_); } @args; | |||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||
| 357 | 22 | $self->_reindex; | |||||||||||||||||||||||||||
| 358 | 22 | return; | |||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||
| 361 | 5 | ▶ | sub insert_before ($self, $val, @args) { | ||||||||||||||||||||||||||
|
Subroutine
insert_before: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 362 | 10 | ▶ | my $test = ref($val) eq 'Regexp' ? sub ($in) { $in =~ /$val/ } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 363 | 5 | ▶ | : sub ($in) { $in eq $val }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||
| 365 | 5 | $self->_assert_leaf_cargo; | |||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||
| 367 | 5 | my $point = 0; | |||||||||||||||||||||||||||
| 368 | 5 | foreach my $v ( $self->fetch_all_values ) { | |||||||||||||||||||||||||||
| 369 | 14 | ▶ | last if $test->($v); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 370 | 9 | $point++; | |||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||
| 373 | 5 | $self->insert_at($point, @args); | |||||||||||||||||||||||||||
| 374 | 5 | return; | |||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||
| 377 | 7 | ▶ | sub insort ($self, @args) { | ||||||||||||||||||||||||||
|
Subroutine
insort: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 378 | 7 | $self->_assert_leaf_cargo; | |||||||||||||||||||||||||||
| 379 | 7 | my @insert = sort @args; | |||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||
| 381 | 7 | my $point = 0; | |||||||||||||||||||||||||||
| 382 | 7 | foreach my $v ( $self->fetch_all_values ) { | |||||||||||||||||||||||||||
| 383 | 43 | ▶ | while ( @insert and $insert[0] lt $v ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@insert and $insert[0] lt $v
MC/DC100%2/2
@insert and $insert[0] lt $v
@insert
$insert[0] lt $v
Truth table100%3/3
A and B
A= @insertB= $insert[0] lt $v
| |||||||||||||||||||||||||||||
| 384 | 13 | $self->insert_at( $point++, shift @insert ); | |||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||
| 386 | 43 | $point++; | |||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||
| 388 | 7 | ▶ | $self->push(@insert) if @insert; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 389 | 7 | return; | |||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||
| 392 | 0 | ▶ | sub store ($self, @args) { | ||||||||||||||||||||||||||
|
Subroutine
store: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 393 | 0 | return $self->push_x(@args); | |||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||
| 396 | 58 | ▶ | sub _assert_leaf_cargo { | ||||||||||||||||||||||||||
|
Subroutine
_assert_leaf_cargo: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 397 | 58 | my $self = shift; | |||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||
| 399 | 58 | my $ct = $self->cargo_type; | |||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||
| 401 | 58 | ▶ | Config::Model::Exception::User->throw( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 402 | object => $self, | ||||||||||||||||||||||||||||
| 403 | error => "Cannot call sort on list of $ct" | ||||||||||||||||||||||||||||
| 404 | ) unless $ct eq 'leaf'; | ||||||||||||||||||||||||||||
| 405 | 58 | return; | |||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||
| 408 | 7 | ▶ | sub sort_algorithm { | ||||||||||||||||||||||||||
|
Subroutine
sort_algorithm: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 409 | 7 | ▶ | return sub { $_[0]->fetch_gist cmp $_[1]->fetch_gist; }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||
| 412 | ## no critic (Subroutines::ProhibitBuiltinHomonyms) | ||||||||||||||||||||||||||||
| 413 | 7 | ▶ | sub sort { | ||||||||||||||||||||||||||
|
Subroutine
sort: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 414 | 7 | my $self = shift; | |||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||
| 416 | 7 | $self->_sort_data( $self->sort_algorithm ); | |||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||
| 418 | 7 | my $has_changed = $self->_reindex; | |||||||||||||||||||||||||||
| 419 | 7 | ▶ | $self->notify_change( note => "sorted" ) if $has_changed; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 420 | 7 | return; | |||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||
| 423 | 29 | ▶ | sub _reindex { | ||||||||||||||||||||||||||
|
Subroutine
_reindex: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 424 | 29 | my $self = shift; | |||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||
| 426 | 29 | my $i = 0; | |||||||||||||||||||||||||||
| 427 | 29 | my $has_changed = 0; | |||||||||||||||||||||||||||
| 428 | 29 | foreach my $o ( $self->_all_data ) { | |||||||||||||||||||||||||||
| 429 | 177 | ▶ | next unless defined $o; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 430 | 177 | ▶ | $has_changed = 1 if $o->index_value != $i; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 431 | 177 | $o->index_value( $i++ ); | |||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||
| 433 | 29 | return $has_changed; | |||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||
| 436 | 2 | ▶ | sub swap { | ||||||||||||||||||||||||||
|
Subroutine
swap: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 437 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 438 | 2 | my $ida = shift; | |||||||||||||||||||||||||||
| 439 | 2 | my $idb = shift; | |||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||
| 441 | 2 | my $obja = $self->{data}[$ida]; | |||||||||||||||||||||||||||
| 442 | 2 | my $objb = $self->{data}[$idb]; | |||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||
| 444 | # swap the index values contained in the objects | ||||||||||||||||||||||||||||
| 445 | 2 | my $obja_index = $obja->index_value; | |||||||||||||||||||||||||||
| 446 | 2 | $obja->index_value( $objb->index_value ); | |||||||||||||||||||||||||||
| 447 | 2 | $objb->index_value($obja_index); | |||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||
| 449 | # then swap the objects | ||||||||||||||||||||||||||||
| 450 | 2 | $self->{data}[$ida] = $objb; | |||||||||||||||||||||||||||
| 451 | 2 | $self->{data}[$idb] = $obja; | |||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||
| 453 | 2 | $self->notify_change( note => "swapped index $ida and $idb" ); | |||||||||||||||||||||||||||
| 454 | 2 | return; | |||||||||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||
| 457 | #die "check index number after wap"; | ||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||
| 459 | 23 | ▶ | sub remove { | ||||||||||||||||||||||||||
|
Subroutine
remove: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 460 | 23 | my $self = shift; | |||||||||||||||||||||||||||
| 461 | 23 | my $idx = shift; | |||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||
| 463 | 23 | ▶ | Config::Model::Exception::User->throw( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 464 | object => $self, | ||||||||||||||||||||||||||||
| 465 | error => "Non numeric index for list: $idx" | ||||||||||||||||||||||||||||
| 466 | ) unless $idx =~ /^\d+$/; | ||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||
| 468 | 22 | $self->delete_data_mode( index => $idx ); | |||||||||||||||||||||||||||
| 469 | 22 | my $note = "removed idx $idx"; | |||||||||||||||||||||||||||
| 470 | 22 | ▶ | if ( $self->{cargo}{type} eq 'leaf' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 471 | 19 | $note .= ' ("' . $self->fetch_summary($idx) . '")'; | |||||||||||||||||||||||||||
| 472 | } | ||||||||||||||||||||||||||||
| 473 | 22 | $self->notify_change(note => $note); | |||||||||||||||||||||||||||
| 474 | 22 | splice @{ $self->{data} }, $idx, 1; | |||||||||||||||||||||||||||
| 475 | 22 | return; | |||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||
| 478 | #internal | ||||||||||||||||||||||||||||
| 479 | 290 | ▶ | sub auto_create_elements { | ||||||||||||||||||||||||||
|
Subroutine
auto_create_elements: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 480 | 290 | my $self = shift; | |||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||
| 482 | 290 | my $auto_nb = $self->auto_create_ids; | |||||||||||||||||||||||||||
| 483 | 290 | ▶ | return unless defined $auto_nb; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||
| 485 | 2 | $logger->debug( $self->name, " auto-creating $auto_nb elements" ); | |||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||
| 487 | 2 | ▶ | Config::Model::Exception::Model->throw( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 488 | object => $self, | ||||||||||||||||||||||||||||
| 489 | error => "Wrong auto_create argument for list: $auto_nb" | ||||||||||||||||||||||||||||
| 490 | ) unless $auto_nb =~ /^\d+$/; | ||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||
| 492 | 1 | my $auto_p = $auto_nb - 1; | |||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||
| 494 | # create empty slots | ||||||||||||||||||||||||||||
| 495 | 1 | ▶ | map { $self->{data}[$_] = undef unless defined $self->{data}[$_]; } ( 0 .. $auto_p ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 496 | 1 | return; | |||||||||||||||||||||||||||
| 497 | } | ||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||
| 499 | # internal | ||||||||||||||||||||||||||||
| 500 | 1224 | ▶ | sub create_default { | ||||||||||||||||||||||||||
|
Subroutine
create_default: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 501 | 1224 | my $self = shift; | |||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||
| 503 | 1224 | ▶ | return if @{ $self->{data} }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||
| 505 | # list is empty so create empty element for default keys | ||||||||||||||||||||||||||||
| 506 | 525 | my $def = $self->get_default_keys; | |||||||||||||||||||||||||||
| 507 | 0 | map { $self->{data}[$_] = undef } @$def; | |||||||||||||||||||||||||||
| 508 | 525 | return; | |||||||||||||||||||||||||||
| 509 | } | ||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||
| 511 | 74 | ▶ | sub load_data ($self, @args) { | ||||||||||||||||||||||||||
|
Subroutine
load_data: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 512 | 74 | my %args = _resolve_arg_shortcut(\@args, 'data'); | |||||||||||||||||||||||||||
| 513 | 74 | my $raw_data = delete $args{data}; | |||||||||||||||||||||||||||
| 514 | 74 | my $check = $self->_check_check( $args{check} ); | |||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||
| 516 | my $data = | ||||||||||||||||||||||||||||
| 517 | ref($raw_data) eq 'ARRAY' ? $raw_data | ||||||||||||||||||||||||||||
| 518 | 74 | ▶ | : $args{split_reg} ? [ split $args{split_reg}, $raw_data ] | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 519 | : defined $raw_data ? [$raw_data] | ||||||||||||||||||||||||||||
| 520 | : undef; | ||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||
| 522 | 74 | ▶ | Config::Model::Exception::LoadData->throw( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 523 | object => $self, | ||||||||||||||||||||||||||||
| 524 | message => "load_data called with non expected data. Expected array ref or scalar", | ||||||||||||||||||||||||||||
| 525 | wrong_data => $raw_data, | ||||||||||||||||||||||||||||
| 526 | ) unless defined $data; | ||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||
| 528 | 73 | my $idx = 0; | |||||||||||||||||||||||||||
| 529 | 73 | $logger->info( "ListId load_data (", $self->location, ") will load idx ", "0..$#$data" ); | |||||||||||||||||||||||||||
| 530 | 73 | foreach my $item (@$data) { | |||||||||||||||||||||||||||
| 531 | 144 | my $obj = $self->fetch_with_id( $idx ); | |||||||||||||||||||||||||||
| 532 | # increment idx only if the value was accepted. This allow to | ||||||||||||||||||||||||||||
| 533 | # prune the array to the right size. | ||||||||||||||||||||||||||||
| 534 | 144 | $idx += $obj->load_data( %args, data => $item ); | |||||||||||||||||||||||||||
| 535 | } | ||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||
| 537 | # and delete unused items | ||||||||||||||||||||||||||||
| 538 | 73 | $self->_prune_above_idx($idx); | |||||||||||||||||||||||||||
| 539 | 73 | return 1; | |||||||||||||||||||||||||||
| 540 | } | ||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||
| 542 | 29 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||
| 544 | 29 | 1; | |||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||
| 546 | # ABSTRACT: Handle list element for configuration model | ||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||
| 548 | __END__ | ||||||||||||||||||||||||||||