| 1 | package Manipulator; | ||||||||||||||||||
| 2 | 2 | ▶ | use 5.006; use strict; use warnings; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 3 | 2 | our $VERSION = '0.01'; | |||||||||||||||||
| 4 | 2 | ▶ | use overload '&{}' => 'engage'; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 5 | 2 | ▶ | use Tie::IxHash; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 6 | 2 | ▶ | use base 'Import::Export'; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 7 | |||||||||||||||||||
| 8 | 2 | our %EX = ( | |||||||||||||||||
| 9 | manipulate => [qw/all/], | ||||||||||||||||||
| 10 | ); | ||||||||||||||||||
| 11 | |||||||||||||||||||
| 12 | sub manipulate { | ||||||||||||||||||
| 13 | my (%args) = (scalar @_ > 1 | ||||||||||||||||||
| 14 | ? @_ | ||||||||||||||||||
| 15 | : ref $_[0] eq 'CODE' | ||||||||||||||||||
| 16 | ? (code => $_[0]) | ||||||||||||||||||
| 17 | : ref $_[0] eq 'HASH' | ||||||||||||||||||
| 18 | 0 | ? %{ $_[0] } | |||||||||||||||||
| 19 | 2 | ▶ | : @{ $_[0] } | ||||||||||||||||
|
Subroutine
manipulate: called CC=4 SCAR=16.9
Pod
undocumented
Branch: 3 branches
| |||||||||||||||||||
| 20 | ); | ||||||||||||||||||
| 21 | 2 | bless \%args, __PACKAGE__; | |||||||||||||||||
| 22 | } | ||||||||||||||||||
| 23 | |||||||||||||||||||
| 24 | sub engage { | ||||||||||||||||||
| 25 | 3 | ▶ | my ($self) = shift; | ||||||||||||||||
|
Subroutine
engage: called CC=1 SCAR=0.1
Pod
undocumented
| |||||||||||||||||||
| 26 | return sub { | ||||||||||||||||||
| 27 | 3 | ▶ | my (@params) = @_; | ||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.7
| |||||||||||||||||||
| 28 | |||||||||||||||||||
| 29 | 3 | ▶ | if (scalar @params == 1) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 30 | 0 | my $hash = shift @params; | |||||||||||||||||
| 31 | 0 | @params = map {($_, $hash->{$_})} sort { $a <=> $b } keys %{$hash}; | |||||||||||||||||
| 32 | } | ||||||||||||||||||
| 33 | |||||||||||||||||||
| 34 | 3 | ▶ | if (scalar keys %{$self} > 1) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 35 | 2 | ▶ | for (my $i = 0; $i < scalar @params; $i += 2) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 36 | 4 | my ($key, $value) = ($params[$i], $params[$i + 1]); | |||||||||||||||||
| 37 | 4 | $params[$i + 1] = $self->{$key}->($value); | |||||||||||||||||
| 38 | } | ||||||||||||||||||
| 39 | } else { | ||||||||||||||||||
| 40 | 1 | ▶ | for (my $i = 0; $i < scalar @params; $i++) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 41 | 4 | $params[$i] = $self->{code}->($params[$i]); | |||||||||||||||||
| 42 | } | ||||||||||||||||||
| 43 | } | ||||||||||||||||||
| 44 | |||||||||||||||||||
| 45 | 3 | ▶ | return wantarray ? @params : {@params}; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 46 | 3 | }; | |||||||||||||||||
| 47 | } | ||||||||||||||||||
| 48 | |||||||||||||||||||
| 49 | sub ordered { | ||||||||||||||||||
| 50 | 1 | ▶ | my ($self, @params) = @_; | ||||||||||||||||
|
Subroutine
ordered: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||
| 51 | 1 | my @data = $self->(@params); | |||||||||||||||||
| 52 | 1 | my %out; tie %out, 'Tie::IxHash', @data; | |||||||||||||||||
| 53 | 1 | ▶ | return wantarray ? %out : \%out; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 54 | } | ||||||||||||||||||
| 55 | |||||||||||||||||||
| 56 | 2 | 1; | |||||||||||||||||
| 57 | |||||||||||||||||||
| 58 | __END__ | ||||||||||||||||||