lib/Net/ISC/DHCPd/Config/Role.pm

filter: Statementstmt 88.8% 199 / 224 Branchbran 73.4% 69 / 94 Conditioncond 66.6% 6 / 9 MC/DCmcdc 50.0% 3 / 6 Subroutinesub 83.8% 26 / 31 Podpod 100% 7 / 7 totaltotal 83.5% 310 / 371 SCAR 45.4
CC
72
Cov
84%
parse
17.1
_build_depth
12.0
_set_children
12.0
CRAP 94.1
« blib/lib/Net/ISC/DHCPd/OMAPI.pm ↑ Summary blib/lib/Net/ISC/DHCPd/Config/Key.pm »
1 package Net::ISC::DHCPd::Config::Role;
2  
3 =head1 NAME
4  
5 Net::ISC::DHCPd::Config::Role - Role with generic config methods and attributes
6  
7 =head1 DESCRIPTION
8  
9 This role contains common methods and attributes for each of the config
10 classes in the L<Net::ISC::DHCPd::Config> namespace.
11  
12 =head1 WARNINGS
13  
14 This module will warn when a line in the input config could not be parsed.
15 This can be turned off by adding the line below before calling L</parse>.
16  
17 no warnings 'net_isc_dhcpd_config_parse';
18  
19 =cut
20  
21 26 ▶use Class::Load;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 26 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 26 requires 'generate';
25  
26 =head1 ATTRIBUTES
27  
28 =head2 parent
29  
30 The parent node in the config tree. This must be an object which does
31 this role.
32  
33 =cut
34  
35 26 has parent => (
36 is => 'rw',
37 does => 'Net::ISC::DHCPd::Config::Role',
38 weak_ref => 1,
39 );
40  
41 =head2 root
42  
43 The root node in the config tree.
44  
45 =cut
46  
47 has root => (
48 is => 'ro',
49 isa => 'Object',
50 weak_ref => 1,
51 25 ▶ default => sub { $_[0] },
Subroutine __ANON__: called CC=1 SCAR=0.0
52 26 );
53  
54 =head2 depth
55  
56 Integer value that counts how far this node is from the root node.
57  
58 =cut
59  
60 26 has depth => (
61 is => 'ro',
62 isa => 'Int',
63 lazy => 1,
64 builder => '_build_depth',
65 );
66  
67 sub _build_depth {
68 0 ▶ my $self = shift;
Subroutine _build_depth: not called CC=3 SCAR=24.8
69 0 my $obj = $self;
70 0 my $i = 0;
71  
72 0 ▶ while($obj = $obj->parent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj = $obj->parent) 0 0 0
73 0 $i++;
74 0 ▶ last if($obj == $self->root);
Branch: 1 branch
BranchTrueFalseTotal
if $obj == $self->root 0 0 0
75 }
76  
77 0 return $i;
78 }
79  
80 =head2 children
81  
82 Holds a list of possible child objects as objects. This list is used
83 when L</parse> or L</generate_config_from_children> is called.
84 The child list has a default value set from L</create_children> in each
85 of the config modules. This is a static list, which reflects the actual
86 documentation from C<dhcpd.conf(5)>. Example:
87  
88 package Net::ISC::DHCPd::Config::Foo;
89 __PACKAGE__->create_children("Net::ISC::DHCPd::Config::Host");
90  
91 package main;
92 $config = Net::ISC::DHCPd::Config::Foo->new;
93 $config->add_host({ ... });
94 @host_objects = $config->find_hosts({ ... });
95 $config->remove_host({ ... });
96 @host_objects = $config->hosts;
97  
98 The L</create_children> method will autogenerate three methods and an
99 attribute. The name of the attribute and methods will be the last part
100 of the config class, with "s" at the end in some cases.
101  
102 =over 4
103  
104 =item foos
105  
106 C<foos> is the name the attribute as well as the accessor. The accessor
107 will auto-deref the array-ref to a list if called in list context. (yes:
108 be aware of this!).
109  
110 =item add_foo
111  
112 Instead of pushing values directly to the C<foos> list, an C<add_foo>
113 method is available. It can take either a hash, hash-ref or an object
114 to add/construct a new child.
115  
116 =item find_foos
117  
118 This method will return zero or more objects as a list. It takes
119 a hash-ref which will be matched against the object attributes of
120 the children.
121  
122 =item remove_foo
123  
124 This method will remove zero or more children from the C<foos> attribute.
125 The method takes a hash-ref which will be used to match against the
126 child list. It returns the number of child nodes actually matched and
127 removed.
128  
129 =back
130  
131 =cut
132  
133 # should be overridden by anything that has children
134 ▶sub children { }
Subroutine children: called CC=1 SCAR=0.0
Pod documented
135  
136 # actual children
137 has _children => (
138 is => 'ro',
139 isa => 'ArrayRef',
140 294 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
141 26 );
142  
143 =head2 comments
144  
145 @str = $self->comments;
146  
147 Will return all the comments before this element appeared in the config file.
148 The comments will not contain leading hash symbol spaces, nor trailing newline.
149  
150 =cut
151  
152 has _comments => (
153 is => 'ro',
154 traits => ['Array'],
155 init_arg => 'comments',
156 40 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
157 26 handles => {
158 comments => 'elements',
159 },
160 );
161  
162 =head2 regex
163  
164 Regex used to scan a line of config text, which then spawns an
165 a new node to the config tree. This is used inside l</parse>.
166  
167 THIS IS A STATIC METHOD. SELF is not used.
168  
169 =cut
170  
171 26 has _filehandle => (
172 is => 'ro',
173 lazy_build => 1,
174 );
175  
176 sub _build__filehandle {
177 19 ▶ my $self = shift;
Subroutine _build__filehandle: called CC=5 SCAR=17.6
178 19 my $file;
179  
180 # get filehandle from parent to prevent seeking file from beginning
181 19 ▶ if(my $parent = $self->parent) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $parent = $self->parent) 0 19 19
182 0 return $parent->_filehandle;
183 }
184  
185 19 ▶ if ($self->fh) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->fh) 17 2 19
186 17 return $self->fh;
187 }
188  
189 2 $file = $self->file;
190  
191 2 ▶ if($file->is_relative and !-e $file) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file->is_relative and not -e $file) 0 2 2
Condition33%1/3
$file->is_relative and not -e $file
!ll&&!rl&&r
020
MC/DC0%0/2
$file->is_relative and not -e $file
$file->is_relative not -e $file
Truth table33%1/3
A and not(B)
A= $file->is_relativeB= not -e $file
ABresult
0X0
100
111
192 0 $file = Path::Class::File->new($self->root->file->dir, $file);
193 }
194  
195 2 return $file->openr;
196 }
197  
198 =head2 filename_callback
199  
200 Callback for changing file paths when include files are on different relative paths.
201  
202 # here is an example:
203 my $cb = sub {
204 my $file = shift;
205 print "We're in callback and file is $file\n";
206 if ($file =~ /catphotos/) {
207 return "/dog.conf";
208 }
209 };
210  
211 =cut
212  
213 26 has filename_callback => (
214 is => 'rw',
215 isa => 'CodeRef',
216 );
217  
218  
219 =head1 METHODS
220  
221 =head2 BUILD
222  
223 Used to convert input arguments to child nodes.
224  
225 =cut
226  
227 sub BUILD {
228 294 ▶ my($self, $args) = @_;
Subroutine BUILD: called CC=6 SCAR=17.9
Pod documented
229 # skip the expensive method check if called through the parser. The only
230 # time this code applies is with code like add_method( submethod => { } );
231 294 ▶ return if ($args->{'parse'});
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"parse"} 254 40 294
232 40 my $meta = $self->meta;
233  
234 40 for my $key (sort keys %$args) {
235 86 my $list = $args->{$key};
236 86 my $method = "add_$key";
237 86 $method =~ s/s$//;
238 86 ▶ if(ref $list eq 'ARRAY' and $meta->has_method($method)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $list eq "ARRAY" and $meta->has_method($method)) 7 79 86
Condition66%2/3
ref $list eq "ARRAY" and $meta->has_method($method)
!ll&&!rl&&r
7907
MC/DC50%1/2
ref $list eq "ARRAY" and $meta->has_method($method)
ref $list eq "ARRAY" $meta->has_method($method)
Truth table66%2/3
A and B
A= ref $list eq "ARRAY"B= $meta->has_method($method)
ABresult
0X0
100
111
239 7 for my $element (@$list) {
240 7 $self->$method($element);
241 }
242 }
243 }
244 }
245  
246 =head2 parse
247  
248 Will read a line of the time from the current config
249 L<file|Net::ISC::DHCPd::Config::Root/file>. For each line, this method
250 will loop though each object in L</children> and try to match the line
251 against a given child and create a new node in the object graph if it
252 match the L</regex>. This method is called recursively for each child
253 when possible.
254  
255 =cut
256  
257 sub parse {
258 101 ▶ my $self = shift;
Subroutine parse: called CC=17 SCAR=28.4
Pod documented
259 101 my $fh = $_[1];
260 101 my $linebuf = $_[2];
261 101 my($n, @comments);
262 101 my $lines;
263 101 my $line_from_array=0;
264 # if $fh is a File::Temp or IO::File object then comparing on assignment
265 # above makes it convert to a number (refaddr), which takes 4µs/call
266 101 ▶ if (!defined($fh)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $fh) 24 77 101
267 24 $fh = $self->_filehandle;
268 }
269  
270 LINE:
271 101 while(1) {
272 465 my $line;
273 465 ▶ if (defined($linebuf->[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $linebuf->[0]) { } 46 419 465
274 46 $line = pop(@{$linebuf});
275 46 $line_from_array=1;
276 } else {
277 419 ▶ defined($line = readline $fh) or last LINE;
Branch: 1 branch
BranchTrueFalseTotal
defined($line = readline $fh) or last LINE 24 395 419
278 395 $n++;
279 395 chomp $line;
280 395 $line_from_array=0;
281 # From here we need to preprocess the line to see if it can be broken
282 # into multiple lines. Something like group { option test; }
283 # lines with comments can't be handled by this so we do them first
284 395 ▶ if($line =~ /^\s*\#\s*(.*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*\#\s*(.*)/) 26 369 395
285 26 push @comments, $1;
286 26 next LINE;
287 }
288  
289 # after semicolon or braces if there isn't a semicolon or return insert a newline
290 369 ▶ if ($line =~ s/([;\{\}])([^;\n\r])/$1\n$2/g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ s/([;\{\}])([^;\n\r])/$1\n$2/g) 13 356 369
291 13 push(@{$linebuf}, reverse split(/\n/, $line));
292 13 next LINE;
293 }
294 }
295  
296  
297 402 ▶ if ($line =~ /^(?:\s*|\s*\{\s*)$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($line =~ /^(?:\s*|\s*\{\s*)$/) { } 52 350 402
elsif ($line =~ /^\s*\}\s*$/) { } 77 273 350
298 52 next LINE;
299 }
300 elsif($line =~ /^\s*\}\s*$/) {
301 77 ▶ next LINE if($self->root == $self);
Branch: 1 branch
BranchTrueFalseTotal
if $self->root == $self 0 77 77
302 77 last LINE;
303 }
304  
305 # this is how we handle incomplete lines
306 # we need a space for lines like 'option\ndomain-name-servers'
307 273 ▶ if ($lines) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lines) { } 19 254 273
308 19 $lines .= ' '.$line;
309 } else {
310 254 $lines = $line;
311 }
312  
313 CHILD:
314 273 for my $child ($self->children) {
315 26 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
316 1867 my $regex = ${"$child".'::regex'};
317 1867 ▶ my @c = $lines =~ $regex or next CHILD;
Branch: 1 branch
BranchTrueFalseTotal
my(@c) = $lines =~ /$regex/ or next CHILD 1613 254 1867
318 254 my $add = 'add_' .lc +($child =~ /::(\w+)$/)[0];
319 254 my $method = $child->can('captured_to_args');
320 254 my $args = $method->(@c);
321 254 my $obj;
322  
323 254 $args->{'comments'} = [@comments];
324 254 $args->{'parse'} = 1;
325 254 @comments = ();
326 254 undef $lines;
327 254 $obj = $self->$add($args);
328 254 ▶ $n += $obj->_parse_slurp($fh, $linebuf) if ($obj->can('slurp'));
Branch: 1 branch
BranchTrueFalseTotal
if $obj->can("slurp") 7 247 254
329  
330 # the recursive statement is used for Include.pm
331 254 ▶ $n += $obj->parse('recursive', $fh, $linebuf) if(@_ = $obj->children);
Branch: 1 branch
BranchTrueFalseTotal
if @_ = $obj->children 82 172 254
332  
333 254 next LINE;
334 }
335  
336 # if we get here that means our parse failed. If the incoming line
337 # doesn't have a semicolon then we can guess it's a partial line and
338 # append the next line to it.
339 # we could do this with Slurp but then everything would need to
340 # support slurp and odd semicolon handling. If we figure out a way to
341 # merge the lines then the normal parser should be able to cover it.
342 19 ▶ if ($lines !~ /;/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($lines =~ /;/) 19 0 19
343 19 next LINE;
344 }
345  
346 0 ▶ if(warnings::enabled('net_isc_dhcpd_config_parse')) {
Branch: 1 branch
BranchTrueFalseTotal
if (warnings::enabled("net_isc_dhcpd_config_parse")) 0 0 0
347 0 warn sprintf qq[Could not parse "%s" at %s line %s\n],
348 $line,
349 $self->root->file,
350 $fh->input_line_number
351 ;
352 }
353 }
354  
355 101 ▶ return $n ? $n : '0e0';
Branch: 1 branch
BranchTrueFalseTotal
$n ? : 93 8 101
356 }
357  
358 =head2 _parse_slurp
359  
360 This is a simplified parser for the slurp method. It's only used when slurp
361 is available in a child method.
362  
363 =cut
364  
365  
366 sub _parse_slurp {
367 7 ▶ my $self = shift;
Subroutine _parse_slurp: called CC=7 SCAR=21.8
368 7 my $fh = shift;
369 7 my $linebuf = shift;
370 7 my($n, @comments);
371  
372 LINE:
373 7 while(1) {
374 35 my $line;
375 35 ▶ if (defined($linebuf->[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $linebuf->[0]) { } 0 35 35
376 0 $line = pop(@{$linebuf});
377 } else {
378 35 ▶ defined($line = readline $fh) or last LINE;
Branch: 1 branch
BranchTrueFalseTotal
defined($line = readline $fh) or last LINE 0 35 35
379 35 $n++;
380 35 chomp $line;
381 }
382  
383  
384 35 ▶ if($self->can('slurp')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->can("slurp")) 35 0 35
385 35 my $action = $self->slurp($line); # next or last
386 35 ▶ if($action eq 'next') {
Branch: 3 branches
BranchTrueFalseTotal
if ($action eq 'next') { } 28 7 35
elsif ($action eq 'last') { } 7 0 7
elsif ($action eq 'backtrack') { } 0 0 0
387 28 next LINE;
388 }
389 elsif($action eq 'last') {
390 7 last LINE;
391 }
392 elsif($action eq 'backtrack') {
393 0 push(@{$linebuf}, $line);
394 0 last LINE;
395 }
396 }
397 }
398 7 return $n;
399 }
400  
401 =head2 captured_to_args
402  
403 $hash_ref = $self->captured_to_args(@list);
404  
405 Called when a L</regex> matches, with a list of captured strings.
406 This method then returns a hash-ref passed on to the constructor when
407 a new node in the object graph is constructed.
408  
409 THIS IS A STATIC METHOD. SELF is not used.
410  
411 =cut
412  
413 sub captured_to_args {
414 11 ▶ return {};
Subroutine captured_to_args: called CC=1 SCAR=0.0
Pod documented
415 }
416  
417 =head2 create_children
418  
419 This method takes a list of classes, and creates builder method for
420 the L</children> attribute, an attribute and helper methods. See
421 L</children> for more details.
422  
423 =cut
424  
425 sub create_children {
426 286 ▶ my $self = shift;
Subroutine create_children: called CC=4 SCAR=14.1
Pod documented
427 286 my $meta = $self->meta;
428 286 my @children = @_;
429  
430 286 for my $class (@children) {
431 2678 my $name = lc (($class =~ /::(\w+)$/)[0]);
432 2678 my $attr = $name .'s';
433  
434 # hack so the child method for class is classes instead of classs
435 2678 ▶ $attr = $name . 'es' if ($name =~ /s$/);
Branch: 1 branch
BranchTrueFalseTotal
if $name =~ /s$/ 234 2444 2678
436  
437  
438 2678 Class::Load::load_class($class);
439  
440 2678 ▶ unless($meta->find_method_by_name($attr)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($meta->find_method_by_name($attr)) 2678 0 2678
441 2678 ▶ $meta->add_method("add_${name}" => sub { shift->_add_child($class, @_) });
Subroutine add_subnet6: not called CC=1 SCAR=0.4
Subroutine add_zone: called CC=1 SCAR=0.4
442 2678 ▶ $meta->add_method("find_${attr}" => sub { shift->_find_children($class, @_) });
Subroutine find_conditionals: not called CC=1 SCAR=0.4
Subroutine find_keyvalues: called CC=1 SCAR=0.4
443 2678 ▶ $meta->add_method("remove_${attr}" => sub { shift->_remove_children($class, @_) });
Subroutine remove_groups: not called CC=1 SCAR=0.4
Subroutine remove_subclasses: called CC=1 SCAR=0.4
444 $meta->add_method($attr => sub {
445 14 ▶ my $self = shift;
Subroutine groups: called CC=2 SCAR=7.1
Subroutine subclasses: called CC=2 SCAR=7.1
446 14 ▶ return $self->_set_children($class, @_) if(@_);
Branch: 2 branches
BranchTrueFalseTotal
if @_ 0 14 14
if @_ 0 143 143
447 14 return $self->_get_children_by_class($class);
448 2678 });
449 }
450 }
451  
452 286 return \@children;
453 }
454  
455 sub _set_children {
456 0 ▶ my($self, $attr, $class, $children) = @_;
Subroutine _set_children: not called CC=3 SCAR=24.8
457  
458 0 for my $child (@$children) {
459 0 ▶ $child = $class->new(parent => $self, root => $self->root, %$child) if(ref $child eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
if ref $child eq "HASH" 0 0 0
460 }
461  
462 0 @{ $self->_children } = @$children;
463 }
464  
465 sub _get_children_by_class {
466 157 ▶ my($self, $class) = @_;
Subroutine _get_children_by_class: called CC=2 SCAR=6.9
467 157 my @children = grep { $class eq ref $_ } @{ $self->_children };
468  
469 157 ▶ return wantarray ? @children : \@children;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 25 132 157
470 }
471  
472 sub _add_child {
473 269 ▶ my $self = shift;
Subroutine _add_child: called CC=3 SCAR=11.0
474 269 my $class = shift;
475 269 ▶ my $child = @_ == 1 ? $_[0] : {@_};
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 261 8 269
476 269 my $children = $self->_children;
477  
478 269 ▶ if(ref $child eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $child eq "HASH") 269 0 269
479 269 $child = $class->new(parent => $self, root => $self->root, %$child);
480 }
481  
482 269 push @$children, $child;
483 269 return $child;
484 }
485  
486 sub _find_children {
487 3 ▶ my($self, $class, $query) = @_;
Subroutine _find_children: called CC=6 SCAR=18.0
488 3 my @children;
489  
490 3 ▶ if(ref $query ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $query ne "HASH") 0 3 3
491 0 return;
492 }
493  
494 CHILD:
495 3 for my $child (@{ $self->_children }) {
496 38 ▶ if($class ne ref $child) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class ne ref $child) 36 2 38
497 36 next CHILD;
498 }
499 2 for my $key (keys %$query) {
500 2 ▶ next CHILD unless($child->$key eq $query->{$key});
Branch: 1 branch
BranchTrueFalseTotal
unless $child->$key eq $query->{$key} 1 1 2
501 }
502 1 push @children, $child;
503 }
504  
505 3 return @children;
506 }
507  
508 sub _remove_children {
509 10 ▶ my $self = shift;
Subroutine _remove_children: called CC=6 SCAR=17.9
510 10 my $class = shift;
511 10 ▶ my $query = shift or return;
Branch: 1 branch
BranchTrueFalseTotal
my $query = shift() or return 0 10 10
512 10 my $children = $self->_children;
513 10 my $i = 0;
514 10 my @removed;
515  
516 CHILD:
517 10 ▶ while($i < @$children) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$children) 72 10 82
518 72 ▶ if($class ne ref $children->[$i]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class ne ref $children->[$i]) 57 15 72
519 57 next CHILD;
520 }
521 15 for my $key (keys %$query) {
522 13 ▶ next CHILD unless($children->[$i]->$key eq $query->{$key});
Branch: 1 branch
BranchTrueFalseTotal
unless $children->[$i]->$key eq $query->{$key} 4 9 13
523 }
524 11 push @removed, splice @$children, $i, 1;
525 11 $i--;
526 } continue {
527 72 $i++;
528 }
529  
530 10 return @removed;
531 }
532  
533  
534 =head2 find_all_children
535  
536 Loops through all child nodes with recursion looking for nodes of "class"
537 type. Returns an array of those nodes. You can use the full classname or
538 just the end part. For subclasses like Host::FixedAddress you would need to
539 use the whole name.
540  
541 my @subnet = $config->find_all_children('subnet');
542  
543 =cut
544  
545 sub find_all_children {
546 7 ▶ my $self = shift;
Subroutine find_all_children: called CC=5 SCAR=16.1
Pod documented
547 7 my $class = shift;
548 7 my @children;
549  
550 7 ▶ if ($class !~ /::/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class =~ /::/) 1 6 7
551 # strip plural if they put it.
552 1 $class =~ s/s\z//;
553 1 $class =~ s/(class|address)e/$1/;
554 1 $class = 'Net::ISC::DHCPd::Config::' . ucfirst(lc($class));
555 }
556  
557 7 for my $child (@{ $self->_children }) {
558 6 ▶ if (ref($child) eq $class) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $child eq $class) 3 3 6
559 3 push(@children, $child);
560 }
561  
562 6 ▶ if ($child->_children) {
Branch: 1 branch
BranchTrueFalseTotal
if ($child->_children) 6 0 6
563 6 push(@children, $child->find_all_children($class));
564 }
565 }
566 7 return @children;
567 }
568  
569 =head2 generate_config_from_children
570  
571 Loops all child nodes in reverse order and calls L</generate> on each
572 of them. Each L</generate> method must return a list of strings which
573 will be indented correctly and concatenated with newline inside this
574 method, before returned as one string.
575  
576 =cut
577  
578 sub generate_config_from_children {
579 26 ▶ return join "\n", shift->_generate_config_from_children;
Subroutine generate_config_from_children: called CC=1 SCAR=0.0
Pod documented
580 }
581  
582 sub _generate_config_from_children {
583 49 ▶ my $self = shift;
Subroutine _generate_config_from_children: called CC=4 SCAR=13.9
584 49 my $indent = '';
585 49 my @text;
586  
587 49 ▶ if($self->parent and !$self->can('generate_with_include')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->parent and not $self->can("generate_with_include")) 30 19 49
Condition100%3/3
$self->parent and not $self->can("generate_with_include")
!ll&&!rl&&r
17230
MC/DC100%2/2
$self->parent and not $self->can("generate_with_include")
$self->parent not $self->can("generate_with_include")
Truth table100%3/3
A and not(B)
A= $self->parentB= not $self->can("generate_with_include")
ABresult
0X0
100
111
588 30 $indent = ' ' x 4;
589 }
590  
591 49 for my $child (@{ $self->_children }) {
592 112 push @text, map { "$indent# $_" } $child->comments;
593 112 push @text, map { "$indent$_" } $child->generate;
594 }
595  
596 49 return @text;
597 }
598  
599 =head2 generate
600  
601 A C<generate()> must be defined in the consuming class. This method
602 must return a list of lines (zero or more), which will be indented
603 and concatenated inside L</generate_config_from_children>.
604  
605 =head1 COPYRIGHT & LICENSE
606  
607 =head1 AUTHOR
608  
609 See L<Net::ISC::DHCPd>.
610  
611 =cut
612  
613 package # hack to register a new warnings category
614 net_isc_dhcpd_config_parse;
615 26 ▶use warnings::register;
Subroutine BEGIN: called CC=1 SCAR=0.0
616  
617 26 1;
« blib/lib/Net/ISC/DHCPd/OMAPI.pm ↑ Summary blib/lib/Net/ISC/DHCPd/Config/Key.pm »