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

filter: Statementstmt 0.0% 0 / 32 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 53 CC 4 SCAR 17.6
CC
4
Cov
0%
add_to_actionset
12.0
increment_deferrals
6.0
BEGIN
2.0
CRAP 5.8
1 use utf8;
2 package App::Netdisco::DB::Result::DeviceSkip;
3  
4 use strict;
5 use warnings;
6  
7 use List::MoreUtils ();
8  
9 use base 'App::Netdisco::DB::Result';
10 __PACKAGE__->table("device_skip");
11 __PACKAGE__->add_columns(
12 "backend",
13 { data_type => "text", is_nullable => 0 },
14 "device",
15 { data_type => "inet", is_nullable => 0 },
16 "actionset",
17 { data_type => "text[]", is_nullable => 1, default_value => \"'{}'::text[]" },
18 "deferrals",
19 { data_type => "integer", is_nullable => 1, default_value => '0' },
20 "last_defer",
21 { data_type => "timestamp", is_nullable => 1 },
22 );
23  
24 __PACKAGE__->set_primary_key("backend", "device");
25  
26 __PACKAGE__->add_unique_constraint(
27 device_skip_pkey => [qw/backend device/]);
28  
29 =head1 METHODS
30  
31 =head2 increment_deferrals
32  
33 Increments the C<deferrals> field in the row, only if the row is in storage.
34 There is a race in the update, but this is not worrying for now.
35  
36 =cut
37  
38 sub increment_deferrals {
39 my $row = shift;
40 return unless $row->in_storage;
41 return $row->update({
42 deferrals => (($row->deferrals || 0) + 1),
43 last_defer => \'LOCALTIMESTAMP',
44 });
45 }
46  
47 =head2 add_to_actionset
48  
49 =cut
50  
51 sub add_to_actionset {
52 my ($row, @badactions) = @_;
53 return unless $row->in_storage;
54 return unless scalar @badactions;
55 return $row->update({ actionset =>
56 [ sort (List::MoreUtils::uniq( @{ $row->actionset || [] }, @badactions )) ]
57 });
58 }
59  
60 1;