| 1 | package Net::ISC::DHCPd::Config::Option; | ||||||||||
| 2 | |||||||||||
| 3 | =head1 NAME | ||||||||||
| 4 | |||||||||||
| 5 | Net::ISC::DHCPd::Config::Option - Option config parameter | ||||||||||
| 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 $name_attribute_value "$value_attribute_value"; | ||||||||||
| 16 | option $name_attribute_value $value_attribute_value; | ||||||||||
| 17 | |||||||||||
| 18 | =head1 SYNOPSIS | ||||||||||
| 19 | |||||||||||
| 20 | See L<Net::ISC::DHCPd::Config/SYNOPSIS>. | ||||||||||
| 21 | |||||||||||
| 22 | =cut | ||||||||||
| 23 | |||||||||||
| 24 | 27 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 25 | |||||||||||
| 26 | 27 | with 'Net::ISC::DHCPd::Config::Role'; | |||||||||
| 27 | |||||||||||
| 28 | =head1 ATTRIBUTES | ||||||||||
| 29 | |||||||||||
| 30 | =head2 name | ||||||||||
| 31 | |||||||||||
| 32 | A plain string representing the name of the option. | ||||||||||
| 33 | |||||||||||
| 34 | =cut | ||||||||||
| 35 | |||||||||||
| 36 | 27 | has name => ( | |||||||||
| 37 | is => 'ro', | ||||||||||
| 38 | isa => 'Str', | ||||||||||
| 39 | ); | ||||||||||
| 40 | |||||||||||
| 41 | =head2 value | ||||||||||
| 42 | |||||||||||
| 43 | A plain string representing the value of the option. | ||||||||||
| 44 | |||||||||||
| 45 | =cut | ||||||||||
| 46 | |||||||||||
| 47 | 27 | has value => ( | |||||||||
| 48 | is => 'ro', | ||||||||||
| 49 | isa => 'Str', | ||||||||||
| 50 | ); | ||||||||||
| 51 | |||||||||||
| 52 | =head2 quoted | ||||||||||
| 53 | |||||||||||
| 54 | This flag tells if the option value should be quoted or not. | ||||||||||
| 55 | |||||||||||
| 56 | =cut | ||||||||||
| 57 | |||||||||||
| 58 | 27 | has quoted => ( | |||||||||
| 59 | is => 'ro', | ||||||||||
| 60 | isa => 'Bool', | ||||||||||
| 61 | ); | ||||||||||
| 62 | |||||||||||
| 63 | =head2 regex | ||||||||||
| 64 | |||||||||||
| 65 | See L<Net::ISC::DHCPd::Config::Role/regex>. | ||||||||||
| 66 | |||||||||||
| 67 | =cut | ||||||||||
| 68 | |||||||||||
| 69 | 27 | our $regex = qr{^\s* option \s+ (\S+) \s+ (.*) ;}x; | |||||||||
| 70 | |||||||||||
| 71 | =head1 METHODS | ||||||||||
| 72 | |||||||||||
| 73 | =head2 captured_to_args | ||||||||||
| 74 | |||||||||||
| 75 | See L<Net::ISC::DHCPd::Config::Role/captured_to_args>. | ||||||||||
| 76 | |||||||||||
| 77 | =cut | ||||||||||
| 78 | |||||||||||
| 79 | 45 | ▶ | sub captured_to_args { | ||||||||
|
Subroutine
captured_to_args: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 80 | 45 | my $name = shift; | |||||||||
| 81 | 45 | my $value = shift; | |||||||||
| 82 | 45 | my $quoted = 0; | |||||||||
| 83 | |||||||||||
| 84 | 45 | ▶ | $quoted = 1 if($value =~ s/^"(.*)"$/$1/g); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 85 | |||||||||||
| 86 | return { | ||||||||||
| 87 | 45 | name => $name, | |||||||||
| 88 | value => $value, | ||||||||||
| 89 | quoted => $quoted, | ||||||||||
| 90 | }; | ||||||||||
| 91 | } | ||||||||||
| 92 | |||||||||||
| 93 | =head2 generate | ||||||||||
| 94 | |||||||||||
| 95 | See L<Net::ISC::DHCPd::Config::Role/generate>. | ||||||||||
| 96 | |||||||||||
| 97 | =cut | ||||||||||
| 98 | |||||||||||
| 99 | 20 | ▶ | sub generate { | ||||||||
|
Subroutine
generate: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 100 | 20 | my $self = shift; | |||||||||
| 101 | 20 | ▶ | my $format = $self->quoted ? qq(option %s "%s";) : qq(option %s %s;); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 102 | |||||||||||
| 103 | 20 | return sprintf $format, $self->name, $self->value; | |||||||||
| 104 | } | ||||||||||
| 105 | |||||||||||
| 106 | =head1 COPYRIGHT & LICENSE | ||||||||||
| 107 | |||||||||||
| 108 | =head1 AUTHOR | ||||||||||
| 109 | |||||||||||
| 110 | See L<Net::ISC::DHCPd>. | ||||||||||
| 111 | |||||||||||
| 112 | =cut | ||||||||||
| 113 | 27 | __PACKAGE__->meta->make_immutable; | |||||||||
| 114 | 27 | 1; | |||||||||