DHCPd/Config/FailoverPeer.pm

filter: Statementstmt 75.0% 24 / 32 Branchbran 100% 6 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 83.3% 5 / 6 Podpod 100% 3 / 3 totaltotal 80.8% 38 / 47 CC 5 SCAR 11.6
CC
5
Cov
79%
generate
6.0
slurp
4.0
BEGIN
1.0
CRAP 3.2
« DHCPd/OMAPI/Sugar.pm ↑ Summary DHCPd/Config/Include.pm »
1 package Net::ISC::DHCPd::Config::FailoverPeer;
2  
3 =head1 NAME
4  
5 Net::ISC::DHCPd::Config::FailoverPeer - Failover Peer Configuration
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 the block below:
13  
14 $name_attribute_value $value_attribute_value;
15  
16 failover peer "$name" {
17 $primary;
18 address dhcp-primary.example.com;
19 port 519;
20 peer address dhcp-secondary.example.com;
21 peer port 520;
22 max-response-delay 60;
23 max-unacked-updates 10;
24 mclt 3600;
25 split 128;
26 load balance max seconds 3;
27 }
28  
29 =head1 SYNOPSIS
30  
31 See L<Net::ISC::DHCPd::Config/SYNOPSIS>.
32  
33 =cut
34  
35 27 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 27 with 'Net::ISC::DHCPd::Config::Role';
38  
39 =head1 ATTRIBUTES
40  
41 =head2 name
42  
43 Name of the key - See L</DESCRIPTION> for details.
44  
45 =head2 arguments
46  
47 This is an array of arguments supplied to the failover peer.
48  
49 =cut
50  
51 has arguments => (
52 traits => ['Hash'],
53 is => 'ro',
54 isa => 'HashRef',
55 3 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
56 {
57 3 port => { "text" => "port %s", regex => qr/^ \s+ port \s+ (\d+);/x },
58 peer_port => { "text" => "peer port %s", regex => qr/^ \s+ peer \s+ port \s+ (\d+);/x },
59 address => { "text" => "address %s", regex => qr/^ \s+ address \s+ (\S+);/x },
60 peer_address => { "text" => "peer address %s", regex => qr/^ \s+ peer \s+ address \s+ (\S+);/x },
61 type => { "text" => "%s", regex => qr/^ \s+ (primary|secondary);/x },
62 max_response_delay => { "text" => "max-response-delay %s", regex => qr/^ \s+ max-response-delay \s+ (\d+);/x },
63 max_unacked_updates => { "text" => "max-unacked-updates %s", regex => qr/^ \s+ max-unacked-updates \s+ (\d+);/x },
64 lb_max_seconds => { "text" => "load balance max seconds %s", regex => qr/^ \s+ load\s+balance\s+max\s+seconds \s+ (\d+);/x },
65 mclt => { "text" => "mclt %s", regex => qr/^ \s+ mclt \s+ (\d+);/x },
66 split => { "text" => "split %s", regex => qr/^ \s+ split \s+ (\d+);/x },
67 }
68 },
69 27 );
70  
71 has _order => (
72 traits => ['Array'],
73 is => 'rw',
74 isa => 'ArrayRef',
75 3 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
76 27 );
77  
78 27 has [qw/ peer_port port mclt split lb_max_seconds max_response_delay max_unacked_updates /] => (
79 is => 'rw',
80 isa => 'Int',
81 );
82  
83 27 has [qw/ name type address peer_address /] => (
84 is => 'rw',
85 isa => 'Str',
86 );
87  
88 =head2 regex
89  
90 See L<Net::ISC::DHCPd::Config::Role/regex>.
91  
92 =cut
93 27 our $regex = qr{^\s* failover \s+ peer \s+ ("?)(\S+)(\1) }x;
94  
95 =head1 METHODS
96  
97 =head2 slurp
98  
99 This method is used by L<Net::ISC::DHCPd::Config::Role/parse>, and will
100 slurp the content of the function, instead of trying to parse the
101 statements.
102  
103 =cut
104  
105 22 ▶sub slurp {
Subroutine slurp: called CC=4 SCAR=13.9
Pod documented
106 22 my($self, $line) = @_;
107  
108 22 ▶ while(my ($name, $value) = each (%{$self->arguments})) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$self->arguments;}) 220 22 242
109 220 my $regex = $value->{regex};
110 220 ▶ if ($line =~ $regex) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /$regex/) 17 203 220
111 17 $self->$name($1);
112 17 push(@{$self->_order}, $name);
113 }
114 }
115  
116 22 ▶ return 'last' if($line =~ /^\s*}/);
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*}/ 3 19 22
117 19 return 'next';
118 }
119  
120 =head2 captured_to_args
121  
122 See L<Net::ISC::DHCPd::Config::Role/captured_to_args>.
123  
124 =cut
125  
126 3 ▶sub captured_to_args {
Subroutine captured_to_args: called CC=1 SCAR=0.0
Pod documented
127 3 return { name => $_[1] }; # $_[0] == quote or empty string
128 }
129  
130 =head2 generate
131  
132 See L<Net::ISC::DHCPd::Config::Role/generate>.
133  
134 =cut
135  
136 0 ▶sub generate {
Subroutine generate: not called CC=2 SCAR=17.9
Pod documented
137 0 my $self = shift;
138  
139 0 my $return = sprintf('failover peer "%s" {', $self->name);
140 0 $return .= "\n";
141  
142 0 for(@{$self->_order}) {
143 0 $return .= sprintf(' '. $self->arguments->{$_}->{text} . ";\n", $self->$_);
144 }
145  
146 0 $return .= "}\n";
147  
148 0 return($return);
149 }
150  
151 =head1 COPYRIGHT & LICENSE
152  
153 =head1 AUTHOR
154  
155 See L<Net::ISC::DHCPd>.
156  
157 =cut
158 27 __PACKAGE__->meta->make_immutable;
159 27 1;
« DHCPd/OMAPI/Sugar.pm ↑ Summary DHCPd/Config/Include.pm »