| 1 | package Net::ISC::DHCPd::Config::Key; | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | Net::ISC::DHCPd::Config::Key - Server key | ||
| 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 the block below: | ||
| 13 | |||
| 14 | $name_attribute_value $value_attribute_value; | ||
| 15 | |||
| 16 | key "$name" { | ||
| 17 | algorithm $algorithm; | ||
| 18 | secret "$secret"; | ||
| 19 | }; | ||
| 20 | |||
| 21 | =head1 SYNOPSIS | ||
| 22 | |||
| 23 | See L<Net::ISC::DHCPd::Config/SYNOPSIS>. | ||
| 24 | |||
| 25 | =cut | ||
| 26 | |||
| 27 | use Moose; | ||
| 28 | |||
| 29 | with 'Net::ISC::DHCPd::Config::Role'; | ||
| 30 | |||
| 31 | =head1 ATTRIBUTES | ||
| 32 | |||
| 33 | =head2 quoted | ||
| 34 | |||
| 35 | This flag tells if the group name should be quoted or not. | ||
| 36 | |||
| 37 | =cut | ||
| 38 | |||
| 39 | has quoted => ( | ||
| 40 | is => 'ro', | ||
| 41 | isa => 'Bool', | ||
| 42 | ); | ||
| 43 | |||
| 44 | =head2 name | ||
| 45 | |||
| 46 | Name of the key - See L</DESCRIPTION> for details. | ||
| 47 | |||
| 48 | =head2 algorithm | ||
| 49 | |||
| 50 | =head2 secret | ||
| 51 | |||
| 52 | =cut | ||
| 53 | |||
| 54 | has [qw/ name algorithm secret /] => ( | ||
| 55 | is => 'rw', # TODO: WILL PROBABLY CHANGE! | ||
| 56 | isa => 'Str', | ||
| 57 | ); | ||
| 58 | |||
| 59 | =head2 regex | ||
| 60 | |||
| 61 | See L<Net::ISC::DHCPd::Config::Role/regex>. | ||
| 62 | |||
| 63 | =cut | ||
| 64 | |||
| 65 | our $regex = qr{^\s* key \s+ ([\w-]+|".*?") }x; | ||
| 66 | |||
| 67 | =head1 METHODS | ||
| 68 | |||
| 69 | =head2 slurp | ||
| 70 | |||
| 71 | This method is used by L<Net::ISC::DHCPd::Config::Role/parse>, and will | ||
| 72 | slurp the content of the function, instead of trying to parse the | ||
| 73 | statements. | ||
| 74 | |||
| 75 | =cut | ||
| 76 | |||
| 77 | sub slurp { | ||
| 78 | my($self, $line) = @_; | ||
| 79 | |||
| 80 | return 'last' if($line =~ /^\s*}/); | ||
| 81 | $self->algorithm($1) if($line =~ /algorithm \s+ (\S+);/x); | ||
| 82 | $self->secret($2) if($line =~ /secret \s+ ("?)(\S+)\1;/x); | ||
| 83 | return 'next'; | ||
| 84 | } | ||
| 85 | |||
| 86 | =head2 captured_to_args | ||
| 87 | |||
| 88 | See L<Net::ISC::DHCPd::Config::Role/captured_to_args>. | ||
| 89 | |||
| 90 | =cut | ||
| 91 | |||
| 92 | sub captured_to_args { | ||
| 93 | my $value = shift; | ||
| 94 | my $quoted = 0; | ||
| 95 | $quoted = 1 if($value =~ s/^"(.*)"$/$1/g); | ||
| 96 | return { quoted => $quoted, name => $value }; | ||
| 97 | } | ||
| 98 | |||
| 99 | =head2 generate | ||
| 100 | |||
| 101 | See L<Net::ISC::DHCPd::Config::Role/generate>. | ||
| 102 | |||
| 103 | =cut | ||
| 104 | |||
| 105 | sub generate { | ||
| 106 | my $self = shift; | ||
| 107 | my $name = $self->name; | ||
| 108 | |||
| 109 | return( | ||
| 110 | sprintf('key '. ($self->quoted ? qq("$name") : $name). ' {'), | ||
| 111 | $self->algorithm ? (sprintf ' algorithm %s;', $self->algorithm) : (), | ||
| 112 | $self->secret ? (sprintf ' secret "%s";', $self->secret) : (), | ||
| 113 | '};', # semicolon is for compatibility with bind key files | ||
| 114 | ); | ||
| 115 | } | ||
| 116 | |||
| 117 | =head1 COPYRIGHT & LICENSE | ||
| 118 | |||
| 119 | =head1 AUTHOR | ||
| 120 | |||
| 121 | See L<Net::ISC::DHCPd>. | ||
| 122 | |||
| 123 | =cut | ||
| 124 | __PACKAGE__->meta->make_immutable; | ||
| 125 | 1; |