Deduper/DB_File.pm

filter: Statementstmt 83.3% 10 / 12 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 87.5% 14 / 16 CC 1 SCAR 0.7
CC
1
Cov
83%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« Deduper/Role.pm ↑ Summary
1 package XML::Feed::Deduper::DB_File;
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 with 'XML::Feed::Deduper::Role';
6 0 ▶use DB_File;
Subroutine BEGIN: called CC=1 SCAR=2.6
7  
8 has path => (
9 is => 'rw',
10 isa => 'Str',
11 required => 1,
12 );
13  
14 has db => (
15 is => 'rw',
16 isa => 'DB_File',
17 lazy => 1,
18 default => sub {
19 my $self = shift;
20 ## no critic.
21 my $obj = tie my %cache, 'DB_File', $self->path, O_RDWR|O_CREAT, 0666, $DB_HASH or die "cannot open @{[ $self->path ]}";
22 $obj;
23 }
24 );
25  
26 no Mouse;
27  
28 sub find_entry {
29 my ( $self, $url ) = @_;
30  
31 my $status = $self->db->get( $url, my $value );
32 return if $status == 1; # not found
33  
34 return $value;
35 }
36  
37 sub create_entry {
38 my ( $self, $id, $digest ) = @_;
39 $self->db->put( $id, $digest );
40 $self->db->sync;
41 }
42  
43 1;
« Deduper/Role.pm ↑ Summary