Catmandu/Store.pm

filter: Statementstmt 100% 56 / 56 Branchbran 100% 2 / 2 Conditioncond 69.5% 16 / 23 MC/DCmcdc 35.7% 5 / 14 Subroutinesub 100% 17 / 17 Podpod 75.0% 3 / 4 totaltotal 85.3% 99 / 116 CC 11 SCAR 12.4
CC
11
Cov
91%
new_bag
8.3
bag
3.1
bags
2.0
CRAP 3.5
« Catmandu/Fix/Inlineable.pm ↑ Summary Catmandu/CLI.pm »
1 package Catmandu::Store;
2  
3 19 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 19 our $VERSION = '1.2025';
6  
7 19 ▶use Hash::Util::FieldHash qw(fieldhash);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 19 ▶use Catmandu::Util qw(require_package);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 19 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 19 ▶use MooX::Aliases;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 19 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 19 with 'Catmandu::Logger';
14  
15 46 ▶has bag_class => (is => 'ro', default => sub {ref($_[0]) . '::Bag'},);
Subroutine __ANON__: called CC=1 SCAR=0.0
16  
17 19 has default_bag => (is => 'lazy');
18 48 ▶has default_plugins => (is => 'ro', default => sub {[]},);
Subroutine __ANON__: called CC=1 SCAR=0.0
19 48 ▶has default_options => (is => 'ro', default => sub {+{}},);
Subroutine __ANON__: called CC=1 SCAR=0.0
20 33 ▶has bag_options => (is => 'ro', init_arg => 'bags', default => sub {+{}},);
Subroutine __ANON__: called CC=1 SCAR=0.0
21 28 ▶has key_prefix => (is => 'lazy', default => sub {'_'},);
Subroutine __ANON__: called CC=1 SCAR=0.0
22 19 has id_key => (is => 'lazy', alias => 'id_field');
23  
24 30 ▶sub key_for {
Subroutine key_for: called CC=1 SCAR=0.0
Pod documented
25 30 $_[0]->key_prefix . $_[1];
26 }
27  
28 26 ▶sub _build_id_key {
Subroutine _build_id_key: called CC=1 SCAR=0.0
29 26 $_[0]->key_for('id');
30 }
31  
32 30 ▶sub _build_default_bag {
Subroutine _build_default_bag: called CC=1 SCAR=0.0
33 30 'data';
34 }
35  
36 43 ▶sub new_bag {
Subroutine new_bag: called CC=8 SCAR=21.2
Pod undocumented
37 43 my ($self, $name, $opts) = @_;
38 43 ▶ $opts ||= {};
Condition50%1/2
$opts ||= {}
l!l
043
MC/DC0%0/1
$opts ||= {}
$opts
Truth table50%1/2
A
A= $opts
Aresult
11
00
39 43 $opts->{store} = $self;
40 43 ▶ $opts->{name} = $name // $self->default_bag;
Condition33%1/3
$name // $self->default_bag
l!l&&r!l&&!r
4300
MC/DC0%0/2
$name // $self->default_bag
$name $self->default_bag
Truth table33%1/3
A // B
A= $nameB= $self->default_bag
ABresult
1X1
011
000
41 43 my $default_opts = $self->default_options;
42 43 ▶ my $bag_opts = $self->bag_options->{$opts->{name}} //= {};
Condition100%2/2
$self->bag_options->{$opts->{"name"}} //= {}
l!l
1726
MC/DC100%1/1
$self->bag_options->{$opts->{"name"}} //= {}
$self->bag_options->{$opts->{"name"}}
Truth table100%2/2
A
A= $self->bag_options->{$opts->{"name"}}
Aresult
11
00
43 43 $opts = {%$default_opts, %$bag_opts, %$opts};
44  
45 43 ▶ my $pkg = require_package(delete($opts->{class}) // $self->bag_class);
Condition33%1/3
delete $opts->{"class"} // $self->bag_class
l!l&&r!l&&!r
0430
MC/DC0%0/2
delete $opts->{"class"} // $self->bag_class
delete $opts->{"class"} $self->bag_class
Truth table33%1/3
A // B
A= delete $opts->{"class"}B= $self->bag_class
ABresult
1X1
011
000
46 43 my $default_plugins = $self->default_plugins;
47 43 ▶ my $plugins = delete($opts->{plugins}) // [];
Condition100%2/2
delete $opts->{"plugins"} // []
l!l
1330
MC/DC100%1/1
delete $opts->{"plugins"} // []
delete $opts->{"plugins"}
Truth table100%2/2
A
A= delete $opts->{"plugins"}
Aresult
11
00
48 43 ▶ if (@$default_plugins || @$plugins) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$default_plugins or @$plugins) 14 29 43
Condition100%3/3
@$default_plugins or @$plugins
l!l&&r!l&&!r
21229
MC/DC100%2/2
@$default_plugins or @$plugins
@$default_plugins @$plugins
Truth table100%3/3
A or B
A= @$default_pluginsB= @$plugins
ABresult
1X1
011
000
49 14 $pkg = $pkg->with_plugins(@$default_plugins, @$plugins);
50 }
51 43 $pkg->new($opts);
52 }
53  
54 {
55 19 fieldhash my %bag_instances;
56  
57 149 ▶ sub bags {
Subroutine bags: called CC=2 SCAR=6.9
Pod documented
58 149 my ($self) = @_;
59 149 ▶ $bag_instances{$self} ||= {};
Condition100%2/2
$bag_instances{$self} ||= {}
l!l
11237
MC/DC100%1/1
$bag_instances{$self} ||= {}
$bag_instances{$self}
Truth table100%2/2
A
A= $bag_instances{$self}
Aresult
11
00
60 }
61  
62 149 ▶ sub bag {
Subroutine bag: called CC=3 SCAR=11.3
Pod documented
63 149 my ($self, $name) = @_;
64 149 ▶ $name ||= $self->default_bag;
Condition66%2/3
$name ||= $self->default_bag
l!l&&r!l&&!r
391100
MC/DC0%0/2
$name ||= $self->default_bag
$name $self->default_bag
Truth table66%2/3
A ||= B
A= $nameB= $self->default_bag
ABresult
1X1
011
000
65 149 ▶ $self->bags->{$name} ||= $self->new_bag($name);
Condition66%2/3
$self->bags->{$name} ||= $self->new_bag($name)
l!l&&r!l&&!r
106430
MC/DC0%0/2
$self->bags->{$name} ||= $self->new_bag($name)
$self->bags->{$name} $self->new_bag($name)
Truth table66%2/3
A ||= B
A= $self->bags->{$name}B= $self->new_bag($name)
ABresult
1X1
011
000
66 }
67 }
68  
69 19 1;
70  
71 __END__
« Catmandu/Fix/Inlineable.pm ↑ Summary Catmandu/CLI.pm »