| 1 | package NG::Array; | ||||||||||||
| 2 | |||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 1 | ▶ | use base qw(NG::Object); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 1 | ▶ | use NG::Hashtable; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 1 | ▶ | use List::Util; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | |||||||||||||
| 9 | 0 | ▶ | sub new { | ||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 10 | 0 | my $pkg = shift; | |||||||||||
| 11 | 0 | my @args = @_; | |||||||||||
| 12 | 0 | return bless \@args, $pkg; | |||||||||||
| 13 | } | ||||||||||||
| 14 | |||||||||||||
| 15 | 0 | ▶ | sub each { | ||||||||||
|
Subroutine
each: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 16 | 0 | my ( $self, $sub ) = @_; | |||||||||||
| 17 | 0 | for my $i ( 0 .. scalar(@$self) - 1 ) { | |||||||||||
| 18 | 0 | $sub->( $self->[$i], $i ); | |||||||||||
| 19 | } | ||||||||||||
| 20 | 0 | return $self; | |||||||||||
| 21 | } | ||||||||||||
| 22 | |||||||||||||
| 23 | 0 | ▶ | sub pop { | ||||||||||
|
Subroutine
pop: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 24 | 0 | my ($self) = @_; | |||||||||||
| 25 | 0 | return pop @$self; | |||||||||||
| 26 | } | ||||||||||||
| 27 | |||||||||||||
| 28 | 0 | ▶ | sub push { | ||||||||||
|
Subroutine
push: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 29 | 0 | my ( $self, $value ) = @_; | |||||||||||
| 30 | 0 | push @$self, $value; | |||||||||||
| 31 | 0 | return $self; | |||||||||||
| 32 | } | ||||||||||||
| 33 | |||||||||||||
| 34 | 0 | ▶ | sub shift { | ||||||||||
|
Subroutine
shift: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 35 | 0 | my ($self) = @_; | |||||||||||
| 36 | 0 | return shift @$self; | |||||||||||
| 37 | } | ||||||||||||
| 38 | |||||||||||||
| 39 | 0 | ▶ | sub unshift { | ||||||||||
|
Subroutine
unshift: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 40 | 0 | my ( $self, $value ) = @_; | |||||||||||
| 41 | 0 | unshift @$self, $value; | |||||||||||
| 42 | 0 | return $self; | |||||||||||
| 43 | } | ||||||||||||
| 44 | |||||||||||||
| 45 | 0 | ▶ | sub sort { | ||||||||||
|
Subroutine
sort: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 46 | 0 | my ( $self, $sub ) = @_; | |||||||||||
| 47 | 0 | my @tmp; | |||||||||||
| 48 | 0 | ▶ | if ( defined $sub ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 49 | 0 | @tmp = sort { $sub->( $a, $b ) } @$self; | |||||||||||
| 50 | } | ||||||||||||
| 51 | else { | ||||||||||||
| 52 | 0 | @tmp = sort @$self; | |||||||||||
| 53 | } | ||||||||||||
| 54 | 0 | return NG::Array->new(@tmp); | |||||||||||
| 55 | } | ||||||||||||
| 56 | |||||||||||||
| 57 | 0 | ▶ | sub size { | ||||||||||
|
Subroutine
size: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 58 | 0 | my ($self) = @_; | |||||||||||
| 59 | 0 | return scalar(@$self); | |||||||||||
| 60 | } | ||||||||||||
| 61 | |||||||||||||
| 62 | 0 | ▶ | sub get { | ||||||||||
|
Subroutine
get: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 63 | 0 | my ( $self, $index ) = @_; | |||||||||||
| 64 | 0 | return $self->[$index]; | |||||||||||
| 65 | } | ||||||||||||
| 66 | |||||||||||||
| 67 | 0 | ▶ | sub join { | ||||||||||
|
Subroutine
join: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 68 | 0 | my ( $self, $expr ) = @_; | |||||||||||
| 69 | 0 | return join( $expr, @$self ); | |||||||||||
| 70 | } | ||||||||||||
| 71 | |||||||||||||
| 72 | 0 | ▶ | sub to_hash { | ||||||||||
|
Subroutine
to_hash: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 73 | 0 | my ($self) = @_; | |||||||||||
| 74 | 0 | return NG::Hashtable->new(@$self); | |||||||||||
| 75 | } | ||||||||||||
| 76 | |||||||||||||
| 77 | 0 | ▶ | sub zip { | ||||||||||
|
Subroutine
zip: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||
| 78 | 0 | my ( $self, @arrs ) = @_; | |||||||||||
| 79 | 0 | my $tmp = NG::Array->new; | |||||||||||
| 80 | 0 | my $size = NG::Array->new; | |||||||||||
| 81 | 0 | $size->push($_->size) for @_; | |||||||||||
| 82 | 0 | for my $i ( 0 .. $size->max - 1 ) { | |||||||||||
| 83 | 0 | ▶ | $tmp->push($_->get($i) || '') for @_; | ||||||||||
|
Condition0%0/2
$_->get($i) || ''
MC/DC0%0/1
$_->get($i) || ''
$_->get($i)
Truth table0%0/2
A
A= $_->get($i)
| |||||||||||||
| 84 | } | ||||||||||||
| 85 | 0 | return $tmp; | |||||||||||
| 86 | } | ||||||||||||
| 87 | |||||||||||||
| 88 | 0 | ▶ | sub uniq { | ||||||||||
|
Subroutine
uniq: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 89 | 0 | my ($self) = @_; | |||||||||||
| 90 | 0 | my %seen; | |||||||||||
| 91 | 0 | ▶ | return $self->grep(sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 92 | 0 | not $seen{$_}++; | |||||||||||
| 93 | 0 | }); | |||||||||||
| 94 | } | ||||||||||||
| 95 | |||||||||||||
| 96 | 0 | ▶ | sub reduce { | ||||||||||
|
Subroutine
reduce: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 97 | 0 | my ( $self, $sub ) = @_; | |||||||||||
| 98 | 0 | return reduce { $sub->($a, $b) } @$self; | |||||||||||
| 99 | } | ||||||||||||
| 100 | |||||||||||||
| 101 | 0 | ▶ | sub grep { | ||||||||||
|
Subroutine
grep: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 102 | 0 | my ( $self, $sub ) = @_; | |||||||||||
| 103 | 0 | return NG::Array->new( grep { $sub->($_) } @$self ); | |||||||||||
| 104 | } | ||||||||||||
| 105 | |||||||||||||
| 106 | 0 | ▶ | sub map { | ||||||||||
|
Subroutine
map: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 107 | 0 | my ( $self, $sub ) = @_; | |||||||||||
| 108 | 0 | return NG::Array->new( map { $sub->($_) } @$self ); | |||||||||||
| 109 | } | ||||||||||||
| 110 | |||||||||||||
| 111 | 0 | ▶ | sub max { | ||||||||||
|
Subroutine
max: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 112 | 0 | my ($self) = @_; | |||||||||||
| 113 | 0 | return List::Util::max( @$self ); | |||||||||||
| 114 | } | ||||||||||||
| 115 | |||||||||||||
| 116 | 0 | ▶ | sub min { | ||||||||||
|
Subroutine
min: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 117 | 0 | my ($self) = @_; | |||||||||||
| 118 | 0 | return List::Util::min( @$self ); | |||||||||||
| 119 | } | ||||||||||||
| 120 | |||||||||||||
| 121 | 1 | 1; | |||||||||||