DHCPd/Config/Conditional.pm

filter: Statementstmt 100% 16 / 16 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod 100% 3 / 3 totaltotal 100% 25 / 25 CC 2 SCAR 3.4
CC
2
Cov
100%
generate
2.0
BEGIN
1.0
children
1.0
CRAP 1.4
« DHCPd/Config.pm ↑ Summary DHCPd/OMAPI/Meta/Attribute.pm »
1 package Net::ISC::DHCPd::Config::Conditional;
2  
3 =head1 NAME
4  
5 Net::ISC::DHCPd::Config::Conditional - if, elsif and/or else config parameter
6  
7 =head1 DESCRIPTION
8  
9 See L<Net::ISC::DHCPd::Config::Role> for methods and attributes without
10 documentation.
11  
12 An instance from this class, comes from / will produce:
13  
14 if option dhcp-user-class = "accounting" {
15 }
16 elsif option dhcp-user-class = "sales" {
17 }
18 else {
19 }
20  
21 =head1 SYNOPSIS
22  
23 See L<Net::ISC::DHCPd::Config/SYNOPSIS>.
24  
25 =cut
26  
27 27 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 27 with 'Net::ISC::DHCPd::Config::Role';
30  
31 =head2 children
32  
33 See L<Net::ISC::DHCPd::Config::Role/children>.
34  
35 =cut
36 46 ▶sub children {
Subroutine children: called CC=1 SCAR=0.0
Pod documented
37 46 return qw/
38 Net::ISC::DHCPd::Config::Subnet
39 Net::ISC::DHCPd::Config::Subnet6
40 Net::ISC::DHCPd::Config::SharedNetwork
41 Net::ISC::DHCPd::Config::Group
42 Net::ISC::DHCPd::Config::Host
43 Net::ISC::DHCPd::Config::Option
44 Net::ISC::DHCPd::Config::KeyValue
45 /;
46 }
47  
48 27 __PACKAGE__->create_children(__PACKAGE__->children());
49 =head1 ATTRIBUTES
50  
51 =head2 type
52  
53 =cut
54  
55 27 has type => (
56 is => 'ro',
57 isa => 'Str',
58 );
59  
60 =head2 logic
61  
62 =cut
63  
64 27 has logic => (
65 is => 'ro',
66 isa => 'Str',
67 );
68  
69 =head2 regex
70  
71 See L<Net::ISC::DHCPd::Config::Role/regex>.
72  
73 =cut
74 27 our $regex = qr/^ \s* (if|elsif|else) (.*?)(\s+\{|$) /x;
75  
76 =head1 METHODS
77  
78 =head2 captured_to_args
79  
80 See L<Net::ISC::DHCPd::Config::Role/captured_to_args>.
81  
82 =cut
83  
84 11 ▶sub captured_to_args {
Subroutine captured_to_args: called CC=1 SCAR=0.0
Pod documented
85 11 my($type, $logic) = @_;
86  
87 11 $logic =~ s/^\s+|\s+$//g;
88  
89 return {
90 11 type => $type,
91 logic => $logic,
92 };
93 }
94  
95 =head2 generate
96  
97 See L<Net::ISC::DHCPd::Config::Role/generate>.
98  
99 =cut
100  
101 9 ▶sub generate {
Subroutine generate: called CC=2 SCAR=6.9
Pod documented
102 9 my $self = shift;
103  
104 return(
105 9 ▶ $self->logic ? sprintf('%s %s {', $self->type, $self->logic) : $self->type .' {',
Branch: 1 branch
BranchTrueFalseTotal
$self->logic ? : 6 3 9
106 $self->generate_config_from_children,
107 '}',
108 );
109 }
110  
111 =head1 COPYRIGHT & LICENSE
112  
113 =head1 AUTHOR
114  
115 See L<Net::ISC::DHCPd>.
116  
117 =cut
118 27 __PACKAGE__->meta->make_immutable;
119 27 1;
« DHCPd/Config.pm ↑ Summary DHCPd/OMAPI/Meta/Attribute.pm »