File Coverage

lib/Net/ISC/DHCPd/Config/Zone.pm
Criterion Covered Total %
statement 11 13 84.6
branch 6 10 60.0
condition n/a
subroutine 5 6 83.3
pod 5 5 100.0
total 27 34 79.4


line stmt bran cond sub pod time code
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 24     24   21257 use Moose;
  24         65  
  24         226  
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 34     34 1 265 sub regex { qr{^\s* zone \s+ (")?(\S+)(\1|$) }x }
56              
57             =head2 children
58              
59             Modules with slurp need this special children variable to trick the parser
60             into recursively processing them.
61              
62             =cut
63              
64 1     1 1 15 sub children { [undef] }
65              
66              
67             =head1 METHODS
68              
69             =head2 slurp
70              
71             This method is used by L<Net::ISC::DHCPd::Config::Role/parse>, and will
72             slurp the content of the function, instead of trying to parse the
73             statements.
74              
75             =cut
76              
77             sub slurp {
78 4     4 1 9 my($self, $line) = @_;
79              
80 4 100       16 return 'last' if($line =~ /^\s*}/);
81             # not sure if these can really be quoted
82 3 100       54 $self->primary($1) if($line =~ /primary \s+ (\S+);/x);
83 3 100       50 $self->key($2) if($line =~ /key \s+ ("?)(\S+)\1;/x);
84 3         11 return 'next';
85             }
86              
87             =head2 captured_to_args
88              
89             See L<Net::ISC::DHCPd::Config::Role/captured_to_args>.
90              
91             =cut
92              
93             sub captured_to_args {
94 1     1 1 5 return { name => $_[1] }; # $_[0] == quote or empty string
95             }
96              
97             =head2 generate
98              
99             See L<Net::ISC::DHCPd::Config::Role/generate>.
100              
101             =cut
102              
103             sub generate {
104 0     0 1   my $self = shift;
105              
106             return(
107 0 0         sprintf('zone %s {', $self->name),
    0          
108             $self->primary ? (sprintf ' primary %s;', $self->primary) : (),
109             $self->key ? (sprintf ' key %s;', $self->key) : (),
110             '}',
111             );
112             }
113              
114             =head1 COPYRIGHT & LICENSE
115              
116             =head1 AUTHOR
117              
118             See L<Net::ISC::DHCPd>.
119              
120             =cut
121              
122             __PACKAGE__->meta->make_immutable;
123             1;