lib/Package/Strictures.pm

filter: Statementstmt 80.8% 55 / 68 Branchbran 55.5% 10 / 18 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 11 / 11 Podpod n/a totaltotal 76.4% 78 / 102 SCAR 27.4
CC
13
Cov
75%
import
7.3
_setup_from
3.5
_setup_for_package
3.5
CRAP 15.6
« lib/Package/Strictures/Register.pm ↑ Summary blib/lib/Package/Strictures/Registry.pm »
1 3 ▶use 5.008; # 8 = utf8, 6 = pragmas, our, 5 = qr, 4 = __PACAKGE__,for my
Subroutine BEGIN: called CC=1 SCAR=0.0
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 package Package::Strictures;
7 3 $Package::Strictures::VERSION = '1.000000';
8 # ABSTRACT: Facilitate toggling validation code at users request, without extra performance penalties.
9  
10 3 our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
11  
12 3 ▶use Package::Strictures::Registry;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69 sub import {
70 2 ▶ my ( $self, %params ) = @_;
Subroutine import: called CC=6 SCAR=19.9
71 2 ▶ if ( not %params ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (%params) 0 2 2
72 0 Carp::carp( __PACKAGE__ . ' called with no parameters, skipping magic' );
73 0 return;
74 }
75 2 ▶ if ( ( not exists $params{-for} ) && ( not exists $params{-from} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $params{"-for"} or exists $params{"-from"}) 0 2 2
Condition66%2/3
exists $params{"-for"} or exists $params{"-from"}
l!l&&r!l&&!r
110
MC/DC0%0/2
exists $params{"-for"} or exists $params{"-from"}
exists $params{"-for"} exists $params{"-from"}
Truth table66%2/3
A or B
A= exists $params{"-for"}B= exists $params{"-from"}
ABresult
1X1
011
000
76 0 Carp::croak( 'no -for or -from parameter to ' . __PACKAGE__ );
77 }
78 2 ▶ if ( exists $params{-for} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $params{"-for"}) 1 1 2
79 1 $self->_setup_for( $params{-for} );
80 1 return;
81 }
82 1 ▶ if ( exists $params{-from} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $params{"-from"}) 1 0 1
83 1 $self->_setup_from( $params{-from} );
84 1 return;
85 }
86 0 Carp::croak('Ugh!?');
87 }
88  
89 sub _setup_for {
90 2 ▶ my ( $self, $params ) = @_;
Subroutine _setup_for: called CC=3 SCAR=11.2
91 2 my $reftype = ref $params;
92 2 ▶ if ( $reftype ne 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reftype ne "HASH") 0 2 2
93 0 Carp::croak("-for presently only takes HASH, got `$reftype`");
94 }
95 2 for my $package ( keys %{$params} ) {
96 2 $self->_setup_for_package( $params->{$package}, $package );
97 }
98 2 return;
99 }
100  
101 sub _setup_from {
102 1 ▶ my ( $self, $from ) = @_;
Subroutine _setup_from: called CC=3 SCAR=12.6
103 1 my $reftype = ref $from;
104 1 ▶ if ($reftype) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reftype) 0 1 1
105 0 Carp::croak("-from can only take a scalar, not a ref, got `$reftype`");
106 }
107 ## no critic (RegularExpressions::RequireDotMatchAnything RegularExpressions::RequireLineBoundaryMatching)
108 1 ▶ if ( $from =~ /[.]ini$/x ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($from =~ /[.]ini$/x) 1 0 1
109 1 $self->_setup_from_ini($from);
110 1 return;
111 }
112 0 Carp::croak('Only know how to load setup from .ini files at present');
113 0 return;
114 }
115  
116 sub _setup_from_ini {
117 1 ▶ my ( $self, $from ) = @_;
Subroutine _setup_from_ini: called CC=2 SCAR=7.1
118 1 require Config::INI::Reader;
119 1 my ($conf) = Config::INI::Reader->read_file($from);
120 1 ▶ if ( exists $conf->{'_'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $conf->{"_"}) 0 1 1
121 0 Carp::carp("Strictures not addressed at a package found in `$from`");
122 }
123 1 $self->_setup_for($conf);
124 1 return;
125 }
126  
127 sub _setup_for_package {
128 2 ▶ my ( undef, $params, $package ) = @_;
Subroutine _setup_for_package: called CC=3 SCAR=12.6
129 2 my $reftype = ref $params;
130 2 ▶ if ( $reftype ne 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reftype ne "HASH") 0 2 2
131 0 my $mesg = q[];
132 0 $mesg .= q[-for => { Some::Name => X } presently only takes HASH,];
133 0 $mesg .= q[got `%s` on package `%s` ];
134 0 Carp::croak( sprintf $mesg, $reftype, $package );
135 }
136 2 for my $value ( keys %{$params} ) {
137 2 Package::Strictures::Registry->set_value( $package, $value, $params->{$value} );
138 }
139 2 return;
140 }
141  
142 3 1;
143  
144 __END__
« lib/Package/Strictures/Register.pm ↑ Summary blib/lib/Package/Strictures/Registry.pm »