blib/lib/Config/Model/Value/LayeredInclude.pm untested

filter: Statementstmt 0.0% 0 / 50 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod n/a totaltotal 0.0% 0 / 66 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
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::Value::LayeredInclude 2.169;
11  
12 use v5.20;
13 use Mouse;
14 use strict;
15 use warnings;
16 use Log::Log4perl qw(get_logger :levels);
17  
18 use base qw/Config::Model::Value/;
19  
20 use feature qw/postderef signatures/;
21 no warnings qw/experimental::postderef experimental::signatures/;
22  
23 my $logger = get_logger("Tree::Element::Value::LayeredInclude");
24  
25 # should we clear all layered value when include value is changed ?
26 # If yes, beware of recursive includes. Clear should only be done once.
27  
28 around _store => sub ($orig, $self, %args) {
29 my ( $value, $check, $silent, $notify_change, $ok, $callback ) =
30 @args{qw/value check silent notify_change ok callback/};
31  
32 my $old_value = $self->_fetch_no_check;
33  
34 $orig->($self, %args);
35 {
36 ## no critic (TestingAndDebugging::ProhibitNoWarnings)
37 no warnings 'uninitialized';
38 return $value if $value eq $old_value;
39 }
40  
41 my $i = $self->instance;
42 my $already_in_layered = $i->layered;
43  
44 # layered stuff here
45 if ( not $already_in_layered ) {
46 $i->layered_clear;
47 $i->layered_start;
48 }
49  
50 {
51 ## no critic (TestingAndDebugging::ProhibitNoWarnings)
52 no warnings 'uninitialized';
53 $logger->debug("Loading layered config from $value (old_data is $old_value)");
54 }
55  
56 # load included file in layered mode
57 $self->root->read_config_data(
58 # check => 'no',
59 config_file => $value,
60 auto_create => 0, # included file must exist
61 );
62  
63 if ( not $already_in_layered ) {
64 $i->layered_stop;
65 }
66  
67 # test if already in layered mode -> if no, clear layered,
68 $logger->debug("Done loading layered config from $value");
69  
70 return $value;
71 };
72  
73 1;
74  
75 # ABSTRACT: Include a sub layer configuration
76  
77 __END__