lib/Net/ISC/DHCPd/Types.pm

filter: Statementstmt 73.4% 58 / 79 Branchbran 16.6% 3 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 73.9% 17 / 23 Podpod 100% 3 / 3 totaltotal 65.8% 81 / 123 SCAR 29.6
CC
12
Cov
63%
from_State
20.0
from_FailoverState
20.0
__ANON__
6.0
CRAP 19.4
« blib/lib/Net/ISC/DHCPd/Config/OptionCode.pm ↑ Summary lib/Net/ISC/DHCPd.pm »
1 package Net::ISC::DHCPd::Types;
2  
3 =head1 NAME
4  
5 Net::ISC::DHCPd::Types - Moose type constraint declaration
6  
7 =head1 SYNOPSIS
8  
9 use Net::ISC::DHCPd::Types @types;
10 has foo => ( isa => SomeType, ... );
11  
12 =cut
13  
14 28 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 28 ▶use MooseX::Types;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 28 ▶use MooseX::Types::Moose ':all';
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 28 my @type_list;
19 28 my @failover_states = (
20 "na", "partner down",
21 "normal", "communications interrupted",
22 "resolution interrupted", "potential conflict",
23 "recover", "recover done",
24 "shutdown", "paused",
25 "startup", "recover wait",
26 );
27 28 my @states = qw/
28 na free active expired released
29 abandoned reset backup reserved bootp
30 /;
31  
32 BEGIN {
33 28 ▶ MooseX::Types->import(-declare => [@type_list = qw/
Subroutine BEGIN: called CC=1 SCAR=0.0
34 HexInt Ip Mac State Time Statements FailoverState
35 ConfigObject LeasesObject OMAPIObject ProcessObject
36 /]);
37 }
38  
39 =head1 TYPES
40  
41 =head2 HexInt
42  
43 =head2 Ip
44  
45 =head2 Mac
46  
47 =head2 State
48  
49 =head2 Time
50  
51 =cut
52  
53 subtype State, as Str,
54 24 ▶ where { my $s = $_; return grep { $s eq $_ } @states };
Subroutine __ANON__: called CC=1 SCAR=0.0
55 subtype FailoverState, as Str,
56 0 ▶ where { my $s = $_; return grep { $s eq $_ } @failover_states };
Subroutine __ANON__: not called CC=1 SCAR=3.5
57 28 subtype HexInt, as Int;
58 subtype Ip, as Str,
59 24 ▶ where { /^[\d.]+$/ };
Subroutine __ANON__: called CC=1 SCAR=0.0
60 subtype Mac, as Str,
61 48 ▶ where { /^[a-f0-9:]{17}$/i };
Subroutine __ANON__: called CC=1 SCAR=0.0
62  
63 28 subtype Time, as Int;
64  
65 coerce State, (
66 1 ▶ from Str, via { /(\d+)$/ ? $states[$1] : undef }
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
/(\d+)$/ ? : 1 0 1
67 28 );
68  
69 =head2 from_State
70  
71 =cut
72  
73 sub from_State {
74 0 ▶ my $self = shift;
Subroutine from_State: not called CC=4 SCAR=30.0
Pod documented
75 0 my $attr = shift;
76 0 ▶ my $value = $self->$attr or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $value = $self->$attr or return 0 0 0 0
77  
78 0 for my $i (0..@states) {
79 0 ▶ return $i if($states[$i] eq $value);
Branch: 1 branch
BranchTrueFalseTotal
if $states[$i] eq $value 0 0 0
80 }
81  
82 0 return 0;
83 }
84  
85 28 coerce FailoverState, (
86 from Str
87 );
88  
89 =head2 from_FailoverState
90  
91 =cut
92  
93 sub from_FailoverState {
94 0 ▶ my $self = shift;
Subroutine from_FailoverState: not called CC=4 SCAR=30.0
Pod documented
95 0 my $attr = shift;
96 0 ▶ my $value = $self->$attr or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $value = $self->$attr or return 0 0 0 0
97  
98 0 for my $i (0..@failover_states) {
99 0 ▶ return $i if($failover_states[$i] eq $value);
Branch: 1 branch
BranchTrueFalseTotal
if $failover_states[$i] eq $value 0 0 0
100 }
101  
102 0 return 0;
103 }
104  
105 coerce HexInt, (
106 1 ▶ from Str, via { s/://g; hex $_ },
Subroutine __ANON__: called CC=1 SCAR=0.0
107 28 );
108  
109 coerce Ip, (
110 1 ▶ from Str, via { join ".", map { hex $_ } split /:/ },
Subroutine __ANON__: called CC=1 SCAR=0.0
111 28 );
112  
113 coerce Mac, (
114 13 ▶ from Str, via { s/[\-\.:]//g; join ":", /(\w\w)/g },
Subroutine __ANON__: called CC=1 SCAR=0.0
115 28 );
116  
117 coerce Time, (
118 1 ▶ from Str, via { s/://g; hex $_ },
Subroutine __ANON__: called CC=1 SCAR=0.0
119 28 );
120  
121 =head2 Statements
122  
123 =cut
124  
125 3 ▶subtype Statements, as Str, where { /^[\w,]+$/ };
Subroutine __ANON__: called CC=1 SCAR=0.0
126  
127 coerce Statements, (
128 0 ▶ from Str, via { s/\s+/,/g; $_; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
129 1 ▶ from ArrayRef, via { join ",", @$_ },
Subroutine __ANON__: called CC=1 SCAR=0.0
130 28 );
131  
132 =head2 ConfigObject
133  
134 =head2 LeasesObject
135  
136 =head2 OMAPIObject
137  
138 =head2 ProcessObject
139  
140 =cut
141  
142 28 subtype ConfigObject, as Object;
143 28 subtype LeasesObject, as Object;
144 28 subtype OMAPIObject, as Object;
145 28 subtype ProcessObject, as Object;
146  
147 coerce ConfigObject, from HashRef, via {
148 4 ▶ eval "require Net::ISC::DHCPd::Config" or confess $@;
Subroutine __ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
eval "require Net::ISC::DHCPd::Config" or confess($@) 0 4 4
149 4 Net::ISC::DHCPd::Config->new($_);
150 28 };
151 coerce LeasesObject, from HashRef, via {
152 4 ▶ eval "require Net::ISC::DHCPd::Leases" or confess $@;
Subroutine __ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
eval "require Net::ISC::DHCPd::Leases" or confess($@) 0 4 4
153 4 Net::ISC::DHCPd::Leases->new($_);
154 28 };
155 coerce OMAPIObject, from HashRef, via {
156 0 ▶ eval "require Net::ISC::DHCPd::OMAPI" or confess $@;
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
eval "require Net::ISC::DHCPd::OMAPI" or confess($@) 0 0 0
157 0 Net::ISC::DHCPd::OMAPI->new($_);
158 28 };
159 coerce ProcessObject, from HashRef, via {
160 0 ▶ eval "require Net::ISC::DHCPd::Process" or confess $@;
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
eval "require Net::ISC::DHCPd::Process" or confess($@) 0 0 0
161 0 Net::ISC::DHCPd::Process->new($_);
162 28 };
163  
164 =head2 get_type_list
165  
166 @names = $class->get_type_list;
167  
168 Returns the types defined in this package.
169  
170 =cut
171  
172 sub get_type_list {
173 8 ▶ return @type_list;
Subroutine get_type_list: called CC=1 SCAR=0.0
Pod documented
174 }
175  
176 =head1 COPYRIGHT & LICENSE
177  
178 =head1 AUTHOR
179  
180 See L<Net::ISC::DHCPd>.
181  
182 =cut
183 28 __PACKAGE__->meta->make_immutable;
184 28 1;
« blib/lib/Net/ISC/DHCPd/Config/OptionCode.pm ↑ Summary lib/Net/ISC/DHCPd.pm »