PlConfig.pm

filter: Statementstmt 68.9% 71 / 103 Branchbran 33.3% 6 / 18 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 84.2% 16 / 19 Podpod 80.0% 4 / 5 totaltotal 65.3% 98 / 150 CC 12 SCAR 20.6
CC
12
Cov
63%
import
30.5
save
6.0
DEMOLISH
3.8
CRAP 7.9
↑ Summary PlConfig/DotScheme.pm »
1 # $Id$
2 # $Source$
3 # $Author$
4 # $HeadURL$
5 # $Revision$
6 # $Date$
7 package Config::PlConfig;
8 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use 5.006001;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use version; our $VERSION = qv('0.1_02');
Subroutine BEGIN: called CC=1 SCAR=0.0
13 {
14  
15 2 ▶ use Class::Dot qw(property isa_String isa_Data isa_Hash isa_Int isa_Object);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶ use Config::PlConfig::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶ use Config::PlConfig::Host::Local;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 ▶ use Config::PlConfig::Host::Global;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶ use Config::PlConfig::DotScheme;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 2 ▶ use YAML::Syck qw(LoadFile DumpFile);
Subroutine BEGIN: called CC=1 SCAR=0.0
21 2 ▶ use Params::Util qw(_CODELIKE);
Subroutine BEGIN: called CC=1 SCAR=0.0
22
23 2 my %HOST_TO_CLASS = (
24 'local' => 'Config::PlConfig::Host::Local',
25 'global' => 'Config::PlConfig::Host::Global',
26 );
27  
28 2 property domain => isa_String('system.DEFAULT');
29 2 property host => isa_Data();
30 2 property options => isa_Hash();
31 2 property config => isa_Hash();
32 2 property autosave => isa_Int(0);
33 2 property dotscheme => isa_Object;
34  
35 2 my $GLOBAL_AUTOSAVE = 0;
36  
37 my %EXPORT_TAGS = (
38 0 ▶ ':autosave' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
39 0 $GLOBAL_AUTOSAVE = 1;
40 },
41 2 );
42
43 2 ▶ sub import {
Subroutine import: called CC=6 SCAR=34.2
44 2 shift;
45 2 ▶ return if not scalar @_;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @_ 2 0 2
46 0 my $caller = caller 0;
47  
48 ARG:
49 0 for my $arg (@_) {
50 0 ▶ if (exists $EXPORT_TAGS{$arg}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $EXPORT_TAGS{$arg}) 0 0 0
51 0 my $handler = $EXPORT_TAGS{$arg};
52 0 ▶ if (_CODELIKE($handler)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&_CODELIKE($handler)) 0 0 0
53 0 $handler->($caller);
54 }
55 0 next ARG;
56 }
57 0 require Carp;
58 0 my @msg = "No such export tag: $arg.";
59 0 my $alt = ":$arg";
60 0 ▶ if ($EXPORT_TAGS{$alt}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($EXPORT_TAGS{$alt}) 0 0 0
61 0 push @msg, "Did you mean $alt?";
62 };
63 0 my $msg = join q{ }, @msg;
64 0 Carp::croak($msg);
65 }
66  
67 0 return;
68 }
69  
70 2 ▶ sub new {
Subroutine new: called CC=3 SCAR=11.0
Pod documented
71 2 my ($class, $options_ref) = @_;
72 2 my $self = { };
73 2 bless $self, $class;
74  
75 2 my $DEFAULT_HOST = Config::PlConfig::Constants->get(
76 'DEFAULT_HOST'
77 );
78  
79 my $host_class = $options_ref->{host}
80 ? $HOST_TO_CLASS{ lc $options_ref->{host} }
81 2 ▶ : $HOST_TO_CLASS{ lc $DEFAULT_HOST };
Branch: 1 branch
BranchTrueFalseTotal
$options_ref->{'host'} ? : 1 1 2
82 2 my $host = $host_class->new($options_ref);
83  
84 1 ▶ if ($options_ref->{domain}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options_ref->{"domain"}) 0 1 1
85 0 $self->set_domain( $options_ref->{domain} );
86 }
87  
88 my $dotscheme = Config::PlConfig::DotScheme->new({
89 plconfig => $self,
90 dumper => $options_ref->{dumper},
91 1 });
92  
93
94 1 $self->set_host($host);
95 1 $self->set_options($options_ref);
96 1 $self->set_dotscheme($dotscheme);
97  
98 1 $self->load( );
99
100 1 return $self;
101 }
102  
103 0 ▶ sub get {
Subroutine get: not called CC=1 SCAR=6.9
Pod documented
104 0 my ($self, $key) = @_;
105 0 my $config = $self->config;
106  
107 0 return $config->{$key};
108 }
109  
110 1 ▶ sub load {
Subroutine load: called CC=2 SCAR=7.8
Pod documented
111 1 my ($self) = @_;
112 1 my $host = $self->host;
113 1 my $domain = $self->domain;
114 1 my $cfile = $host->file_for_domain($domain);
115  
116 1 ▶ if (! -f $cfile) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f $cfile) 1 0 1
117 1 return;
118 }
119  
120 0 my $config_ref = YAML::Syck::LoadFile($cfile);
121 0 $self->set_config($config_ref);
122  
123 0 return $config_ref;
124 }
125  
126 0 ▶ sub save {
Subroutine save: not called CC=2 SCAR=17.9
Pod documented
127 0 my ($self, $opt_config) = @_;
128 0 my $host = $self->host;
129 0 my $domain = $self->domain;
130 0 my $config = $self->config;
131 0 my $cfile = $host->file_for_domain($domain);
132  
133 0 ▶ if ($opt_config) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt_config) 0 0 0
134 0 $config = $opt_config;
135 }
136  
137 0 return YAML::Syck::DumpFile($cfile, $config);
138 }
139  
140 1 ▶ sub DEMOLISH {
Subroutine DEMOLISH: called CC=3 SCAR=13.3
Pod undocumented
141 1 my ($self) = @_;
142  
143 1 ▶ if ($GLOBAL_AUTOSAVE || $self->autosave) {
Branch: 1 branch
BranchTrueFalseTotal
if ($GLOBAL_AUTOSAVE or $self->autosave) 0 1 1
Condition33%1/3
$GLOBAL_AUTOSAVE or $self->autosave
l!l&&r!l&&!r
001
MC/DC0%0/2
$GLOBAL_AUTOSAVE or $self->autosave
$GLOBAL_AUTOSAVE $self->autosave
Truth table33%1/3
A or B
A= $GLOBAL_AUTOSAVEB= $self->autosave
ABresult
1X1
011
000
144 0 $self->save( );
145 }
146  
147 1 return;
148 }
149 }
150  
151 2 1; # Magic true value required at end of module
152 __END__
↑ Summary PlConfig/DotScheme.pm »