PlConfig/Host/Base.pm

filter: Statementstmt 96.6% 58 / 60 Branchbran 66.6% 4 / 6 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 93.3% 14 / 15 Podpod 0.0% 0 / 5 totaltotal 86.5% 77 / 89 CC 5 SCAR 4.6
CC
5
Cov
93%
init_confdir
3.0
check_domain
2.1
file_for_domain
2.0
CRAP 1.6
« PlConfig/Tied.pm ↑ Summary PlConfig/Host/Global.pm »
1 # $Id$
2 # $Source$
3 # $Author$
4 # $HeadURL$
5 # $Revision$
6 # $Date$
7 package Config::PlConfig::Host::Base;
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 qw(croak);
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 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 {
15  
16 2 ▶ use Class::Dot qw(property isa_String);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶ use File::Path qw(mkpath);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 ▶ use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶ use Config::PlConfig::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 2 property confdir => isa_String;
22  
23 2 my $RE_UNTAINT_DOMAIN = qr/
24 \A # beginning of string.
25 ( # capture:
26 [\w\d\.\+\-\_]+? # any letter, digit, dot, plus-sign,
27 # minus-sign or underscore.
28 )
29 \z # end of string.
30 /xms;
31  
32 4 ▶ sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
33 4 my ($class, $options_ref) = @_;
34 4 my $self = { };
35 4 bless $self, $class;
36  
37 4 my $CONF_DIRNAME = Config::PlConfig::Constants->get('CONF_DIRNAME');
38  
39 4 my $confdir_parent = $self->locate_confdir_parent;
40 4 my $confdir = File::Spec->catdir($confdir_parent, $CONF_DIRNAME);
41 4 $self->set_confdir( $confdir );
42 4 $self->init_confdir( );
43  
44 2 return $self;
45 }
46  
47 1 ▶ sub file_for_domain {
Subroutine file_for_domain: called CC=2 SCAR=7.0
Pod undocumented
48 1 my ($self, $domain) = @_;
49  
50 1 ▶ $domain = $self->check_domain($domain) || return;
Condition50%1/2
$self->check_domain($domain) || (return)
l!l
10
MC/DC0%0/1
$self->check_domain($domain) || (return)
$self->check_domain($domain)
Truth table50%1/2
A
A= $self->check_domain($domain)
Aresult
11
00
51 1 my $DOMAINFILE_SUFFIX = Config::PlConfig::Constants->get(
52 'DOMAINFILE_SUFFIX'
53 );
54  
55 1 my $configfile = File::Spec->catfile(
56 $self->confdir,
57 $domain,
58 );
59  
60 1 $configfile = join q{.}, $configfile, $DOMAINFILE_SUFFIX;
61  
62 1 return $configfile;
63 }
64  
65 0 ▶ sub locate_confdir {
Subroutine locate_confdir: not called CC=1 SCAR=6.9
Pod undocumented
66 0 croak 'Cannot use '. __PACKAGE__ . 'directly!';
67 }
68  
69 1 ▶ sub check_domain {
Subroutine check_domain: called CC=2 SCAR=7.4
Pod undocumented
70 1 my ($self, $domain) = @_;
71
72 1 ▶ if ($domain =~ $RE_UNTAINT_DOMAIN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($domain =~ /$RE_UNTAINT_DOMAIN/msx) 1 0 1
73 1 $domain = $1;
74 1 return $domain;
75 }
76  
77 #carp "Illegal domain name."; # TODO Error handling!.
78
79 0 return;
80 }
81  
82 4 ▶ sub init_confdir {
Subroutine init_confdir: called CC=3 SCAR=11.0
Pod undocumented
83 4 my ($self) = @_;
84 4 my $confdir = $self->confdir;
85  
86 4 ▶ if (! -d $confdir) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $confdir) 3 1 4
87 3 ▶ mkpath($confdir) or return;
Branch: 1 branch
BranchTrueFalseTotal
mkpath($confdir) or return 1 0 1
88 }
89  
90 2 return 1;
91 }
92 }
93  
94 # Module implementation here
95  
96  
97 2 1; # Magic true value required at end of module
98 __END__
« PlConfig/Tied.pm ↑ Summary PlConfig/Host/Global.pm »