| 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::Update 2.169; | ||||||||||||||
| 11 | |||||||||||||||
| 12 | 59 | ▶ | use v5.20; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 13 | 59 | ▶ | use Mouse; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 14 | 59 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 15 | 59 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 16 | 59 | ▶ | use Log::Log4perl qw(get_logger :levels); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 17 | 59 | ▶ | use Mouse::Util::TypeConstraints; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 18 | 59 | ▶ | use Config::Model::Value::UpdateFromFile; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 19 | |||||||||||||||
| 20 | 59 | ▶ | use feature qw/postderef signatures/; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 21 | 59 | ▶ | no warnings qw/experimental::postderef experimental::signatures/; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 22 | |||||||||||||||
| 23 | 59 | my $logger = get_logger("Tree::Element::Value"); | |||||||||||||
| 24 | 59 | my $user_logger = get_logger("User"); | |||||||||||||
| 25 | |||||||||||||||
| 26 | 59 | enum ActionWhenMissing => qw/die warn ignore/; | |||||||||||||
| 27 | |||||||||||||||
| 28 | 59 | has "when_missing" => (is => 'rw', isa => 'ActionWhenMissing'); | |||||||||||||
| 29 | |||||||||||||||
| 30 | 59 | has "files" => ( | |||||||||||||
| 31 | is => 'ro', | ||||||||||||||
| 32 | isa => 'ArrayRef[HashRef]', | ||||||||||||||
| 33 | traits => ['Array'], | ||||||||||||||
| 34 | handles => { | ||||||||||||||
| 35 | file_specs => 'elements', | ||||||||||||||
| 36 | source_count => 'count' | ||||||||||||||
| 37 | }, | ||||||||||||||
| 38 | ); | ||||||||||||||
| 39 | |||||||||||||||
| 40 | has "file_obj" => ( | ||||||||||||||
| 41 | is => 'rw', | ||||||||||||||
| 42 | isa => 'ArrayRef[Config::Model::Value::UpdateFromFile]', | ||||||||||||||
| 43 | traits => ['Array'], | ||||||||||||||
| 44 | handles => { | ||||||||||||||
| 45 | file_sources => 'elements', | ||||||||||||||
| 46 | }, | ||||||||||||||
| 47 | # must be lazy, otherwise, $self->location below may be undef | ||||||||||||||
| 48 | lazy => 1, | ||||||||||||||
| 49 | 5 | ▶ | builder => sub ($self) { | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 50 | return [ | ||||||||||||||
| 51 | map { | ||||||||||||||
| 52 | 5 | Config::Model::Value::UpdateFromFile->new(%$_, location => $self->location); | |||||||||||||
| 53 | } $self->file_specs | ||||||||||||||
| 54 | ]; | ||||||||||||||
| 55 | } | ||||||||||||||
| 56 | 59 | ); | |||||||||||||
| 57 | |||||||||||||||
| 58 | 59 | has 'location' => ( | |||||||||||||
| 59 | is => 'ro', | ||||||||||||||
| 60 | isa => 'Str', | ||||||||||||||
| 61 | ); | ||||||||||||||
| 62 | |||||||||||||||
| 63 | 1 | ▶ | sub get_info ($self) { | ||||||||||||
|
Subroutine
get_info: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||
| 64 | 1 | my @info; | |||||||||||||
| 65 | 1 | foreach my $obj ($self->file_sources) { | |||||||||||||
| 66 | 1 | push @info, $obj->get_info; | |||||||||||||
| 67 | } | ||||||||||||||
| 68 | 1 | return join(", ", @info); | |||||||||||||
| 69 | } | ||||||||||||||
| 70 | |||||||||||||||
| 71 | 8 | ▶ | sub get_update_value ($self) { | ||||||||||||
|
Subroutine
get_update_value: called CC=5 SCAR=16.3
Pod
documented
| |||||||||||||||
| 72 | 8 | my @errors; | |||||||||||||
| 73 | 8 | foreach my $obj ( $self->file_sources ) { | |||||||||||||
| 74 | |||||||||||||||
| 75 | # Go style error handling, either $v or $err is set | ||||||||||||||
| 76 | 8 | my ( $v, $err ) = $obj->get_update_value; | |||||||||||||
| 77 | 8 | ▶ | if ($err) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 78 | 2 | push @errors, $err; | |||||||||||||
| 79 | 2 | next; | |||||||||||||
| 80 | } | ||||||||||||||
| 81 | 6 | return $v; | |||||||||||||
| 82 | } | ||||||||||||||
| 83 | |||||||||||||||
| 84 | # warn when no data was found, e.g. each obj did not find data | ||||||||||||||
| 85 | 2 | my $when_missing = $self->when_missing; | |||||||||||||
| 86 | 2 | my $msg = $self->location . ": " . join( "\n ", @errors ); | |||||||||||||
| 87 | |||||||||||||||
| 88 | 2 | ▶ | if ( $when_missing eq 'die' ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 89 | 0 | $user_logger->logdie($msg); | |||||||||||||
| 90 | } | ||||||||||||||
| 91 | elsif ( $when_missing eq 'warn' ) { | ||||||||||||||
| 92 | 2 | $user_logger->warn($msg); | |||||||||||||
| 93 | } | ||||||||||||||
| 94 | 2 | return; | |||||||||||||
| 95 | } | ||||||||||||||
| 96 | |||||||||||||||
| 97 | 59 | 1; | |||||||||||||
| 98 | |||||||||||||||
| 99 | # ABSTRACT: Retrieve data from several external files | ||||||||||||||
| 100 | |||||||||||||||
| 101 | __END__ | ||||||||||||||