| 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 ||= {}
MC/DC0%0/1
$opts ||= {}
$opts
Truth table50%1/2
A
A= $opts
| |||||||||||||||||||||||||||||
| 39 | 43 | $opts->{store} = $self; | |||||||||||||||||||||||||||
| 40 | 43 | ▶ | $opts->{name} = $name // $self->default_bag; | ||||||||||||||||||||||||||
|
Condition33%1/3
$name // $self->default_bag
MC/DC0%0/2
$name // $self->default_bag
$name
$self->default_bag
Truth table33%1/3
A // B
A= $nameB= $self->default_bag
| |||||||||||||||||||||||||||||
| 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"}} //= {}
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"}}
| |||||||||||||||||||||||||||||
| 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
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
| |||||||||||||||||||||||||||||
| 46 | 43 | my $default_plugins = $self->default_plugins; | |||||||||||||||||||||||||||
| 47 | 43 | ▶ | my $plugins = delete($opts->{plugins}) // []; | ||||||||||||||||||||||||||
|
Condition100%2/2
delete $opts->{"plugins"} // []
MC/DC100%1/1
delete $opts->{"plugins"} // []
delete $opts->{"plugins"}
Truth table100%2/2
A
A= delete $opts->{"plugins"}
| |||||||||||||||||||||||||||||
| 48 | 43 | ▶ | if (@$default_plugins || @$plugins) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@$default_plugins or @$plugins
MC/DC100%2/2
@$default_plugins or @$plugins
@$default_plugins
@$plugins
Truth table100%3/3
A or B
A= @$default_pluginsB= @$plugins
| |||||||||||||||||||||||||||||
| 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} ||= {}
MC/DC100%1/1
$bag_instances{$self} ||= {}
$bag_instances{$self}
Truth table100%2/2
A
A= $bag_instances{$self}
| |||||||||||||||||||||||||||||
| 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
MC/DC0%0/2
$name ||= $self->default_bag
$name
$self->default_bag
Truth table66%2/3
A ||= B
A= $nameB= $self->default_bag
| |||||||||||||||||||||||||||||
| 65 | 149 | ▶ | $self->bags->{$name} ||= $self->new_bag($name); | ||||||||||||||||||||||||||
|
Condition66%2/3
$self->bags->{$name} ||= $self->new_bag($name)
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)
| |||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 19 | 1; | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | __END__ | ||||||||||||||||||||||||||||