| 1 | package DNS::Oterica::Network; | ||||||||||
| 2 | # ABSTRACT: a network to which results are served | ||||||||||
| 3 | 2 | $DNS::Oterica::Network::VERSION = '0.313'; | |||||||||
| 4 | 2 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 2 | ▶ | use Net::IP; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 2 | ▶ | use Moose::Util::TypeConstraints; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | # TODO: move these to a types library | ||||||||||
| 10 | # XXX: Wait, why does the first one not line-break before the second => ? | ||||||||||
| 11 | # Well, because if I do, it fails to parse on 5.14. What?? | ||||||||||
| 12 | # -- rjbs, 2021-07-11 | ||||||||||
| 13 | subtype 'DNS::Oterica::Type::Network' | ||||||||||
| 14 | 0 | ▶ | => as Object => where { $_->isa('Net::IP') }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||
| 15 | |||||||||||
| 16 | coerce 'DNS::Oterica::Type::Network' | ||||||||||
| 17 | => from 'Str' | ||||||||||
| 18 | 0 | ▶ | => via { Net::IP->new($_) || confess( Net::IP::Error() ) }; | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=13.0
Branch: 1 branch
| |||||||||||
| 19 | |||||||||||
| 20 | subtype 'DNS::Oterica::Type::Networks' | ||||||||||
| 21 | => as ArrayRef | ||||||||||
| 22 | 8 | ▶ | => where { @$_ == grep {; ref $_ and $_->isa('Net::IP') } @$_ }; | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||
| 23 | |||||||||||
| 24 | coerce 'DNS::Oterica::Type::Networks' | ||||||||||
| 25 | => from 'ArrayRef' | ||||||||||
| 26 | 4 | ▶ | => via { [ map {; Net::IP->new($_) || confess( Net::IP::Error() ) } @$_ ] }; | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
Branch: 1 branch
| |||||||||||
| 27 | |||||||||||
| 28 | #pod =head1 OVERVIEW | ||||||||||
| 29 | #pod | ||||||||||
| 30 | #pod Networks are IP networks to which results are served, and can be used to | ||||||||||
| 31 | #pod implement split horizons. | ||||||||||
| 32 | #pod | ||||||||||
| 33 | #pod Like other DNS::Oterica objects, they should be created through the hub. | ||||||||||
| 34 | #pod | ||||||||||
| 35 | #pod =attr name | ||||||||||
| 36 | #pod | ||||||||||
| 37 | #pod This is the network's unique name. | ||||||||||
| 38 | #pod | ||||||||||
| 39 | #pod =cut | ||||||||||
| 40 | |||||||||||
| 41 | 2 | has name => (is => 'ro', isa => 'Str', required => 1); | |||||||||
| 42 | |||||||||||
| 43 | #pod =attr subnets | ||||||||||
| 44 | #pod | ||||||||||
| 45 | #pod This is the C<Net::IP> ranges for the network at this network. | ||||||||||
| 46 | #pod | ||||||||||
| 47 | #pod =cut | ||||||||||
| 48 | |||||||||||
| 49 | 2 | has subnets => ( | |||||||||
| 50 | isa => 'DNS::Oterica::Type::Networks', | ||||||||||
| 51 | traits => [ 'Array' ], | ||||||||||
| 52 | handles => { subnets => 'elements' }, | ||||||||||
| 53 | required => 1, | ||||||||||
| 54 | coerce => 1, | ||||||||||
| 55 | ); | ||||||||||
| 56 | |||||||||||
| 57 | sub _class_prefixes { | ||||||||||
| 58 | 4 | ▶ | my ($self, @ips) = @_; # $ip arg for testing | ||||||||
|
Subroutine
_class_prefixes: called CC=4 SCAR=13.9
| |||||||||||
| 59 | |||||||||||
| 60 | 4 | ▶ | @ips = $self->subnets unless @ips; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | |||||||||||
| 62 | 4 | my @prefixes; | |||||||||
| 63 | |||||||||||
| 64 | 4 | for my $ip (@ips) { | |||||||||
| 65 | 4 | my $pl = $ip->prefixlen; | |||||||||
| 66 | 4 | my $class = int( $pl / 8 ); | |||||||||
| 67 | 4 | my @quads = split /\./, $ip->ip; | |||||||||
| 68 | 4 | my @keep = splice @quads, 0, $class; | |||||||||
| 69 | 4 | my $fixed = join q{.}, @keep; | |||||||||
| 70 | 4 | my $bits = 8 - ($pl - $class * 8); | |||||||||
| 71 | |||||||||||
| 72 | 4 | ▶ | if ($bits == 8) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 73 | 2 | push @prefixes, $fixed; | |||||||||
| 74 | } else { | ||||||||||
| 75 | 2 | push @prefixes, map {; "$fixed.$_" } (0 .. (2**$bits - 1)); | |||||||||
| 76 | } | ||||||||||
| 77 | } | ||||||||||
| 78 | |||||||||||
| 79 | 4 | return @prefixes; | |||||||||
| 80 | } | ||||||||||
| 81 | |||||||||||
| 82 | sub as_data_lines { | ||||||||||
| 83 | 0 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
as_data_lines: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 84 | 0 | $self->hub->rec->location($self); | |||||||||
| 85 | } | ||||||||||
| 86 | |||||||||||
| 87 | # Do we really want to keep this? | ||||||||||
| 88 | 2 | has delegated => (is => 'ro', isa => 'Bool', required => 0, default => 0); | |||||||||
| 89 | |||||||||||
| 90 | 2 | has code => (is => 'ro', isa => 'Str', required => 1); | |||||||||
| 91 | |||||||||||
| 92 | 2 | with 'DNS::Oterica::Role::HasHub'; | |||||||||
| 93 | |||||||||||
| 94 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||
| 95 | 2 | ▶ | no Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 96 | 2 | 1; | |||||||||
| 97 | |||||||||||
| 98 | __END__ | ||||||||||
| 99 | |||||||||||
| 100 | =pod | ||||||||||
| 101 | |||||||||||
| 102 | =encoding UTF-8 | ||||||||||
| 103 | |||||||||||
| 104 | =head1 NAME | ||||||||||
| 105 | |||||||||||
| 106 | DNS::Oterica::Network - a network to which results are served | ||||||||||
| 107 | |||||||||||
| 108 | =head1 VERSION | ||||||||||
| 109 | |||||||||||
| 110 | version 0.313 | ||||||||||
| 111 | |||||||||||
| 112 | =head1 OVERVIEW | ||||||||||
| 113 | |||||||||||
| 114 | Networks are IP networks to which results are served, and can be used to | ||||||||||
| 115 | implement split horizons. | ||||||||||
| 116 | |||||||||||
| 117 | Like other DNS::Oterica objects, they should be created through the hub. | ||||||||||
| 118 | |||||||||||
| 119 | =head1 PERL VERSION | ||||||||||
| 120 | |||||||||||
| 121 | This library should run on perls released even a long time ago. It should work | ||||||||||
| 122 | on any version of perl released in the last five years. | ||||||||||
| 123 | |||||||||||
| 124 | Although it may work on older versions of perl, no guarantee is made that the | ||||||||||
| 125 | minimum required version will not be increased. The version may be increased | ||||||||||
| 126 | for any reason, and there is no promise that patches will be accepted to lower | ||||||||||
| 127 | the minimum required perl. | ||||||||||
| 128 | |||||||||||
| 129 | =head1 ATTRIBUTES | ||||||||||
| 130 | |||||||||||
| 131 | =head2 name | ||||||||||
| 132 | |||||||||||
| 133 | This is the network's unique name. | ||||||||||
| 134 | |||||||||||
| 135 | =head2 subnets | ||||||||||
| 136 | |||||||||||
| 137 | This is the C<Net::IP> ranges for the network at this network. | ||||||||||
| 138 | |||||||||||
| 139 | =head1 AUTHOR | ||||||||||
| 140 | |||||||||||
| 141 | Ricardo SIGNES <rjbs@semiotic.systems> | ||||||||||
| 142 | |||||||||||
| 143 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 144 | |||||||||||
| 145 | This software is copyright (c) 2021 by Ricardo SIGNES. | ||||||||||
| 146 | |||||||||||
| 147 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 148 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 149 | |||||||||||
| 150 | =cut | ||||||||||