Oterica/App.pm

filter: Statementstmt 67.3% 35 / 52 Branchbran 25.0% 2 / 8 Conditioncond 28.5% 2 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 87.5% 7 / 8 Podpod 0.0% 0 / 4 totaltotal 55.4% 46 / 83 CC 16 SCAR 29.8
CC
16
Cov
58%
populate_hosts
56.0
BUILD
5.9
populate_domains
4.0
CRAP 19.6
« Oterica/RecordMaker/TinyDNS.pm ↑ Summary Oterica/Node.pm »
1 package DNS::Oterica::App;
2 # ABSTRACT: the code behind `dnsoterica`
3 1 $DNS::Oterica::App::VERSION = '0.313';
4 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use DNS::Oterica::Hub;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use File::Find::Rule;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use YAML::XS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 #pod =attr hub
10 #pod
11 #pod This is the L<DNS::Oterica::Hub> into which entries will be loaded.
12 #pod
13 #pod =cut
14  
15 1 has hub => (
16 is => 'ro',
17 isa => 'DNS::Oterica::Hub',
18 writer => '_set_hub',
19 predicate => '_has_hub',
20 );
21  
22 sub BUILD {
23 1 ▶ my ($self, $arg) = @_;
Subroutine BUILD: called CC=5 SCAR=17.8
Pod undocumented
24  
25 confess "both hub and hub_args provided"
26 1 ▶ if $self->_has_hub and $arg->{hub_args};
Branch: 1 branch
BranchTrueFalseTotal
if $self->_has_hub and $arg->{"hub_args"} 0 1 1
Condition33%1/3
$self->_has_hub and $arg->{"hub_args"}
!ll&&!rl&&r
100
MC/DC0%0/2
$self->_has_hub and $arg->{"hub_args"}
$self->_has_hub $arg->{"hub_args"}
Truth table33%1/3
A and B
A= $self->_has_hubB= $arg->{"hub_args"}
ABresult
0X0
100
111
27  
28 1 ▶ unless ($self->_has_hub) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_has_hub) 1 0 1
29 1 my %args = %{$arg->{hub_args}};
30 1 ▶ $self->_set_hub( DNS::Oterica::Hub->new(\%args || {}) );
Condition50%1/2
\%args || {}
l!l
10
MC/DC0%0/1
\%args || {}
\%args
Truth table50%1/2
A
A= \%args
Aresult
11
00
31 }
32 }
33  
34 #pod =attr root
35 #pod
36 #pod This is a directory in which F<dnsoterica> will look for configuration files.
37 #pod
38 #pod It will look in the subdirectory F<domains> for domain definitions and F<hosts>
39 #pod for hosts.
40 #pod
41 #pod =cut
42  
43 1 has root => (
44 is => 'ro',
45 required => 1,
46 );
47  
48 sub populate_networks {
49 1 ▶ my ($self) = @_;
Subroutine populate_networks: called CC=3 SCAR=11.0
Pod undocumented
50  
51 1 my $root = $self->root;
52 1 for my $file (File::Find::Rule->file->in("$root/networks")) {
53 2 for my $data (YAML::XS::LoadFile($file)) {
54 2 $self->hub->add_network($data);
55 }
56 }
57 }
58  
59 sub populate_domains {
60 1 ▶ my ($self) = @_;
Subroutine populate_domains: called CC=4 SCAR=13.9
Pod undocumented
61 1 my $root = $self->root;
62 1 for my $file (File::Find::Rule->file->in("$root/domains")) {
63 1 for my $data (YAML::XS::LoadFile($file)) {
64 my $node = $self->hub->domain(
65 $data->{domain},
66 1 );
67  
68 1 for my $name (@{ $data->{families} }) {
69 1 my $family = $self->hub->node_family($name);
70  
71 0 $node->add_to_family($family);
72 }
73 }
74 }
75 }
76  
77 sub populate_hosts {
78 0 ▶ my ($self) = @_;
Subroutine populate_hosts: not called CC=7 SCAR=40.3
Pod undocumented
79 0 my $root = $self->root;
80 0 my $hub = $self->hub;
81  
82 0 for my $file (File::Find::Rule->file->in("$root/hosts")) {
83 0 for my $data (YAML::XS::LoadFile($file)) {
84 0 my $interfaces;
85 0 ▶ if (ref $data->{ip}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $data->{'ip'}) { } 0 0 0
86 $interfaces = [
87 map {;
88 [
89 0 $data->{ip}{$_} => $hub->network($_) ]
90 0 } keys %{ $data->{ip}}
91 ];
92 } else {
93 $interfaces = [
94 0 [ $data->{ip} => $hub->network( $hub->all_network_name ) ]
95 ];
96 }
97  
98 my $node = $hub->host(
99 $data->{domain},
100 $data->{hostname},
101 {
102 interfaces => $interfaces,
103 location => $data->{location},
104 aliases => $data->{aliases} || [],
105 0 ▶ (exists $data->{ttl} ? (ttl => $data->{ttl}) : ()),
Branch: 1 branch
BranchTrueFalseTotal
exists $data->{'ttl'} ? : 0 0 0
Condition0%0/2
$data->{'aliases'} || []
l!l
00
MC/DC0%0/1
$data->{'aliases'} || []
$data->{'aliases'}
Truth table0%0/2
A
A= $data->{'aliases'}
Aresult
11
00
106 },
107 );
108  
109 0 for my $name (@{ $data->{families} }) {
110 0 my $family = $hub->node_family($name);
111  
112 0 $node->add_to_family($family);
113 }
114 }
115 }
116 }
117  
118 1 1;
119  
120 __END__
121  
122 =pod
123  
124 =encoding UTF-8
125  
126 =head1 NAME
127  
128 DNS::Oterica::App - the code behind `dnsoterica`
129  
130 =head1 VERSION
131  
132 version 0.313
133  
134 =head1 PERL VERSION
135  
136 This library should run on perls released even a long time ago. It should work
137 on any version of perl released in the last five years.
138  
139 Although it may work on older versions of perl, no guarantee is made that the
140 minimum required version will not be increased. The version may be increased
141 for any reason, and there is no promise that patches will be accepted to lower
142 the minimum required perl.
143  
144 =head1 ATTRIBUTES
145  
146 =head2 hub
147  
148 This is the L<DNS::Oterica::Hub> into which entries will be loaded.
149  
150 =head2 root
151  
152 This is a directory in which F<dnsoterica> will look for configuration files.
153  
154 It will look in the subdirectory F<domains> for domain definitions and F<hosts>
155 for hosts.
156  
157 =head1 AUTHOR
158  
159 Ricardo SIGNES <rjbs@semiotic.systems>
160  
161 =head1 COPYRIGHT AND LICENSE
162  
163 This software is copyright (c) 2021 by Ricardo SIGNES.
164  
165 This is free software; you can redistribute it and/or modify it under
166 the same terms as the Perl 5 programming language system itself.
167  
168 =cut
« Oterica/RecordMaker/TinyDNS.pm ↑ Summary Oterica/Node.pm »