blib/lib/App/Netdisco/DB/Result/DeviceIp.pm untested

filter: Statementstmt 0.0% 0 / 26 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 35 CC 1 SCAR 6.9
CC
1
Cov
0%
l3_domain
2.0
TO_JSON
2.0
BEGIN
2.0
CRAP 2.0
1 use utf8;
2 package App::Netdisco::DB::Result::DeviceIp;
3  
4  
5 use strict;
6 use warnings;
7  
8 use base 'App::Netdisco::DB::Result';
9 use App::Netdisco::Util::L3Domain 'row_l3_domain';
10  
11 __PACKAGE__->table("device_ip");
12 __PACKAGE__->add_columns(
13 "ip",
14 { data_type => "inet", is_nullable => 0 },
15 "alias",
16 { data_type => "inet", is_nullable => 0 },
17 "subnet",
18 { data_type => "cidr", is_nullable => 1 },
19 "port",
20 { data_type => "text", is_nullable => 1 },
21 "dns",
22 { data_type => "text", is_nullable => 1 },
23 "creation",
24 {
25 data_type => "timestamp",
26 default_value => \"LOCALTIMESTAMP",
27 is_nullable => 1,
28 original => { default_value => \"LOCALTIMESTAMP" },
29 },
30 "first_seen",
31 {
32 data_type => "timestamp",
33 default_value => \"LOCALTIMESTAMP",
34 is_nullable => 1,
35 original => { default_value => \"LOCALTIMESTAMP" },
36 },
37 "vrf",
38 { data_type => "text", is_nullable => 0, default_value => "" },
39 );
40 __PACKAGE__->set_primary_key("ip", "alias", "vrf");
41  
42  
43  
44 =head1 RELATIONSHIPS
45  
46 =head2 device
47  
48 Returns the entry from the C<device> table to which this IP alias relates.
49  
50 =cut
51  
52 __PACKAGE__->belongs_to( device => 'App::Netdisco::DB::Result::Device', 'ip' );
53  
54 =head2 device_port
55  
56 Returns the Port on which this IP address is configured (typically a loopback,
57 routed port or virtual interface).
58  
59 =cut
60  
61 __PACKAGE__->belongs_to( device_port => 'App::Netdisco::DB::Result::DevicePort',
62 { 'foreign.port' => 'self.port', 'foreign.ip' => 'self.ip' } );
63  
64  
65 =head2 l3_domain
66  
67 Returns C<< { id, name } >> of the L3 domain this row's VRF belongs to, or undef
68 when it cannot be determined. A default-table row is domain 0 without a query.
69  
70 =cut
71  
72 sub l3_domain { return row_l3_domain($_[0], $_[0]->get_column('ip')) }
73  
74 sub TO_JSON {
75 my $self = shift;
76 my $data = $self->next::method(@_);
77 $data->{l3_domain} = $self->l3_domain;
78 return $data;
79 }
80  
81 1;