DHCPd/Config/Key.pm

filter: Statementstmt 100% 21 / 21 Branchbran 78.5% 11 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod 100% 3 / 3 totaltotal 92.8% 39 / 42 CC 8 SCAR 12.8
CC
8
Cov
91%
generate
4.6
slurp
4.0
captured_to_args
2.0
CRAP 3.6
« DHCPd.pm ↑ Summary DHCPd/OMAPI/Sugar.pm »
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
BranchTrueFalseTotal
if $line =~ /^\s*}/ 3 6 9
81 6 ▶ $self->algorithm($1) if($line =~ /algorithm \s+ (\S+);/x);
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /algorithm \s+ (\S+);/x 3 3 6
82 6 ▶ $self->secret($2) if($line =~ /secret \s+ ("?)(\S+)\1;/x);
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /secret \s+ ("?)(\S+)\1;/x 2 4 6
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
BranchTrueFalseTotal
if $value =~ s/^"(.*)"$/$1/g 2 1 3
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
BranchTrueFalseTotal
$self->quoted ? : 1 0 1
$self->algorithm ? : 1 0 1
$self->secret ? : 1 0 1
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;
« DHCPd.pm ↑ Summary DHCPd/OMAPI/Sugar.pm »