Ref/Util/LRU/Array.pm

filter: Statementstmt 100% 41 / 41 Branchbran 70.0% 7 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 3 totaltotal 90.7% 59 / 65 CC 6 SCAR 5.6
CC
6
Cov
94%
_filter
3.0
insert
2.0
remove
2.0
CRAP 1.8
« Ref/LRU.pm ↑ Summary Ref/Util/LRU/List.pm »
1 package Cache::Ref::Util::LRU::Array;
2 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 $Cache::Ref::Util::LRU::Array::AUTHORITY = 'cpan:NUFFIN';
4 }
5 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 $Cache::Ref::Util::LRU::Array::VERSION = '0.05'; # TRIAL
7 }
8 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use Scalar::Util qw(refaddr);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Hash::Util::FieldHash::Compat qw(id);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 has _list => (
16 traits => [qw(Array)],
17 isa => "ArrayRef",
18 2 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
19 1 is => "ro",
20 handles => {
21 #size => "length",
22 mru => [ get => 0 ],
23 lru => [ get => -1 ],
24 remove_mru => "shift",
25 remove_lru => "pop",
26 clear => "clear",
27 },
28 );
29  
30 1 with qw(Cache::Ref::Util::LRU::API);
31  
32 # since there's no need for metadata, insert is just like hit
33 1766 ▶sub insert {
Subroutine insert: called CC=2 SCAR=7.1
Pod undocumented
34 1766 my ( $self, @elements ) = @_;
35  
36 1766 $self->hit(@elements);
37  
38 1766 ▶ return ( @elements == 1 ? $elements[0] : @elements );
Branch: 1 branch
BranchTrueFalseTotal
@elements == 1 ? : 1766 0 1766
39 }
40  
41 3027 ▶sub _filter {
Subroutine _filter: called CC=3 SCAR=11.0
42 3027 my ( $self, $l, $elements ) = @_;
43  
44 3027 ▶ return () unless @$l;
Branch: 1 branch
BranchTrueFalseTotal
unless @$l 2 3025 3027
45  
46 3025 ▶ confess if grep { not defined } @$elements;
Branch: 1 branch
BranchTrueFalseTotal
if grep {not defined $_;} @$elements 0 3025 3025
47 3025 my %hash; @hash{map {id($_)} @$elements} = ();
48 3025 grep { not exists $hash{id($_)} } @$l;
49 }
50  
51 4792 ▶sub hit {
Subroutine hit: called CC=2 SCAR=6.9
Pod undocumented
52 4792 my ( $self, @elements ) = @_;
53  
54 4792 ▶ return unless @elements;
Branch: 1 branch
BranchTrueFalseTotal
unless @elements 1766 3026 4792
55  
56 3026 my $l = $self->_list;
57 3026 @$l = ( @elements, $self->_filter($l, \@elements) );
58  
59 3026 return;
60 }
61  
62 1 ▶sub remove {
Subroutine remove: called CC=2 SCAR=7.0
Pod undocumented
63 1 my ( $self, @elements ) = @_;
64  
65 1 ▶ return unless @elements;
Branch: 1 branch
BranchTrueFalseTotal
unless @elements 0 1 1
66  
67 1 my $l = $self->_list;
68 1 @$l = $self->_filter($l, \@elements);
69  
70 1 return;
71 }
72  
73 1 __PACKAGE__->meta->make_immutable;
74  
75 1 __PACKAGE__;
76  
77 # ex: set sw=4 et:
78  
79  
80 __END__
« Ref/LRU.pm ↑ Summary Ref/Util/LRU/List.pm »