| 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 | use Moose; | ||
| 36 | |||
| 37 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | sub captured_to_args { | ||
| 112 | my $name = shift; | ||
| 113 | my $code = shift; | ||
| 114 | my $value = shift; | ||
| 115 | my %values; | ||
| 116 | my $quoted = 0; | ||
| 117 | if ($name =~ /(\S+)\.(\S+)/) { | ||
| 118 | $name = $2; | ||
| 119 | $values{prefix} = $1; | ||
| 120 | } | ||
| 121 | |||
| 122 | $quoted = 1 if($value =~ s/^"(.*)"$/$1/g); | ||
| 123 | |||
| 124 | return { | ||
| 125 | %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 | sub generate { | ||
| 140 | my $self = shift; | ||
| 141 | |||
| 142 | if (defined($self->prefix)) { | ||
| 143 | return sprintf('option %s.%s code %i = %s;', | ||
| 144 | $self->prefix, | ||
| 145 | $self->name, | ||
| 146 | $self->code, | ||
| 147 | $self->value, | ||
| 148 | ); | ||
| 149 | } else { | ||
| 150 | 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 | 1; |