| 1 | package Net::ISC::DHCPd::Config::OptionCode; | ||||||||||
| 2 | |||||||||||
| 3 | =head1 NAME | ||||||||||
| 4 | |||||||||||
| 5 | Net::ISC::DHCPd::Config::OptionCode - Optionspace config param data | ||||||||||
| 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 one of the | ||||||||||
| 13 | lines below, dependent on L</quoted>. | ||||||||||
| 14 | |||||||||||
| 15 | option $prefix_attribute_value.$name_attribute_value \ | ||||||||||
| 16 | code $code_attribute_value = $value_attribute_value; | ||||||||||
| 17 | |||||||||||
| 18 | option $prefix_attribute_value.$name_attribute_value \ | ||||||||||
| 19 | code $code_attribute_value = "$value_attribute_value"; | ||||||||||
| 20 | |||||||||||
| 21 | This used to be under OptionSpace, but they can actually be seperated in | ||||||||||
| 22 | dhcpd.conf files, which means they need to be parsed seperately. This | ||||||||||
| 23 | actually makes the parsing easier because they're treated as individual lines. | ||||||||||
| 24 | |||||||||||
| 25 | There is no real difference between these and normal options, but I'm leaving | ||||||||||
| 26 | them seperate in the parser to keep things easy. | ||||||||||
| 27 | |||||||||||
| 28 | |||||||||||
| 29 | =head1 SYNOPSIS | ||||||||||
| 30 | |||||||||||
| 31 | See L<Net::ISC::DHCPd::Config> for synopsis. | ||||||||||
| 32 | |||||||||||
| 33 | =cut | ||||||||||
| 34 | |||||||||||
| 35 | 27 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 36 | |||||||||||
| 37 | 27 | with 'Net::ISC::DHCPd::Config::Role'; | |||||||||
| 38 | |||||||||||
| 39 | =head1 ATTRIBUTES | ||||||||||
| 40 | |||||||||||
| 41 | =head2 prefix | ||||||||||
| 42 | |||||||||||
| 43 | Human readable prefix of this option. This is the parent of the option. | ||||||||||
| 44 | |||||||||||
| 45 | =cut | ||||||||||
| 46 | |||||||||||
| 47 | 27 | has prefix => ( | |||||||||
| 48 | is => 'ro', | ||||||||||
| 49 | isa => 'Str', | ||||||||||
| 50 | ); | ||||||||||
| 51 | |||||||||||
| 52 | =head2 name | ||||||||||
| 53 | |||||||||||
| 54 | Human readable name of this option, without parent name prefix | ||||||||||
| 55 | |||||||||||
| 56 | =cut | ||||||||||
| 57 | |||||||||||
| 58 | 27 | has name => ( | |||||||||
| 59 | is => 'ro', | ||||||||||
| 60 | isa => 'Str', | ||||||||||
| 61 | ); | ||||||||||
| 62 | |||||||||||
| 63 | =head2 code | ||||||||||
| 64 | |||||||||||
| 65 | Computer readable code for this option. | ||||||||||
| 66 | |||||||||||
| 67 | =cut | ||||||||||
| 68 | |||||||||||
| 69 | 27 | has code => ( | |||||||||
| 70 | is => 'ro', | ||||||||||
| 71 | isa => 'Int', | ||||||||||
| 72 | ); | ||||||||||
| 73 | |||||||||||
| 74 | =head2 value | ||||||||||
| 75 | |||||||||||
| 76 | Value of the option, as a string. | ||||||||||
| 77 | |||||||||||
| 78 | =cut | ||||||||||
| 79 | |||||||||||
| 80 | 27 | has value => ( | |||||||||
| 81 | is => 'ro', | ||||||||||
| 82 | isa => 'Str', | ||||||||||
| 83 | ); | ||||||||||
| 84 | |||||||||||
| 85 | =head2 quoted | ||||||||||
| 86 | |||||||||||
| 87 | This flag tells if the option value should be quoted or not. | ||||||||||
| 88 | |||||||||||
| 89 | =cut | ||||||||||
| 90 | |||||||||||
| 91 | 27 | has quoted => ( | |||||||||
| 92 | is => 'ro', | ||||||||||
| 93 | isa => 'Bool', | ||||||||||
| 94 | ); | ||||||||||
| 95 | |||||||||||
| 96 | =head2 regex | ||||||||||
| 97 | |||||||||||
| 98 | See L<Net::ISC::DHCPd::Config::Role/regex>. | ||||||||||
| 99 | |||||||||||
| 100 | =cut | ||||||||||
| 101 | 27 | our $regex = qr{^\s* option \s+ (\S+) \s+ code \s+ (\d+) \s+ = \s+ (.*) ;}x; | |||||||||
| 102 | |||||||||||
| 103 | =head1 METHODS | ||||||||||
| 104 | |||||||||||
| 105 | =head2 captured_to_args | ||||||||||
| 106 | |||||||||||
| 107 | See L<Net::ISC::DHCPd::Config::Role/captured_to_args>. | ||||||||||
| 108 | |||||||||||
| 109 | =cut | ||||||||||
| 110 | |||||||||||
| 111 | 12 | ▶ | sub captured_to_args { | ||||||||
|
Subroutine
captured_to_args: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 112 | 12 | my $name = shift; | |||||||||
| 113 | 12 | my $code = shift; | |||||||||
| 114 | 12 | my $value = shift; | |||||||||
| 115 | 12 | my %values; | |||||||||
| 116 | 12 | my $quoted = 0; | |||||||||
| 117 | 12 | ▶ | if ($name =~ /(\S+)\.(\S+)/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 118 | 8 | $name = $2; | |||||||||
| 119 | 8 | $values{prefix} = $1; | |||||||||
| 120 | } | ||||||||||
| 121 | |||||||||||
| 122 | 12 | ▶ | $quoted = 1 if($value =~ s/^"(.*)"$/$1/g); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 123 | |||||||||||
| 124 | return { | ||||||||||
| 125 | 12 | %values, | |||||||||
| 126 | name => $name, | ||||||||||
| 127 | code => $code, | ||||||||||
| 128 | value => $value, | ||||||||||
| 129 | quoted => $quoted, | ||||||||||
| 130 | }; | ||||||||||
| 131 | } | ||||||||||
| 132 | |||||||||||
| 133 | =head2 generate | ||||||||||
| 134 | |||||||||||
| 135 | See L<Net::ISC::DHCPd::Config::Role/generate>. | ||||||||||
| 136 | |||||||||||
| 137 | =cut | ||||||||||
| 138 | |||||||||||
| 139 | 6 | ▶ | sub generate { | ||||||||
|
Subroutine
generate: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 140 | 6 | my $self = shift; | |||||||||
| 141 | |||||||||||
| 142 | 6 | ▶ | if (defined($self->prefix)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 143 | 3 | return sprintf('option %s.%s code %i = %s;', | |||||||||
| 144 | $self->prefix, | ||||||||||
| 145 | $self->name, | ||||||||||
| 146 | $self->code, | ||||||||||
| 147 | $self->value, | ||||||||||
| 148 | ); | ||||||||||
| 149 | } else { | ||||||||||
| 150 | 3 | return sprintf('option %s code %i = %s;', | |||||||||
| 151 | $self->name, | ||||||||||
| 152 | $self->code, | ||||||||||
| 153 | $self->value, | ||||||||||
| 154 | ); | ||||||||||
| 155 | } | ||||||||||
| 156 | } | ||||||||||
| 157 | |||||||||||
| 158 | =head1 COPYRIGHT & LICENSE | ||||||||||
| 159 | |||||||||||
| 160 | =head1 AUTHOR | ||||||||||
| 161 | |||||||||||
| 162 | See L<Net::ISC::DHCPd>. | ||||||||||
| 163 | |||||||||||
| 164 | =cut | ||||||||||
| 165 | |||||||||||
| 166 | 27 | 1; | |||||||||