| 1 | package Catmandu::Fix::add_to_store; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use Catmandu::Sane; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 1 | our $VERSION = '1.2025'; | |||||||||
| 6 | |||||||||||
| 7 | 1 | ▶ | use Catmandu; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use Catmandu::Util::Path qw(as_path); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 1 | ▶ | use namespace::clean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 1 | ▶ | use Catmandu::Fix::Has; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 1 | has path => (fix_arg => 1); | |||||||||
| 14 | 1 | has store_name => (fix_arg => 1); | |||||||||
| 15 | 1 | has bag_name => (fix_opt => 1, init_arg => 'bag'); | |||||||||
| 16 | 1 | has store_args => (fix_opt => 'collect'); | |||||||||
| 17 | 1 | has store => (is => 'lazy', init_arg => undef); | |||||||||
| 18 | 1 | has bag => (is => 'lazy', init_arg => undef); | |||||||||
| 19 | |||||||||||
| 20 | 1 | with 'Catmandu::Fix::Builder'; | |||||||||
| 21 | |||||||||||
| 22 | 1 | ▶ | sub _build_store { | ||||||||
|
Subroutine
_build_store: called CC=1 SCAR=0.0
| |||||||||||
| 23 | 1 | my ($self) = @_; | |||||||||
| 24 | 1 | Catmandu->store($self->store_name, %{$self->store_args}); | |||||||||
| 25 | } | ||||||||||
| 26 | |||||||||||
| 27 | 1 | ▶ | sub _build_bag { | ||||||||
|
Subroutine
_build_bag: called CC=2 SCAR=7.2
| |||||||||||
| 28 | 1 | my ($self) = @_; | |||||||||
| 29 | 1 | ▶ | defined $self->bag_name | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | ? $self->store->bag($self->bag_name) | ||||||||||
| 31 | : $self->store->bag; | ||||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | 1 | ▶ | sub _build_fixer { | ||||||||
|
Subroutine
_build_fixer: called CC=1 SCAR=0.0
| |||||||||||
| 35 | 1 | my ($self) = @_; | |||||||||
| 36 | 1 | my $bag = $self->bag; | |||||||||
| 37 | 1 | my $getter = as_path($self->path)->getter; | |||||||||
| 38 | 1 | ▶ | sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||
| 39 | 1 | my $data = $_[0]; | |||||||||
| 40 | 1 | my $vals = $getter->($data); | |||||||||
| 41 | 1 | $bag->add($_) for @$vals; | |||||||||
| 42 | 1 | $data; | |||||||||
| 43 | 1 | }; | |||||||||
| 44 | } | ||||||||||
| 45 | |||||||||||
| 46 | 1 | 1; | |||||||||
| 47 | |||||||||||
| 48 | __END__ | ||||||||||