CSAF/Util/Options.pm untested

filter: Statementstmt 0.0% 0 / 38 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 56 CC 3 SCAR 12.4
CC
3
Cov
0%
_trigger_config_file
6.0
configure
6.0
clone
2.0
CRAP 3.5
1 package CSAF::Util::Options;
2  
3 use 5.010001;
4 use strict;
5 use warnings;
6 use utf8;
7  
8 use YAML::XS 'LoadFile';
9  
10 use Moo::Role;
11  
12 $YAML::XS::LoadBlessed = 0;
13  
14 has config_file =>
15 (is => 'rw', isa => sub { Carp::croak "Unable to open configuration file" unless -e $_[0] }, trigger => 1);
16  
17 sub _trigger_config_file {
18  
19 my $self = shift;
20  
21 my $config_data = LoadFile($self->config_file);
22  
23 foreach my $config_name (keys %{$config_data}) {
24  
25 my $config_value = $config_data->{$config_name};
26  
27 $config_name =~ s/\-/_/;
28 $self->$config_name($config_value) if $self->can($config_name);
29  
30 }
31  
32 }
33  
34 sub configure {
35  
36 my ($self, %args) = @_;
37  
38 foreach my $method (keys %args) {
39 my $value = $args{$method};
40 $self->$method($value) if $self->can($method);
41 }
42  
43 }
44  
45 sub clone {
46  
47 my $self = shift;
48 my $clone = {%$self};
49  
50 bless $clone, ref $self;
51 return $clone;
52  
53 }
54  
55 1;
56  
57 __END__