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

filter: Statementstmt 0.0% 0 / 16 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 33 SCAR 37.4
CC
6
Cov
0%
slurp
20.0
generate
12.0
captured_to_args
2.0
CRAP 42.0
1 package Net::ISC::DHCPd::Config::Zone;
2  
3 =head1 NAME
4  
5 Net::ISC::DHCPd::Config::Zone - Server Zone
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 zone $name {
17 primary $primary;
18 key $key;
19 };
20  
21 =head1 SYNOPSIS
22  
23 See L<Net::ISC::DHCPd::Config/SYNOPSIS>.
24  
25 =cut
26  
27 use Moose;
28  
29 with 'Net::ISC::DHCPd::Config::Role';
30  
31 =head1 ATTRIBUTES
32  
33 =head2 name
34  
35 Name of the Zone - See L</DESCRIPTION> for details.
36  
37 =head2 primary
38  
39 =head2 key
40  
41 =cut
42  
43 has [qw/ name key primary /] => (
44 is => 'rw', # TODO: WILL PROBABLY CHANGE!
45 isa => 'Str',
46 );
47  
48 =head2 regex
49  
50 See L<Net::ISC::DHCPd::Config::Role/regex>.
51  
52 =cut
53  
54 # not sure if this can be quoted or not
55 our $regex = qr{^\s* zone \s+ (")?(\S+)(\1|$) }x;
56  
57 =head1 METHODS
58  
59 =head2 slurp
60  
61 This method is used by L<Net::ISC::DHCPd::Config::Role/parse>, and will
62 slurp the content of the function, instead of trying to parse the
63 statements.
64  
65 =cut
66  
67 sub slurp {
68 my($self, $line) = @_;
69  
70 return 'last' if($line =~ /^\s*}/);
71 # not sure if these can really be quoted
72 $self->primary($1) if($line =~ /primary \s+ (\S+);/x);
73 $self->key($2) if($line =~ /key \s+ ("?)(\S+)\1;/x);
74 return 'next';
75 }
76  
77 =head2 captured_to_args
78  
79 See L<Net::ISC::DHCPd::Config::Role/captured_to_args>.
80  
81 =cut
82  
83 sub captured_to_args {
84 return { name => $_[1] }; # $_[0] == quote or empty string
85 }
86  
87 =head2 generate
88  
89 See L<Net::ISC::DHCPd::Config::Role/generate>.
90  
91 =cut
92  
93 sub generate {
94 my $self = shift;
95  
96 return(
97 sprintf('zone %s {', $self->name),
98 $self->primary ? (sprintf ' primary %s;', $self->primary) : (),
99 $self->key ? (sprintf ' key %s;', $self->key) : (),
100 '}',
101 );
102 }
103  
104 =head1 COPYRIGHT & LICENSE
105  
106 =head1 AUTHOR
107  
108 See L<Net::ISC::DHCPd>.
109  
110 =cut
111  
112 __PACKAGE__->meta->make_immutable;
113 1;