| 1 | package Data::Zipper::API; | ||||||||||
| 2 | 3 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 3 | $Data::Zipper::API::VERSION = '0.02'; | |||||||||
| 4 | } | ||||||||||
| 5 | |||||||||||
| 6 | 3 | ▶ | use warnings FATAL => 'all'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 3 | ▶ | use MooseX::Role::Parameterized; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 3 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 3 | parameter 'type' => ( | |||||||||
| 11 | required => 1 | ||||||||||
| 12 | ); | ||||||||||
| 13 | |||||||||||
| 14 | 4 | ▶ | role { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | 3 | ▶ | use MooseX::Types::Moose qw( ArrayRef ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | |||||||||||
| 18 | 4 | my $params = shift; | |||||||||
| 19 | |||||||||||
| 20 | 4 | requires 'traverse', 'reconstruct'; | |||||||||
| 21 | |||||||||||
| 22 | has path => ( | ||||||||||
| 23 | is => 'bare', | ||||||||||
| 24 | isa => ArrayRef[ $params->type ], | ||||||||||
| 25 | 5 | ▶ | default => sub { [] }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 26 | 4 | traits => [ 'Array' ], | |||||||||
| 27 | handles => { | ||||||||||
| 28 | path => 'elements' | ||||||||||
| 29 | } | ||||||||||
| 30 | ); | ||||||||||
| 31 | |||||||||||
| 32 | 4 | has focus => ( | |||||||||
| 33 | is => 'ro', | ||||||||||
| 34 | required => 1 | ||||||||||
| 35 | ); | ||||||||||
| 36 | |||||||||||
| 37 | 8 | ▶ | around traverse => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 38 | 8 | my ($traverser, $self, @args) = @_; | |||||||||
| 39 | 8 | my ($focus, $path) = $self->$traverser(@args); | |||||||||
| 40 | 8 | return $self->meta->new_object( | |||||||||
| 41 | focus => $focus, | ||||||||||
| 42 | path => [ | ||||||||||
| 43 | $path, | ||||||||||
| 44 | $self->path | ||||||||||
| 45 | ] | ||||||||||
| 46 | ); | ||||||||||
| 47 | 4 | }; | |||||||||
| 48 | |||||||||||
| 49 | 6 | ▶ | sub set { | ||||||||
|
Subroutine
set: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 50 | 6 | my ($self, $new_value) = @_; | |||||||||
| 51 | 6 | return $self->meta->new_object( | |||||||||
| 52 | path => [ $self->path ], | ||||||||||
| 53 | focus => $new_value | ||||||||||
| 54 | ) | ||||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 1 | ▶ | sub set_via { | ||||||||
|
Subroutine
set_via: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 58 | 1 | my ($self, $code) = @_; | |||||||||
| 59 | 1 | local $_ = $self->focus; | |||||||||
| 60 | 1 | $self->set($code->($self->focus)); | |||||||||
| 61 | } | ||||||||||
| 62 | |||||||||||
| 63 | 8 | ▶ | sub up { | ||||||||
|
Subroutine
up: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 64 | 8 | my $self = shift; | |||||||||
| 65 | 8 | my ($path, @rest) = $self->path; | |||||||||
| 66 | 8 | return $self->meta->new_object( | |||||||||
| 67 | focus => $self->reconstruct($self->focus, $path), | ||||||||||
| 68 | path => \@rest | ||||||||||
| 69 | ); | ||||||||||
| 70 | } | ||||||||||
| 71 | |||||||||||
| 72 | 5 | ▶ | sub zip { | ||||||||
|
Subroutine
zip: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 73 | 5 | my $zipper = shift; | |||||||||
| 74 | |||||||||||
| 75 | 5 | ▶ | while ($zipper->path) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 76 | 6 | $zipper = $zipper->up; | |||||||||
| 77 | } | ||||||||||
| 78 | 5 | return $zipper->focus; | |||||||||
| 79 | } | ||||||||||
| 80 | |||||||||||
| 81 | 3 | }; | |||||||||
| 82 | |||||||||||
| 83 | 3 | 1; | |||||||||
| 84 | |||||||||||
| 85 | |||||||||||
| 86 | __END__ | ||||||||||