File Coverage

blib/lib/DNS/Oterica/Network.pm
Criterion Covered Total %
statement 1 3 33.3
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 2 4 50.0


line stmt bran cond sub pod time code
1             package DNS::Oterica::Network;
2             # ABSTRACT: a network to which results are served
3             $DNS::Oterica::Network::VERSION = '0.205';
4 1     1   1288 use Moose;
  0            
  0            
5              
6             use Net::IP;
7             use Moose::Util::TypeConstraints;
8              
9             # TODO: move these to a types library
10             subtype 'DNS::Oterica::Type::Network'
11             => as Object
12             => where { $_->isa('Net::IP') };
13              
14             coerce 'DNS::Oterica::Type::Network'
15             => from 'Str'
16             => via { Net::IP->new($_) || confess( Net::IP::Error() ) };
17              
18             #pod =head1 OVERVIEW
19             #pod
20             #pod Networks are IP networks to which results are served, and can be used to
21             #pod implement split horizons.
22             #pod
23             #pod Like other DNS::Oterica objects, they should be created through the hub.
24             #pod
25             #pod =attr name
26             #pod
27             #pod This is the network's unique name.
28             #pod
29             #pod =cut
30              
31             has name => (is => 'ro', isa => 'Str', required => 1);
32              
33             #pod =attr subnet
34             #pod
35             #pod This is the C<Net::IP> range for the network at this network.
36             #pod
37             #pod =cut
38              
39             has subnet => (
40             is => 'ro',
41             isa => 'DNS::Oterica::Type::Network',
42             required => 1,
43             coerce => 1,
44             );
45              
46             sub _class_prefixes {
47             my ($self, $ip) = @_; # $ip arg for testing
48              
49             $ip ||= $self->subnet;
50             my $pl = $ip->prefixlen;
51             my $class = int( $pl / 8 );
52             my @quads = split /\./, $ip->ip;
53             my @keep = splice @quads, 0, $class;
54             my $fixed = join q{.}, @keep;
55             my $bits = 8 - ($pl - $class * 8);
56              
57             return $fixed if $bits == 8;
58              
59             my @prefixes = map {; "$fixed.$_" } (0 .. (2**$bits - 1));
60             return @prefixes;
61             }
62              
63             sub as_data_lines {
64             my ($self) = @_;
65             $self->hub->rec->location($self);
66             }
67              
68             # Do we really want to keep this?
69             has delegated => (is => 'ro', isa => 'Bool', required => 0, default => 0);
70              
71             has code => (is => 'ro', isa => 'Str', required => 1);
72              
73             with 'DNS::Oterica::Role::HasHub';
74              
75             __PACKAGE__->meta->make_immutable;
76             no Moose;
77             1;
78              
79             __END__
80              
81             =pod
82              
83             =encoding UTF-8
84              
85             =head1 NAME
86              
87             DNS::Oterica::Network - a network to which results are served
88              
89             =head1 VERSION
90              
91             version 0.205
92              
93             =head1 OVERVIEW
94              
95             Networks are IP networks to which results are served, and can be used to
96             implement split horizons.
97              
98             Like other DNS::Oterica objects, they should be created through the hub.
99              
100             =head1 ATTRIBUTES
101              
102             =head2 name
103              
104             This is the network's unique name.
105              
106             =head2 subnet
107              
108             This is the C<Net::IP> range for the network at this network.
109              
110             =head1 AUTHOR
111              
112             Ricardo SIGNES <rjbs@cpan.org>
113              
114             =head1 COPYRIGHT AND LICENSE
115              
116             This software is copyright (c) 2014 by Ricardo SIGNES.
117              
118             This is free software; you can redistribute it and/or modify it under
119             the same terms as the Perl 5 programming language system itself.
120              
121             =cut