| 1 | package Net::Google::SafeBrowsing4::Storage::File; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use base qw(Net::Google::SafeBrowsing4::Storage); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use List::Util qw(first); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use Path::Tiny; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use Storable qw(nstore retrieve); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use List::BinarySearch qw(binsearch); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 3 | our $VERSION = '0.2'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | Net::Google::SafeBrowsing4::Storage::File - File storage for the Google Safe Browsing v4 database | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | use Net::Google::SafeBrowsing4::Storage::File; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | my $storage = Net::Google::SafeBrowsing4::Storage::File->new(path => '.'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | $storage->save(...); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | This is the a file-based implementation of L<Net::Google::SafeBrowsing4::Storage> to manage the Google Safe Browsing v4 local database. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | =head1 CONSTRUCTOR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | =head2 new() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | Create a Net::Google::SafeBrowsing4::Storage::File object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | my $storage => Net::Google::SafeBrowsing4::Storage::File->new(path => '.'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | Arguments | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | =item path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | Optional. Path to store the database files Use current directory by default. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | =item keep_all | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | Optional. Set to 1 to keep old information (such as expiring full hashes) in the database. 0 (delete) by default. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | =item sticky | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | Optional. Set to 1 to if you are going to do multiple lookup. More memory will be used but lookup will be sped up. 0 by default. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | =item files | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | Optional. Hash reference to map file types to file names. Default: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | updates => "updates.gdb4", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | full_hashes => "full_hashes.gsb4" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | =item logger | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | Optional. Log4Perl compatible object reference. By default this option is unset, making Net::Google::SafeBrowsing4::Storage::File silent. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 11 | ▶ | my ($class, %args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 11 | my $self = { # default arguments | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | keep_all => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | path => '.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | sticky => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | files => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | updates => "updates.gdb4", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | full_hashes => "full_hashes.gsb4" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | data => { }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | %args, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 11 | ▶ | bless($self, $class) or croak("Can't bless $class: $!"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 11 | $self->init(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 11 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | =head1 PUBLIC FUNCTIONS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | See L<Net::Google::SafeBrowsing4::Storage> for a complete list of public functions. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | =head2 close() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | Cleanup old full hashes, and close the connection to the database. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | $storage->close(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | sub init { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 11 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=6 SCAR=20.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | # make sure path exists | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 11 | ▶ | if (! -d $self->{path}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | mkdir($self->{path}) or croak("Cannot create directory " . $self->{path} . ": $!\n"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | # file to hold all updates | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 11 | my $file = path(join("/", $self->{path}, $self->{files}->{updates})); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 11 | ▶ | if (! -e $file) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 1 | my %update = (last_update => 0, next_update => 0, errors => 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 1 | ▶ | if ($self->{sticky}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | $self->{data}->{ $self->{files}->{updates} } = { %update }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 1 | ▶ | nstore(\%update, $file) or croak("Cannot store information into $file: $!\n"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | sub save { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
save: not called CC=19 SCAR=59.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | my $list = $args{list} || croak("Missing list information"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$args{'list'} || croak('Missing list information')
MC/DC0%0/2
$args{'list'} || croak('Missing list information')
$args{'list'}
croak('Missing list information')
Truth table0%0/3
A || B
A= $args{'list'}B= croak('Missing list information')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | my $override = $args{override} || 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$args{'override'} || 0
MC/DC0%0/1
$args{'override'} || 0
$args{'override'}
Truth table0%0/2
A
A= $args{'override'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | ▶ | my @hashes = @{ $args{add} || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | my @remove = @{ $args{remove} || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | my $state = $args{'state'} || ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$args{'state'} || ''
MC/DC0%0/1
$args{'state'} || ''
$args{'state'}
Truth table0%0/2
A
A= $args{'state'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | # save the information somewhere | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | my $file = path(join("/", $self->{path}, $self->list_to_file($list))); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | ▶ | $self->{logger} && $self->{logger}->debug("Save hashes to $file"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | my %data = ('state' => $state, hashes => [@hashes]); # hashes are already stored | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | if (-e $file && !$override) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-e $file and not $override
MC/DC0%0/2
-e $file and not $override
-e $file
not $override
Truth table0%0/3
A and not(B)
A= -e $fileB= not $override
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | my $db = retrieve($file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | ▶ | $self->{logger} && $self->{logger}->debug("Load $file (save)"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | ▶ | $self->{logger} && $self->{logger}->debug("hashes to remove: ", scalar(@remove)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | ▶ | $self->{logger} && $self->{logger}->debug("hashes to add: ", scalar(@hashes)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | $self->{logger} && $self->{logger}->debug("Number of hashes before removal: ", scalar(@{ $db->{hashes} })); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | foreach my $index (@remove) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | $self->{logger} && $self->{logger}->debug("Remove index $index"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | $db->{hashes}->[$index] = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | $db->{hashes} = [ grep { $_ ne '' } @{ $db->{hashes} } ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | $self->{logger} && $self->{logger}->debug("Number of hashes after removal: ", scalar(@{ $db->{hashes} })); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | $data{hashes} = [sort { $a cmp $b } (@hashes, @{ $db->{hashes} })]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | nstore(\%data, $file) or croak("Cannot save data to $file: $!\n"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | ▶ | if ($self->{sticky}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | $self->{data}->{ $self->list_to_file($list) } = { %data }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | # return the list of hashes, sorted, from the new storage | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | ▶ | $self->{logger} && $self->{logger}->debug("Number of hashes at end: ", scalar(@{ $data{hashes} })); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | return @{ $data{hashes} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | sub reset { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reset: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | ▶ | my $list = $args{list} || croak("Missing list information"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$args{'list'} || croak('Missing list information')
MC/DC0%0/2
$args{'list'} || croak('Missing list information')
$args{'list'}
croak('Missing list information')
Truth table0%0/3
A || B
A= $args{'list'}B= croak('Missing list information')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | my $file = path(join("/", $self->{path}, $self->list_to_file($list))); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | unlink($file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | if ($self->{sticky}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | $self->{data}->{ $self->list_to_file($list) } = { }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | sub next_update { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
next_update: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | # make sure the file exists | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | $self->init(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | my $update = { }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | ▶ | if ($self->{sticky} && exists($self->{data}->{ $self->{files}->{updates} })) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"sticky"} and exists $self->{"data"}{$self->{"files"}{"updates"}}
MC/DC0%0/2
$self->{"sticky"} and exists $self->{"data"}{$self->{"files"}{"updates"}}
$self->{"sticky"}
exists $self->{"data"}{$self->{"files"}{"updates"}}
Truth table0%0/3
A and B
A= $self->{"sticky"}B= exists $self->{"data"}{$self->{"files"}{"updates"}}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | $update = $self->{data}->{ $self->{files}->{updates} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | # retrieve information from storage | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | my $file = path(join("/", $self->{path}, $self->{files}->{updates})); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | $update = retrieve($file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | ▶ | $self->{logger} && $self->{logger}->debug("Load $file (reset)"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | ▶ | if ($self->{sticky}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | $self->{data}->{ $self->{files}->{updates} } = $update;; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | ▶ | return $update->{next_update} || 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$update->{'next_update'} || 0
MC/DC0%0/1
$update->{'next_update'} || 0
$update->{'next_update'}
Truth table0%0/2
A
A= $update->{'next_update'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | sub last_update { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
last_update: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | # make sure the file exists | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | $self->init(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | my $update = { }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | ▶ | if ($self->{sticky} && exists($self->{data}->{ $self->{files}->{updates} })) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"sticky"} and exists $self->{"data"}{$self->{"files"}{"updates"}}
MC/DC0%0/2
$self->{"sticky"} and exists $self->{"data"}{$self->{"files"}{"updates"}}
$self->{"sticky"}
exists $self->{"data"}{$self->{"files"}{"updates"}}
Truth table0%0/3
A and B
A= $self->{"sticky"}B= exists $self->{"data"}{$self->{"files"}{"updates"}}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | $update = $self->{data}->{ $self->{files}->{updates} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | # retrieve information from storage | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | my $file = path(join("/", $self->{path}, $self->{files}->{updates})); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | $update = retrieve($file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | ▶ | $self->{logger} && $self->{logger}->debug("Load $file (last_udpate)"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | ▶ | if ($self->{sticky}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | $self->{data}->{ $self->{files}->{updates} } = $update; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | return { last_update => $update->{last_update} || 0, errors => $update->{errors} || 0 }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/4
$update->{'last_update'} || 0
$update->{'errors'} || 0
MC/DC0%0/1
$update->{'last_update'} || 0
$update->{'last_update'}
MC/DC0%0/1
$update->{'errors'} || 0
$update->{'errors'}
Truth table0%0/2
A
A= $update->{'last_update'}
Truth table0%0/2
A
A= $update->{'errors'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | sub get_state { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_state: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | ▶ | my $list = $args{list} || croak("Missing list information\n"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$args{'list'} || croak("Missing list information\n")
MC/DC0%0/2
$args{'list'} || croak("Missing list information\n")
$args{'list'}
croak("Missing list information\n")
Truth table0%0/3
A || B
A= $args{'list'}B= croak("Missing list information\n")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | my $update = { }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | ▶ | if ($self->{sticky} && exists($self->{data}->{ $self->list_to_file($list) })) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"sticky"} and exists $self->{"data"}{$self->list_to_file($list)}
MC/DC0%0/2
$self->{"sticky"} and exists $self->{"data"}{$self->list_to_file($list)}
$self->{"sticky"}
exists $self->{"data"}{$self->list_to_file($list)}
Truth table0%0/3
A and B
A= $self->{"sticky"}B= exists $self->{"data"}{$self->list_to_file($list)}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | $update = $self->{data}->{ $self->list_to_file($list) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | my $file = path(join("/", $self->{path}, $self->list_to_file($list))); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | ▶ | if (! -e $file) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | return ""; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | ▶ | $self->{logger} && $self->{logger}->debug("Load $file (get_state)"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | $update = retrieve($file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | ▶ | if ($self->{sticky}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | $self->{data}->{ $self->list_to_file($list) } = $update; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | ▶ | return $update->{'state'} || ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$update->{'state'} || ''
MC/DC0%0/1
$update->{'state'} || ''
$update->{'state'}
Truth table0%0/2
A
A= $update->{'state'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | sub updated { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
updated: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | my $time = $args{'time'} || time(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$args{'time'} || time
MC/DC0%0/2
$args{'time'} || time
$args{'time'}
time
Truth table0%0/3
A || B
A= $args{'time'}B= time
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | ▶ | my $next = $args{'next'} || time() + 1800; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$args{'next'} || time + 1800
MC/DC0%0/2
$args{'next'} || time + 1800
$args{'next'}
time + 1800
Truth table0%0/3
A || B
A= $args{'next'}B= time + 1800
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | # next update applies to all lists, save it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | # make sure the file exists | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | $self->init(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | my $file = path(join("/", $self->{path}, $self->{files}->{updates})); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | my $update = { }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | ▶ | if ($self->{sticky} && exists($self->{data}->{ $self->{files}->{updates} })) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"sticky"} and exists $self->{"data"}{$self->{"files"}{"updates"}}
MC/DC0%0/2
$self->{"sticky"} and exists $self->{"data"}{$self->{"files"}{"updates"}}
$self->{"sticky"}
exists $self->{"data"}{$self->{"files"}{"updates"}}
Truth table0%0/3
A and B
A= $self->{"sticky"}B= exists $self->{"data"}{$self->{"files"}{"updates"}}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | $update = $self->{data}->{ $self->{files}->{updates} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | # retrieve information from storage | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | ▶ | $self->{logger} && $self->{logger}->debug("Load $file (updated)"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | $update = retrieve($file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | $update->{next_update} = $next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | $update->{last_udpate} = $time; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | $update->{errors} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | ▶ | nstore($update, $file) or croak("Cannot save data to $file: $!\n"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | ▶ | if ($self->{sticky}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | $self->{data}->{ $self->{files}->{updates} } = $update; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | sub update_error { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update_error: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | ▶ | my $time = $args{'time'} || time(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$args{'time'} || time
MC/DC0%0/2
$args{'time'} || time
$args{'time'}
time
Truth table0%0/3
A || B
A= $args{'time'}B= time
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | ▶ | my $wait = $args{'wait'} || 1800; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$args{'wait'} || 1800
MC/DC0%0/1
$args{'wait'} || 1800
$args{'wait'}
Truth table0%0/2
A
A= $args{'wait'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | ▶ | my $errors = $args{errors} || 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$args{'errors'} || 0
MC/DC0%0/1
$args{'errors'} || 0
$args{'errors'}
Truth table0%0/2
A
A= $args{'errors'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | # make sure the file exists | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | $self->init(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | my $file = path(join("/", $self->{path}, $self->{files}->{updates})); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | my $update = { }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | ▶ | if ($self->{sticky} && exists($self->{data}->{ $self->{files}->{updates} })) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"sticky"} and exists $self->{"data"}{$self->{"files"}{"updates"}}
MC/DC0%0/2
$self->{"sticky"} and exists $self->{"data"}{$self->{"files"}{"updates"}}
$self->{"sticky"}
exists $self->{"data"}{$self->{"files"}{"updates"}}
Truth table0%0/3
A and B
A= $self->{"sticky"}B= exists $self->{"data"}{$self->{"files"}{"updates"}}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | $update = $self->{data}->{ $self->{files}->{updates} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | # retrieve information from storage | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | ▶ | $self->{logger} && $self->{logger}->debug("Load $file (update_error)"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | $update = retrieve($file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | $update->{next_update} = $time + $wait; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | $update->{last_udpate} = $time; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | $update->{errors} = $errors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | ▶ | nstore($update, $file) or croak("Cannot save data to $file: $!\n"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | ▶ | if ($self->{sticky}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | $self->{data}->{ $self->{files}->{updates} } = $update; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | sub get_prefixes { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_prefixes: not called CC=13 SCAR=52.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | ▶ | my @lists = @{ $args{lists} || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | ▶ | my @hashes = @{ $args{hashes} || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | my @data = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | ▶ | $self->{logger} && $self->{logger}->debug("Number of lists: ", scalar(@lists)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | foreach my $list (@lists) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | my $db = { }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | ▶ | if ($self->{sticky} && exists($self->{data}->{ $self->list_to_file($list) })) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"sticky"} and exists $self->{"data"}{$self->list_to_file($list)}
MC/DC0%0/2
$self->{"sticky"} and exists $self->{"data"}{$self->list_to_file($list)}
$self->{"sticky"}
exists $self->{"data"}{$self->list_to_file($list)}
Truth table0%0/3
A and B
A= $self->{"sticky"}B= exists $self->{"data"}{$self->list_to_file($list)}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | $db = $self->{data}->{ $self->list_to_file($list) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | my $file = path(join("/", $self->{path}, $self->list_to_file($list))); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | ▶ | if (! -e $file) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | ▶ | $self->{logger} && $self->{logger}->debug("File $file does not exist"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | ▶ | $self->{logger} && $self->{logger}->debug("Load $file (get_prefixes)"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | $db = retrieve($file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | ▶ | if ($self->{sticky}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | $self->{data}->{ $self->list_to_file($list) } = $db; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | foreach my $hash (@hashes) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | my $prefix = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | ▶ | my $index = binsearch {substr($a,0,length($b)) cmp $b} $hash, @{ $db->{hashes} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | ▶ | if (defined $index) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | $prefix = $db->{hashes}->[$index]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | push(@data, { prefix => $prefix, list => $list }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | return @data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | sub add_full_hashes { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_full_hashes: not called CC=11 SCAR=48.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | ▶ | my @hashes = @{ $args{hashes} || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | ▶ | my $timestamp = $args{timestamp} || time(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$args{'timestamp'} || time
MC/DC0%0/2
$args{'timestamp'} || time
$args{'timestamp'}
time
Truth table0%0/3
A || B
A= $args{'timestamp'}B= time
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | my $file = path(join("/", $self->{path}, $self->{files}->{full_hashes})); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | my $db = { hashes => [] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | ▶ | if ($self->{sticky} && exists($self->{data}->{ $self->{files}->{full_hashes} })) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$self->{"sticky"} and exists $self->{"data"}{$self->{"files"}{"full_hashes"}}
MC/DC0%0/2
$self->{"sticky"} and exists $self->{"data"}{$self->{"files"}{"full_hashes"}}
$self->{"sticky"}
exists $self->{"data"}{$self->{"files"}{"full_hashes"}}
Truth table0%0/3
A and B
A= $self->{"sticky"}B= exists $self->{"data"}{$self->{"files"}{"full_hashes"}}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | $db = $self->{data}->{ $self->{files}->{full_hashes} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | elsif (-e $file) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | $db = retrieve($file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | foreach my $hash (@hashes) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | my $cache = $hash->{cache}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | $cache =~ s/s//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | ▶ | $self->{logger} && $self->{logger}->debug("cache: $cache"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 0 | $hash->{expire} = $cache + $timestamp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | push(@{ $db->{hashes} }, $hash); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | ▶ | $self->{logger} && $self->{logger}->debug("Save ", scalar(@{ $db->{hashes} }), " full hashes to $file"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | ▶ | nstore($db, $file) or croak("Cannot save data to $file: $!\n"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | ▶ | if ($self->{sticky}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | $self->{data}->{ $self->{files}->{full_hashes} } = $db; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | return (@{ $db->{hashes} }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | sub get_full_hashes { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_full_hashes: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | ▶ | my @lists = @{ $args{lists} || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | ▶ | my $hash = $args{hash} || return (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$args{'hash'} || (return ())
MC/DC0%0/1
$args{'hash'} || (return ())
$args{'hash'}
Truth table0%0/2
A
A= $args{'hash'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | my $db = { }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | ▶ | if ($self->{sticky} && exists($self->{data}->{ $self->{files}->{full_hashes} })) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"sticky"} and exists $self->{"data"}{$self->{"files"}{"full_hashes"}}
MC/DC0%0/2
$self->{"sticky"} and exists $self->{"data"}{$self->{"files"}{"full_hashes"}}
$self->{"sticky"}
exists $self->{"data"}{$self->{"files"}{"full_hashes"}}
Truth table0%0/3
A and B
A= $self->{"sticky"}B= exists $self->{"data"}{$self->{"files"}{"full_hashes"}}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | $db = $self->{data}->{ $self->{files}->{full_hashes} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | my $file = path(join("/", $self->{path}, $self->{files}->{full_hashes})); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | ▶ | if (! -e $file) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | return (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | ▶ | $self->{logger} && $self->{logger}->debug("Load $file"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 0 | $db = retrieve($file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | my @hashes = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | ▶ | $self->{logger} && $self->{logger}->debug("Number of full hashes on file: ", scalar(@{ $db->{hashes} })); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | foreach my $list (@lists) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | my $result = first { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | $_->{hash} eq $hash && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | $_->{list}->{threatEntryType} eq $list->{threatEntryType} && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | $_->{list}->{threatType} eq $list->{threatType} && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | $_->{list}->{platformType} eq $list->{platformType} && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | $_->{expire} > time() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 0 | ▶ | } @{ $db->{hashes} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
Branch: 1 branch
Condition0%0/9
$_->{"hash"} eq $hash and $_->{"list"}{"threatEntryType"} eq $list->{"threatEntryType"} and $_->{"list"}{"threatType"} eq $list->{"threatType"} and $_->{"list"}{"platformType"} eq $list->{"platformType"}
$_->{"hash"} eq $hash and $_->{"list"}{"threatEntryType"} eq $list->{"threatEntryType"} and $_->{"list"}{"threatType"} eq $list->{"threatType"}
$_->{"hash"} eq $hash and $_->{"list"}{"threatEntryType"} eq $list->{"threatEntryType"}
MC/DC0%0/4
$_->{"hash"} eq $hash and $_->{"list"}{"threatEntryType"} eq $list->{"threatEntryType"} and $_->{"list"}{"threatType"} eq $list->{"threatType"} and $_->{"list"}{"platformType"} eq $list->{"platformType"}
$_->{"hash"} eq $hash
$_->{"list"}{"threatEntryType"} eq $list->{"threatEntryType"}
$_->{"list"}{"threatType"} eq $list->{"threatType"}
$_->{"list"}{"platformType"} eq $list->{"platformType"}
Truth table0%0/5
A and B and C and D
A= $_->{"hash"} eq $hashB= $_->{"list"}{"threatEntryType"} eq $list->{"threatEntryType"}C= $_->{"list"}{"threatType"} eq $list->{"threatType"}D= $_->{"list"}{"platformType"} eq $list->{"platformType"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | ▶ | push(@hashes, $result) if (defined($result)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | return @hashes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | sub list_to_file { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | ▶ | my ($self, $list) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list_to_file: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | return join("_", $list->{threatType}, $list->{platformType}, $list->{threatEntryType}) . ".gsb4"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | sub close { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 0 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
close: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | ▶ | if ($self->{keep_all} == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 0 | my $file = path(join("/", $self->{path}, $self->{files}->{full_hashes})); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 0 | ▶ | if (! -e $file) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 0 | my $db = retrieve($file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 0 | my @results = grep { $_->{expire} > time() } @{ $db->{hashes} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 0 | ▶ | if (scalar(@results) < scalar(@{ $db->{hashes} })) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 0 | $db->{hashes} = [@results]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 0 | ▶ | nstore($db, $file) or croak("Cannot save data to $file: $!\n"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 0 | $self->{data} = { }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | =head1 CHANGELOG | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | =item 0.1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | Initial release | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | See L<Net::Google::SafeBrowsing4> for handling Google Safe Browsing v4. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | See L<Net::Google::SafeBrowsing4::Storage> for the list of public functions. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | Google Safe Browsing v4 API: L<https://developers.google.com/safe-browsing/v4/> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | Julien Sobrier, E<lt>julien@sobrier.netE<gt> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | Copyright (C) 2016 by Julien Sobrier | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | This library is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | it under the same terms as Perl itself, either Perl version 5.8.8 or, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | at your option, any later version of Perl 5 you may have available. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||