| 1 | package Net::ISC::DHCPd::Config::Block; | ||||||||||
| 2 | |||||||||||
| 3 | =head1 NAME | ||||||||||
| 4 | |||||||||||
| 5 | Net::ISC::DHCPd::Config::Block - Unknown config blocks | ||||||||||
| 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: | ||||||||||
| 13 | |||||||||||
| 14 | $type $name { | ||||||||||
| 15 | $body_attribute_value | ||||||||||
| 16 | } | ||||||||||
| 17 | |||||||||||
| 18 | $type "$string" { | ||||||||||
| 19 | $body_attribute_value | ||||||||||
| 20 | } | ||||||||||
| 21 | |||||||||||
| 22 | IMPORTANT! "Blocks" may be redefined to a "real" instance later on. | ||||||||||
| 23 | This is simply here as a "catch-all" feature, in case something | ||||||||||
| 24 | could not be parsed. | ||||||||||
| 25 | |||||||||||
| 26 | =head1 SYNOPSIS | ||||||||||
| 27 | |||||||||||
| 28 | See L<Net::ISC::DHCPd::Config/SYNOPSIS>. | ||||||||||
| 29 | |||||||||||
| 30 | =cut | ||||||||||
| 31 | |||||||||||
| 32 | 27 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 33 | |||||||||||
| 34 | 27 | with 'Net::ISC::DHCPd::Config::Role'; | |||||||||
| 35 | |||||||||||
| 36 | =head1 ATTRIBUTES | ||||||||||
| 37 | |||||||||||
| 38 | =head2 type | ||||||||||
| 39 | |||||||||||
| 40 | See L</SYNOPSIS>. | ||||||||||
| 41 | |||||||||||
| 42 | =head2 name | ||||||||||
| 43 | |||||||||||
| 44 | See L</SYNOPSIS>. | ||||||||||
| 45 | |||||||||||
| 46 | =cut | ||||||||||
| 47 | |||||||||||
| 48 | 27 | has [qw/ type name /] => ( | |||||||||
| 49 | is => 'ro', | ||||||||||
| 50 | isa => 'Str', | ||||||||||
| 51 | ); | ||||||||||
| 52 | |||||||||||
| 53 | =head2 quoted | ||||||||||
| 54 | |||||||||||
| 55 | This flag tells if the name should be quoted or not. | ||||||||||
| 56 | |||||||||||
| 57 | =cut | ||||||||||
| 58 | |||||||||||
| 59 | 27 | has quoted => ( | |||||||||
| 60 | is => 'ro', | ||||||||||
| 61 | isa => 'Bool', | ||||||||||
| 62 | ); | ||||||||||
| 63 | |||||||||||
| 64 | =head2 body | ||||||||||
| 65 | |||||||||||
| 66 | The body of the block, without trailing newline at end. | ||||||||||
| 67 | This text is not parsed, so the containing text can be anything. | ||||||||||
| 68 | |||||||||||
| 69 | =cut | ||||||||||
| 70 | |||||||||||
| 71 | has _body => ( | ||||||||||
| 72 | is => 'rw', | ||||||||||
| 73 | isa => 'ArrayRef', | ||||||||||
| 74 | 0 | ▶ | default => sub { [] }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 75 | 27 | ); | |||||||||
| 76 | |||||||||||
| 77 | 0 | ▶ | sub body { join "\n", @{ shift->_body } } | ||||||||
|
Subroutine
body: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 78 | |||||||||||
| 79 | =head2 regex | ||||||||||
| 80 | |||||||||||
| 81 | See L<Net::ISC::DHCPd::Config::Role/regex>. | ||||||||||
| 82 | |||||||||||
| 83 | =cut | ||||||||||
| 84 | |||||||||||
| 85 | 27 | our $regex = qr/^\s* ([\w-]+) \s+ (\S*) \s* { /x; | |||||||||
| 86 | |||||||||||
| 87 | 27 | has _depth => ( | |||||||||
| 88 | is => 'ro', | ||||||||||
| 89 | isa => 'Int', | ||||||||||
| 90 | traits => ['Counter'], | ||||||||||
| 91 | default => 1, | ||||||||||
| 92 | handles => { | ||||||||||
| 93 | _inc_depth => 'inc', | ||||||||||
| 94 | _dec_depth => 'dec', | ||||||||||
| 95 | }, | ||||||||||
| 96 | ); | ||||||||||
| 97 | |||||||||||
| 98 | =head1 METHODS | ||||||||||
| 99 | |||||||||||
| 100 | =head2 BUILD | ||||||||||
| 101 | |||||||||||
| 102 | Will convert body (as string) in C<new()> into a list which is used | ||||||||||
| 103 | internally. | ||||||||||
| 104 | |||||||||||
| 105 | =cut | ||||||||||
| 106 | |||||||||||
| 107 | 0 | ▶ | sub BUILD { | ||||||||
|
Subroutine
BUILD: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 108 | 0 | my($self, $args) = @_; | |||||||||
| 109 | 0 | ▶ | push @{ $self->_body }, split /\n/, $args->{'body'} if(defined $args->{'body'}); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 110 | } | ||||||||||
| 111 | |||||||||||
| 112 | =head2 slurp | ||||||||||
| 113 | |||||||||||
| 114 | This method is used by L<Net::ISC::DHCPd::Config::Role/parse>, and will | ||||||||||
| 115 | slurp the content of the function, instead of trying to parse the | ||||||||||
| 116 | statements. | ||||||||||
| 117 | |||||||||||
| 118 | =cut | ||||||||||
| 119 | |||||||||||
| 120 | 0 | ▶ | sub slurp { | ||||||||
|
Subroutine
slurp: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 121 | 0 | my($self, $line) = @_; | |||||||||
| 122 | |||||||||||
| 123 | 0 | ▶ | $self->_inc_depth if($line =~ /{/); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 124 | 0 | ▶ | $self->_dec_depth if($line =~ /}/); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 125 | |||||||||||
| 126 | 0 | ▶ | if($self->_depth) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 127 | 0 | chomp $line; | |||||||||
| 128 | 0 | $line =~ s/^\s{4}//; | |||||||||
| 129 | 0 | push @{ $self->_body }, $line; | |||||||||
| 130 | 0 | return 'next'; | |||||||||
| 131 | } | ||||||||||
| 132 | else { | ||||||||||
| 133 | 0 | return 'last'; | |||||||||
| 134 | } | ||||||||||
| 135 | } | ||||||||||
| 136 | |||||||||||
| 137 | =head2 captured_to_args | ||||||||||
| 138 | |||||||||||
| 139 | See L<Net::ISC::DHCPd::Config::Role/captured_to_args>. | ||||||||||
| 140 | |||||||||||
| 141 | =cut | ||||||||||
| 142 | |||||||||||
| 143 | 0 | ▶ | sub captured_to_args { | ||||||||
|
Subroutine
captured_to_args: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 144 | 0 | my($type, $name) = @_; | |||||||||
| 145 | 0 | ▶ | my $quoted = $name =~ s/^"(.*)"$/$1/ ? 1 : 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 146 | |||||||||||
| 147 | 0 | return { type => $type, name => $name, quoted => $quoted } | |||||||||
| 148 | } | ||||||||||
| 149 | |||||||||||
| 150 | =head2 generate | ||||||||||
| 151 | |||||||||||
| 152 | See L<Net::ISC::DHCPd::Config::Role/generate>. | ||||||||||
| 153 | |||||||||||
| 154 | =cut | ||||||||||
| 155 | |||||||||||
| 156 | 0 | ▶ | sub generate { | ||||||||
|
Subroutine
generate: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 157 | 0 | my $self = shift; | |||||||||
| 158 | 0 | ▶ | my $format = $self->quoted ? '%s "%s" {' : '%s %s {'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 159 | |||||||||||
| 160 | return( | ||||||||||
| 161 | sprintf($format, $self->type, $self->name), | ||||||||||
| 162 | 0 | @{ $self->_body }, | |||||||||
| 163 | '}', | ||||||||||
| 164 | ); | ||||||||||
| 165 | } | ||||||||||
| 166 | |||||||||||
| 167 | =head1 COPYRIGHT & LICENSE | ||||||||||
| 168 | |||||||||||
| 169 | =head1 AUTHOR | ||||||||||
| 170 | |||||||||||
| 171 | See L<Net::ISC::DHCPd>. | ||||||||||
| 172 | |||||||||||
| 173 | =cut | ||||||||||
| 174 | |||||||||||
| 175 | 27 | __PACKAGE__->meta->make_immutable; | |||||||||
| 176 | |||||||||||
| 177 | 27 | 1; | |||||||||