| 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 | 27 | ▶ | use Moose; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 28 | |||||||||||||||||||
| 29 | 27 | 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 | 27 | 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 | 27 | 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 | 27 | 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 | 9 | ▶ | sub slurp { | ||||||||||||||||
|
Subroutine
slurp: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||
| 78 | 9 | my($self, $line) = @_; | |||||||||||||||||
| 79 | |||||||||||||||||||
| 80 | 9 | ▶ | return 'last' if($line =~ /^\s*}/); | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 81 | 6 | ▶ | $self->algorithm($1) if($line =~ /algorithm \s+ (\S+);/x); | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 82 | 6 | ▶ | $self->secret($2) if($line =~ /secret \s+ ("?)(\S+)\1;/x); | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 83 | 6 | 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 | 3 | ▶ | sub captured_to_args { | ||||||||||||||||
|
Subroutine
captured_to_args: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||
| 93 | 3 | my $value = shift; | |||||||||||||||||
| 94 | 3 | my $quoted = 0; | |||||||||||||||||
| 95 | 3 | ▶ | $quoted = 1 if($value =~ s/^"(.*)"$/$1/g); | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 96 | 3 | 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 | 1 | ▶ | sub generate { | ||||||||||||||||
|
Subroutine
generate: called CC=4 SCAR=15.2
Pod
documented
| |||||||||||||||||||
| 106 | 1 | my $self = shift; | |||||||||||||||||
| 107 | 1 | my $name = $self->name; | |||||||||||||||||
| 108 | |||||||||||||||||||
| 109 | return( | ||||||||||||||||||
| 110 | 1 | ▶ | sprintf('key '. ($self->quoted ? qq("$name") : $name). ' {'), | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 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 | 27 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||
| 125 | 27 | 1; | |||||||||||||||||