blib/lib/auto/share/dist/Cmd-Dwarf/app/lib/Dwarf/Config.pm untested

filter: Statementstmt 0.0% 0 / 50 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 9 totaltotal 0.0% 0 / 93 CC 7 SCAR 23.7
CC
7
Cov
0%
get
30.0
_build_is_data_dpath_installed
6.0
_build_is_data_path_installed
6.0
CRAP 10.7
1 package Dwarf::Config;
2 use Dwarf::Pragma;
3 use Dwarf::Util qw/installed dwarf_log/;
4  
5 use Dwarf::Accessor {
6 ro => [qw/context is_data_path_installed is_data_dpath_installed/]
7 };
8  
9 # Data::DPath サポート
10 sub _build_is_data_dpath_installed {
11 my $self = shift;
12 $self->{is_data_dpath_installed} ||= do {
13 my $is_data_dpath_installed = 0;
14 if (installed('Data::DPath')) {
15 $is_data_dpath_installed = 1;
16 }
17 $is_data_dpath_installed;
18 };
19 }
20  
21 # Data::Path サポート
22 sub _build_is_data_path_installed {
23 my $self = shift;
24 $self->{is_data_path_installed} ||= do {
25 my $is_data_path_installed = 0;
26 if (installed('Data::Path')) {
27 $is_data_path_installed = 1;
28 }
29 $is_data_path_installed;
30 };
31 }
32  
33 sub new {
34 my $class = shift;
35 my $self = bless { @_ }, $class;
36 dwarf_log 'new Config';
37 $self->init;
38 return $self;
39 }
40  
41 sub DESTROY {
42 my $self = shift;
43 dwarf_log 'DESTROY Config';
44 delete $self->{context};
45 }
46  
47 sub c { shift->context }
48  
49 sub init {
50 my $self = shift;
51 $self->set($self->setup);
52 }
53  
54 sub setup { return () }
55  
56 sub get {
57 my ($self, $key) = @_;
58  
59 if ($self->is_data_dpath_installed) {
60 if ($key =~ /\//) {
61 my $dpath = Data::DPath::Path->new(path => $key);
62 return ($dpath->match($self))[0];
63 }
64 } elsif ($self->is_data_path_installed) {
65 if ($key =~ /\//) {
66 my $hpath = Data::Path->new($self);
67 return $hpath->get($key);
68 }
69 }
70  
71 return $self->{$key};
72 }
73  
74 sub set {
75 my $self = shift;
76 my $args = { @_ };
77  
78 while (my ($key, $value) = each %$args) {
79 $self->{$key} = $value;
80 }
81 }
82  
83 1;