blib/lib/App/Netdisco/DB/ResultSet/Subnet.pm untested

filter: Statementstmt 0.0% 0 / 17 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 29 CC 3 SCAR 19.5
CC
3
Cov
0%
upsert_subnet
12.0
BEGIN
2.0
BEGIN
2.0
CRAP 7.0
1 package App::Netdisco::DB::ResultSet::Subnet;
2 use base 'App::Netdisco::DB::ResultSet';
3  
4 use strict;
5 use warnings;
6  
7 __PACKAGE__->load_components(qw/
8 +App::Netdisco::DB::ExplicitLocking
9 /);
10  
11 =head1 ADDITIONAL METHODS
12  
13 =head2 upsert_subnet( $net, $now, $vrf, $router )
14  
15 Records C<$net> as seen at C<$now>, adding the row if it is new. One
16 statement, so two pollers that see the same new subnet at once cannot both
17 try to insert it.
18  
19 C<$now> must be one of the timestamp forms accepted by C<upsert>, such as
20 C<LOCALTIMESTAMP> or C<to_timestamp(1)::timestamp>.
21  
22 Optional C<$vrf> names the routing context the subnet was seen in, and
23 defaults to the empty string (the global table).
24  
25 Optional C<$router> is the device that reported the subnet, kept as
26 C<router_last>. Without one the column is left as it was.
27  
28 =cut
29  
30 sub upsert_subnet {
31 my ($rs, $net, $now, $vrf, $router) = @_;
32 return unless $net;
33 my %row = (net => $net, vrf => $vrf // '', last_discover => \$now);
34 $row{router_last} = $router if defined $router;
35 return $rs->upsert([\%row]);
36 }
37  
38 1;