blib/lib/Net/ISC/DHCPd/Config/FailoverPeer.pm untested

filter: Statementstmt 0.0% 0 / 46 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 57 SCAR 24.8
CC
3
Cov
0%
slurp
12.0
captured_to_args
2.0
generate
2.0
CRAP 12.0
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 use Moose;
36  
37 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 default => sub {
56 {
57 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 );
70  
71 has _order => (
72 traits => ['Array'],
73 is => 'rw',
74 isa => 'ArrayRef',
75 default => sub { [] },
76 );
77  
78 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 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 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 sub slurp {
106 my($self, $line) = @_;
107  
108 while(my ($name, $value) = each (%{$self->arguments})) {
109 my $regex = $value->{regex};
110 if ($line =~ $regex) {
111 $self->$name($1);
112 push(@{$self->_order}, $name);
113 }
114 }
115  
116 return 'last' if($line =~ /^\s*}/);
117 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 sub captured_to_args {
127 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 sub generate {
137 my $self = shift;
138  
139 my $return = sprintf('failover peer "%s" {', $self->name);
140 $return .= "\n";
141  
142 for(@{$self->_order}) {
143 $return .= sprintf(' '. $self->arguments->{$_}->{text} . ";\n", $self->$_);
144 }
145  
146 $return .= "}\n";
147  
148 return($return);
149 }
150  
151 =head1 COPYRIGHT & LICENSE
152  
153 =head1 AUTHOR
154  
155 See L<Net::ISC::DHCPd>.
156  
157 =cut
158 __PACKAGE__->meta->make_immutable;
159 1;