| 1 | package PDL::Role::Enumerable; | ||
| 2 | 17 | $PDL::Role::Enumerable::VERSION = '0.006005'; | |
| 3 | 17 | ▶ | use 5.010; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 17 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 17 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | |||
| 7 | 17 | ▶ | use failures qw/levels::number/; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | |||
| 9 | 17 | ▶ | use Role::Tiny; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | 17 | ▶ | use Safe::Isa; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | 17 | ▶ | use List::AllUtils (); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 12 | |||
| 13 | 17 | with qw(PDL::Role::Stringifiable); | |
| 14 | |||
| 15 | 17 | requires 'levels'; | |
| 16 | |||
| 17 | 4 | ▶ | sub element_stringify_max_width { |
|
Subroutine
element_stringify_max_width: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 18 | 4 | my ($self, $element) = @_; | |
| 19 | 4 | my @where_levels = @{ $self->{PDL}->uniq->unpdl }; | |
| 20 | 4 | my @which_levels = @{ $self->levels }[@where_levels]; | |
| 21 | 4 | my @lengths = map { length $_ } @which_levels; | |
| 22 | 4 | List::AllUtils::max( @lengths ); | |
| 23 | } | ||
| 24 | |||
| 25 | 48 | ▶ | sub element_stringify { |
|
Subroutine
element_stringify: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 26 | 48 | my ($self, $element) = @_; | |
| 27 | 48 | $self->levels->[ $element ]; | |
| 28 | } | ||
| 29 | |||
| 30 | 4 | ▶ | sub number_of_levels { |
|
Subroutine
number_of_levels: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 31 | 4 | my ($self) = @_; | |
| 32 | 4 | return scalar( @{ $self->levels } ); | |
| 33 | } | ||
| 34 | |||
| 35 | 2 | ▶ | sub uniq { |
|
Subroutine
uniq: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 36 | 2 | my $self = shift; | |
| 37 | 2 | my $class = ref($self); | |
| 38 | |||
| 39 | 2 | my $new = $class->new( $self->levels, levels => $self->levels ); | |
| 40 | 2 | $new->{PDL} = $self->{PDL}->uniq; | |
| 41 | 2 | return $new; | |
| 42 | } | ||
| 43 | |||
| 44 | 87 | ▶ | around qw(slice dice) => sub { |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 45 | 87 | my $orig = shift; | |
| 46 | 87 | my $self = shift; | |
| 47 | 87 | my $class = ref($self); | |
| 48 | |||
| 49 | 87 | my $pdl = $self->{PDL}->$orig(@_); | |
| 50 | 87 | my $ret = bless( { PDL => $pdl }, $class ); | |
| 51 | |||
| 52 | # TODO levels needs to be copied | ||
| 53 | 87 | $ret->levels( $self->levels ); | |
| 54 | 87 | return $ret; | |
| 55 | 17 | }; | |
| 56 | |||
| 57 | 17 | 1; | |
| 58 | |||
| 59 | __END__ | ||