blib/lib/Catmandu/Store/Hash.pm

filter: Statementstmt 86.2% 25 / 29 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 87.5% 7 / 8 Podpod 0.0% 0 / 2 totaltotal 82.9% 34 / 41 CC 4 SCAR 9.0
CC
4
Cov
87%
drop
6.0
BUILD
3.0
BEGIN
1.0
CRAP 2.5
« blib/lib/Catmandu/Store/Hash/Bag.pm ↑ Summary blib/lib/Catmandu/Fix/log.pm »
1 package Catmandu::Store::Hash;
2  
3 13 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 13 our $VERSION = '1.0201_02';
6  
7 13 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 13 ▶use Catmandu::Util qw(:is);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 13 ▶use Catmandu::Store::Hash::Bag;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 13 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 13 with 'Catmandu::Store';
13 13 with 'Catmandu::Droppable';
14  
15 has _hashes =>
16 15 ▶ (is => 'ro', lazy => 1, init_arg => undef, default => sub {+{}});
Subroutine __ANON__: called CC=1 SCAR=0.0
17 13 has init_data => (is => 'ro');
18  
19 sub BUILD {
20 20 ▶ my ($self) = @_;
Subroutine BUILD: called CC=3 SCAR=11.0
Pod undocumented
21 20 ▶ if (my $data = $self->init_data) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $data = $self->init_data) 4 16 20
22 4 $self->bag->add($_) for @$data;
23 }
24 }
25  
26 sub drop {
27 0 ▶ my ($self) = @_;
Subroutine drop: not called CC=2 SCAR=17.9
Pod undocumented
28 0 $_->drop for values %{$self->bags};
29 0 return;
30 }
31  
32 13 1;
33  
34 __END__
35  
36 =pod
37  
38 =head1 NAME
39  
40 Catmandu::Store::Hash - An in-memory store
41  
42 =head1 SYNOPSIS
43  
44 use Catmandu::Store::Hash;
45  
46 my $store = Catmandu::Store::Hash->new();
47  
48 my $obj1 = $store->bag->add({ name => 'Patrick' });
49  
50 printf "obj1 stored as %s\n" , $obj1->{_id};
51  
52 # Force an id in the store
53 my $obj2 = $store->bag->add({ _id => 'test123' , name => 'Nicolas' });
54  
55 my $obj3 = $store->bag->get('test123');
56  
57 $store->bag->delete('test123');
58  
59 $store->bag->delete_all;
60  
61 # All bags are iterators
62 $store->bag->each(sub { ... });
63 $store->bag->take(10)->each(sub { ... });
64  
65 =head1 DESCRIPTION
66  
67 A Catmandu::Store::Hash is an in-memory L<Catmandu::Store> backed by a hash
68 for fast retrieval combined with a doubly linked list for fast traversal.
69  
70 =head1 METHODS
71  
72 =head2 new([init_data => [...] ])
73  
74 Create a new Catmandu::Store::Hash. Optionally provide as init_data an array
75 ref of data:
76  
77 my $store = Catmandu->store('Hash', init_data => [
78 { _id => 1, data => foo } ,
79 { _id => 2, data => bar }
80 ]);
81  
82 # or in a catmandu.yml configuration file:
83
84 ---
85 store:
86 hash:
87 package: Hash
88 options:
89 init_data:
90 - _id: 1
91 data: foo
92 - _id: 2
93 data: bar
94  
95 =head2 bag($name)
96  
97 Create or retieve a bag with name $name. Returns a Catmandu::Bag.
98  
99 =head1 SEE ALSO
100  
101 L<Catmandu::Bag>, L<Catmandu::Searchable>
102  
103 =cut
« blib/lib/Catmandu/Store/Hash/Bag.pm ↑ Summary blib/lib/Catmandu/Fix/log.pm »