| 1 | package MouseX::NativeTraits::MethodProvider::ArrayRef; | ||||||||||||||||||||||||||||
| 2 | 9 | ▶ | use Mouse; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 9 | ▶ | use Mouse::Util::TypeConstraints (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 9 | ▶ | use List::Util (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 9 | extends qw(MouseX::NativeTraits::MethodProvider); | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 6 | ▶ | sub generate_count { | ||||||||||||||||||||||||||
|
Subroutine
generate_count: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 10 | 6 | my($self) = @_; | |||||||||||||||||||||||||||
| 11 | 6 | my $reader = $self->reader; | |||||||||||||||||||||||||||
| 12 | 22 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 13 | 22 | ▶ | if(@_ != 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 14 | 10 | $self->argument_error('count', 1, 1, scalar @_); | |||||||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||||||||
| 16 | 12 | return scalar @{ $reader->( $_[0] ) }; | |||||||||||||||||||||||||||
| 17 | 6 | }; | |||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 6 | ▶ | sub generate_is_empty { | ||||||||||||||||||||||||||
|
Subroutine
generate_is_empty: called CC=1 SCAR=0.6
Pod
documented
| |||||||||||||||||||||||||||||
| 21 | 6 | my($self) = @_; | |||||||||||||||||||||||||||
| 22 | 6 | my $reader = $self->reader; | |||||||||||||||||||||||||||
| 23 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=9.2
Subroutine
stack_is_empty: called CC=2 SCAR=9.2
| |||||||||||||||||||||||||||||
| 24 | 0 | ▶ | if(@_ != 1) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 25 | 0 | $self->argument_error('is_empty', 1, 1, scalar @_); | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | 0 | return scalar(@{ $reader->( $_[0] ) }) == 0; | |||||||||||||||||||||||||||
| 28 | 6 | }; | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 10 | ▶ | sub generate_first { | ||||||||||||||||||||||||||
|
Subroutine
generate_first: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 32 | 10 | my($self) = @_; | |||||||||||||||||||||||||||
| 33 | 10 | my $reader = $self->reader; | |||||||||||||||||||||||||||
| 34 | 60 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 35 | 60 | my ( $instance, $block ) = @_; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 60 | ▶ | if(@_ != 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 30 | $self->argument_error('first', 2, 2, scalar @_); | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 30 | ▶ | Mouse::Util::TypeConstraints::CodeRef($block) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | or $instance->meta->throw_error( | ||||||||||||||||||||||||||||
| 43 | "The argument passed to first must be a code reference"); | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 20 | return List::Util::first(\&{$block}, @{ $reader->($instance) }); | |||||||||||||||||||||||||||
| 46 | 10 | }; | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 1 | ▶ | sub generate_any { | ||||||||||||||||||||||||||
|
Subroutine
generate_any: called CC=1 SCAR=0.1
Pod
documented
| |||||||||||||||||||||||||||||
| 50 | 1 | my($self) = @_; | |||||||||||||||||||||||||||
| 51 | 1 | my $reader = $self->reader; | |||||||||||||||||||||||||||
| 52 | 1 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=17.0
| |||||||||||||||||||||||||||||
| 53 | 1 | my ( $instance, $block ) = @_; | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 1 | ▶ | if(@_ != 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 0 | $self->argument_error('any', 2, 2, scalar @_); | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 1 | ▶ | Mouse::Util::TypeConstraints::CodeRef($block) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | or $instance->meta->throw_error( | ||||||||||||||||||||||||||||
| 61 | "The argument passed to any must be a code reference"); | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 1 | foreach (@{ $reader->($instance) }){ | |||||||||||||||||||||||||||
| 64 | 3 | ▶ | if($block->($_)){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 1 | return 1; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | 0 | return 0; | |||||||||||||||||||||||||||
| 69 | 1 | }; | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 1 | ▶ | sub generate_apply { | ||||||||||||||||||||||||||
|
Subroutine
generate_apply: called CC=1 SCAR=4.3
Pod
documented
| |||||||||||||||||||||||||||||
| 73 | 1 | my($self) = @_; | |||||||||||||||||||||||||||
| 74 | 1 | my $reader = $self->reader; | |||||||||||||||||||||||||||
| 75 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 76 | 0 | my ( $instance, $block ) = @_; | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 0 | ▶ | if(@_ != 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 0 | $self->argument_error('apply', 2, 2, scalar @_); | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | ▶ | Mouse::Util::TypeConstraints::CodeRef($block) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | or $instance->meta->throw_error( | ||||||||||||||||||||||||||||
| 84 | "The argument passed to apply must be a code reference"); | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 0 | my @values = @{ $reader->($instance) }; | |||||||||||||||||||||||||||
| 87 | 0 | foreach (@values){ | |||||||||||||||||||||||||||
| 88 | 0 | $block->(); | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | 0 | return @values; | |||||||||||||||||||||||||||
| 91 | 1 | }; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 11 | ▶ | sub generate_map { | ||||||||||||||||||||||||||
|
Subroutine
generate_map: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 95 | 11 | my($self) = @_; | |||||||||||||||||||||||||||
| 96 | 11 | my $reader = $self->reader; | |||||||||||||||||||||||||||
| 97 | 62 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 98 | 62 | my ( $instance, $block ) = @_; | |||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 62 | ▶ | if(@_ != 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | 30 | $self->argument_error('map', 2, 2, scalar @_); | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 32 | ▶ | Mouse::Util::TypeConstraints::CodeRef($block) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | or $instance->meta->throw_error( | ||||||||||||||||||||||||||||
| 106 | "The argument passed to map must be a code reference"); | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 22 | return map { $block->() } @{ $reader->($instance) }; | |||||||||||||||||||||||||||
| 109 | 11 | }; | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 10 | ▶ | sub generate_reduce { | ||||||||||||||||||||||||||
|
Subroutine
generate_reduce: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 113 | 10 | my($self) = @_; | |||||||||||||||||||||||||||
| 114 | 10 | my $reader = $self->reader; | |||||||||||||||||||||||||||
| 115 | 60 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 116 | 60 | my ( $instance, $block ) = @_; | |||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 60 | ▶ | if(@_ != 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | 30 | $self->argument_error('reduce', 2, 2, scalar @_); | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 30 | ▶ | Mouse::Util::TypeConstraints::CodeRef($block) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | or $instance->meta->throw_error( | ||||||||||||||||||||||||||||
| 124 | "The argument passed to reduce must be a code reference"); | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 20 | our ($a, $b); | |||||||||||||||||||||||||||
| 127 | 20 | ▶ | return List::Util::reduce { $block->($a, $b) } @{ $reader->($instance) }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 128 | 10 | }; | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 10 | ▶ | sub generate_sort { | ||||||||||||||||||||||||||
|
Subroutine
generate_sort: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 132 | 10 | my($self) = @_; | |||||||||||||||||||||||||||
| 133 | 10 | my $reader = $self->reader; | |||||||||||||||||||||||||||
| 134 | 40 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 135 | 40 | my ( $instance, $block ) = @_; | |||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 40 | ▶ | if(@_ < 1 or @_ > 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@_ < 1 or @_ > 2
MC/DC50%1/2
@_ < 1 or @_ > 2
@_ < 1
@_ > 2
Truth table66%2/3
A or B
A= @_ < 1B= @_ > 2
| |||||||||||||||||||||||||||||
| 138 | 10 | $self->argument_error('sort', 1, 2, scalar @_); | |||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 30 | ▶ | if (defined $block) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 142 | 20 | ▶ | Mouse::Util::TypeConstraints::CodeRef($block) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 143 | or $instance->meta->throw_error( | ||||||||||||||||||||||||||||
| 144 | "The argument passed to sort must be a code reference"); | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 10 | return sort { $block->( $a, $b ) } @{ $reader->($instance) }; | |||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | else { | ||||||||||||||||||||||||||||
| 149 | 10 | return sort @{ $reader->($instance) }; | |||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | 10 | }; | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 10 | ▶ | sub generate_sort_in_place { | ||||||||||||||||||||||||||
|
Subroutine
generate_sort_in_place: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 155 | 10 | my($self) = @_; | |||||||||||||||||||||||||||
| 156 | 10 | my $reader = $self->reader; | |||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 60 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 159 | 60 | my ( $instance, $block ) = @_; | |||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 60 | ▶ | if(@_ < 1 or @_ > 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@_ < 1 or @_ > 2
MC/DC50%1/2
@_ < 1 or @_ > 2
@_ < 1
@_ > 2
Truth table66%2/3
A or B
A= @_ < 1B= @_ > 2
| |||||||||||||||||||||||||||||
| 162 | 20 | $self->argument_error('sort_in_place', 1, 2, scalar @_); | |||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 40 | my $array_ref = $reader->($instance); | |||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | 40 | ▶ | if(defined $block){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 168 | 30 | ▶ | Mouse::Util::TypeConstraints::CodeRef($block) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 169 | or $instance->meta->throw_error( | ||||||||||||||||||||||||||||
| 170 | "The argument passed to sort_in_place must be a code reference"); | ||||||||||||||||||||||||||||
| 171 | 20 | @{$array_ref} = sort { $block->($a, $b) } @{$array_ref}; | |||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||
| 173 | else{ | ||||||||||||||||||||||||||||
| 174 | 10 | @{$array_ref} = sort @{$array_ref}; | |||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 30 | return $instance; | |||||||||||||||||||||||||||
| 178 | 10 | }; | |||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | # The sort_by algorithm comes from perlfunc/sort | ||||||||||||||||||||||||||||
| 183 | # See also perldoc -f sort and perldoc -q sort | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | 1 | ▶ | sub generate_sort_by { | ||||||||||||||||||||||||||
|
Subroutine
generate_sort_by: called CC=1 SCAR=0.3
Pod
documented
| |||||||||||||||||||||||||||||
| 186 | 1 | my($self) = @_; | |||||||||||||||||||||||||||
| 187 | 1 | my $reader = $self->reader; | |||||||||||||||||||||||||||
| 188 | 1 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=18.2
| |||||||||||||||||||||||||||||
| 189 | 1 | my ( $instance, $block, $compare ) = @_; | |||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | 1 | ▶ | if(@_ < 1 or @_ > 3) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ < 1 or @_ > 3
MC/DC0%0/2
@_ < 1 or @_ > 3
@_ < 1
@_ > 3
Truth table33%1/3
A or B
A= @_ < 1B= @_ > 3
| |||||||||||||||||||||||||||||
| 192 | 0 | $self->argument_error('sort_by', 1, 3, scalar @_); | |||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | 1 | my $array_ref = $reader->($instance); | |||||||||||||||||||||||||||
| 196 | 1 | my @idx; | |||||||||||||||||||||||||||
| 197 | 1 | foreach (@{$array_ref}){ # intentinal use of $_ | |||||||||||||||||||||||||||
| 198 | 3 | push @idx, scalar $block->($_); | |||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | # NOTE: scalar(@idx)-1 is faster than $#idx | ||||||||||||||||||||||||||||
| 202 | 1 | ▶ | if($compare){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 203 | 1 | return @{ $array_ref }[ | |||||||||||||||||||||||||||
| 204 | 1 | sort { $compare->($idx[$a], $idx[$b]) } | |||||||||||||||||||||||||||
| 205 | 0 .. scalar(@idx)-1 | ||||||||||||||||||||||||||||
| 206 | ]; | ||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||
| 208 | else{ | ||||||||||||||||||||||||||||
| 209 | 0 | return @{ $array_ref }[ | |||||||||||||||||||||||||||
| 210 | 0 | sort { $idx[$a] cmp $idx[$b] } | |||||||||||||||||||||||||||
| 211 | 0 .. scalar(@idx)-1 | ||||||||||||||||||||||||||||
| 212 | ]; | ||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||
| 214 | 1 | }; | |||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | 1 | ▶ | sub generate_sort_in_place_by { | ||||||||||||||||||||||||||
|
Subroutine
generate_sort_in_place_by: called CC=1 SCAR=0.3
Pod
documented
| |||||||||||||||||||||||||||||
| 219 | 1 | my($self) = @_; | |||||||||||||||||||||||||||
| 220 | 1 | my $reader = $self->reader; | |||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | 1 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=18.2
| |||||||||||||||||||||||||||||
| 223 | 1 | my ( $instance, $block, $compare ) = @_; | |||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | 1 | ▶ | if(@_ < 1 or @_ > 3) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ < 1 or @_ > 3
MC/DC0%0/2
@_ < 1 or @_ > 3
@_ < 1
@_ > 3
Truth table33%1/3
A or B
A= @_ < 1B= @_ > 3
| |||||||||||||||||||||||||||||
| 226 | 0 | $self->argument_error('sort_by', 1, 3, scalar @_); | |||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | 1 | my $array_ref = $reader->($instance); | |||||||||||||||||||||||||||
| 230 | 1 | my @idx; | |||||||||||||||||||||||||||
| 231 | 1 | foreach (@{$array_ref}){ | |||||||||||||||||||||||||||
| 232 | 3 | push @idx, scalar $block->($_); | |||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | 1 | ▶ | if($compare){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 236 | 1 | @{ $array_ref } = @{ $array_ref }[ | |||||||||||||||||||||||||||
| 237 | 1 | sort { $compare->($idx[$a], $idx[$b]) } | |||||||||||||||||||||||||||
| 238 | 0 .. scalar(@idx)-1 | ||||||||||||||||||||||||||||
| 239 | ]; | ||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||
| 241 | else{ | ||||||||||||||||||||||||||||
| 242 | 0 | @{ $array_ref } = @{ $array_ref }[ | |||||||||||||||||||||||||||
| 243 | 0 | sort { $idx[$a] cmp $idx[$b] } | |||||||||||||||||||||||||||
| 244 | 0 .. scalar(@idx)-1 | ||||||||||||||||||||||||||||
| 245 | ]; | ||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||
| 247 | 1 | return $instance; | |||||||||||||||||||||||||||
| 248 | 1 | }; | |||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | 5 | ▶ | sub generate_shuffle { | ||||||||||||||||||||||||||
|
Subroutine
generate_shuffle: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 253 | 5 | my($self) = @_; | |||||||||||||||||||||||||||
| 254 | 5 | my $reader = $self->reader; | |||||||||||||||||||||||||||
| 255 | 20 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 256 | 20 | my ( $instance ) = @_; | |||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | 20 | ▶ | if(@_ != 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 259 | 10 | $self->argument_error('shuffle', 1, 1, scalar @_); | |||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | 10 | return List::Util::shuffle @{ $reader->($instance) }; | |||||||||||||||||||||||||||
| 263 | 5 | }; | |||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | 10 | ▶ | sub generate_grep { | ||||||||||||||||||||||||||
|
Subroutine
generate_grep: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 267 | 10 | my($self) = @_; | |||||||||||||||||||||||||||
| 268 | 10 | my $reader = $self->reader; | |||||||||||||||||||||||||||
| 269 | 70 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 270 | 70 | my ( $instance, $block ) = @_; | |||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||
| 272 | 70 | ▶ | if(@_ != 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 273 | 30 | $self->argument_error('grep', 2, 2, scalar @_); | |||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||
| 276 | 40 | ▶ | Mouse::Util::TypeConstraints::CodeRef($block) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 277 | or $instance->meta->throw_error( | ||||||||||||||||||||||||||||
| 278 | "The argument passed to grep must be a code reference"); | ||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | 30 | return grep { $block->() } @{ $reader->($instance) }; | |||||||||||||||||||||||||||
| 281 | 10 | }; | |||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||
| 284 | 5 | ▶ | sub generate_uniq { | ||||||||||||||||||||||||||
|
Subroutine
generate_uniq: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 285 | 5 | my($self) = @_; | |||||||||||||||||||||||||||
| 286 | 5 | my $reader = $self->reader; | |||||||||||||||||||||||||||
| 287 | 20 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 288 | 20 | my ( $instance ) = @_; | |||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | 20 | ▶ | if(@_ != 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 291 | 10 | $self->argument_error('uniq', 1, 1, scalar @_); | |||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||
| 294 | 10 | my %seen; | |||||||||||||||||||||||||||
| 295 | my $seen_undef; | ||||||||||||||||||||||||||||
| 296 | return grep{ | ||||||||||||||||||||||||||||
| 297 | ( defined($_) | ||||||||||||||||||||||||||||
| 298 | 110 | ▶ | ? ++$seen{$_} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 299 | : ++$seen_undef | ||||||||||||||||||||||||||||
| 300 | ) == 1 | ||||||||||||||||||||||||||||
| 301 | 10 | } @{ $reader->($instance) }; | |||||||||||||||||||||||||||
| 302 | 5 | }; | |||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | 5 | ▶ | sub generate_elements { | ||||||||||||||||||||||||||
|
Subroutine
generate_elements: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 306 | 5 | my($self) = @_; | |||||||||||||||||||||||||||
| 307 | 5 | my $reader = $self->reader; | |||||||||||||||||||||||||||
| 308 | 22 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 309 | 22 | my ($instance) = @_; | |||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||
| 311 | 22 | ▶ | if(@_ != 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 312 | 10 | $self->argument_error('elements', 1, 1, scalar @_); | |||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||
| 315 | 12 | return @{ $reader->($instance) }; | |||||||||||||||||||||||||||
| 316 | 5 | }; | |||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||
| 319 | 10 | ▶ | sub generate_join { | ||||||||||||||||||||||||||
|
Subroutine
generate_join: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 320 | 10 | my($self) = @_; | |||||||||||||||||||||||||||
| 321 | 10 | my $reader = $self->reader; | |||||||||||||||||||||||||||
| 322 | 50 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 323 | 50 | my ( $instance, $separator ) = @_; | |||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||
| 325 | 50 | ▶ | if(@_ != 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 326 | 20 | $self->argument_error('join', 2, 2, scalar @_); | |||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||
| 329 | 30 | ▶ | Mouse::Util::TypeConstraints::Str($separator) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 330 | or $instance->meta->throw_error( | ||||||||||||||||||||||||||||
| 331 | "The argument passed to join must be a string"); | ||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||
| 333 | 20 | return join $separator, @{ $reader->($instance) }; | |||||||||||||||||||||||||||
| 334 | 10 | }; | |||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||
| 337 | 21 | ▶ | sub generate_push { | ||||||||||||||||||||||||||
|
Subroutine
generate_push: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 338 | 21 | my($self) = @_; | |||||||||||||||||||||||||||
| 339 | 21 | my $reader = $self->reader; | |||||||||||||||||||||||||||
| 340 | 21 | my $writer = $self->writer; | |||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||
| 342 | 36 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 343 | 36 | my($instance, @values) = @_; | |||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||
| 345 | 36 | my @new_values = @{ $reader->($instance) }; | |||||||||||||||||||||||||||
| 346 | 36 | push @new_values, @values; | |||||||||||||||||||||||||||
| 347 | 36 | $writer->($instance, \@new_values); # commit | |||||||||||||||||||||||||||
| 348 | 36 | return scalar @new_values; | |||||||||||||||||||||||||||
| 349 | 21 | }; | |||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||
| 352 | 6 | ▶ | sub generate_pop { | ||||||||||||||||||||||||||
|
Subroutine
generate_pop: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 353 | 6 | my($self) = @_; | |||||||||||||||||||||||||||
| 354 | 6 | my $reader = $self->reader; | |||||||||||||||||||||||||||
| 355 | 23 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 356 | 23 | ▶ | if(@_ != 1) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 357 | 10 | $self->argument_error('pop', 1, 1, scalar @_); | |||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||
| 359 | 13 | return pop @{ $reader->( $_[0] ) }; | |||||||||||||||||||||||||||
| 360 | 6 | }; | |||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||
| 363 | 10 | ▶ | sub generate_unshift { | ||||||||||||||||||||||||||
|
Subroutine
generate_unshift: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 364 | 10 | my($self) = @_; | |||||||||||||||||||||||||||
| 365 | 10 | my $reader = $self->reader; | |||||||||||||||||||||||||||
| 366 | 10 | my $writer = $self->writer; | |||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||
| 368 | 22 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 369 | 22 | my($instance, @values) = @_; | |||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||
| 371 | 22 | my @new_values = @{ $reader->($instance) }; | |||||||||||||||||||||||||||
| 372 | 22 | unshift @new_values, @values; | |||||||||||||||||||||||||||
| 373 | 22 | $writer->($instance, \@new_values); # commit | |||||||||||||||||||||||||||
| 374 | 22 | return scalar @new_values; | |||||||||||||||||||||||||||
| 375 | 10 | }; | |||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||
| 378 | 5 | ▶ | sub generate_shift { | ||||||||||||||||||||||||||
|
Subroutine
generate_shift: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 379 | 5 | my($self) = @_; | |||||||||||||||||||||||||||
| 380 | 5 | my $reader = $self->reader; | |||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||
| 382 | 20 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 383 | 20 | ▶ | if(@_ != 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 384 | 10 | $self->argument_error('shift', 1, 1, scalar @_); | |||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||
| 387 | 10 | return shift @{ $reader->( $_[0] ) }; | |||||||||||||||||||||||||||
| 388 | 5 | }; | |||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||
| 391 | 9 | __PACKAGE__->meta->add_method(generate_get => \&generate_fetch); # alias | |||||||||||||||||||||||||||
| 392 | 14 | ▶ | sub generate_fetch { | ||||||||||||||||||||||||||
|
Subroutine
generate_fetch: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 393 | 14 | my($self, $handle_name) = @_; | |||||||||||||||||||||||||||
| 394 | 14 | my $reader = $self->reader; | |||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||
| 396 | 155 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 397 | 155 | my($instance, $idx) = @_; | |||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||
| 399 | 155 | ▶ | if(@_ != 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 400 | 20 | $self->argument_error('get', 2, 2, scalar @_); | |||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||
| 403 | 135 | ▶ | Mouse::Util::TypeConstraints::Int($idx) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 404 | or $instance->meta->throw_error( | ||||||||||||||||||||||||||||
| 405 | "The index passed to get must be an integer"); | ||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||
| 407 | 105 | return $reader->( $instance )->[ $idx ]; | |||||||||||||||||||||||||||
| 408 | 14 | }; | |||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||
| 411 | 9 | __PACKAGE__->meta->add_method(generate_set => \&generate_store); # alias | |||||||||||||||||||||||||||
| 412 | 16 | ▶ | sub generate_store { | ||||||||||||||||||||||||||
|
Subroutine
generate_store: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 413 | 16 | my($self) = @_; | |||||||||||||||||||||||||||
| 414 | 16 | my $reader = $self->reader; | |||||||||||||||||||||||||||
| 415 | 16 | my $writer = $self->writer; | |||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||
| 417 | 71 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 418 | 71 | my($instance, $idx, $value) = @_; | |||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||
| 420 | 71 | ▶ | if(@_ != 3) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 421 | 30 | $self->argument_error('set', 3, 3, scalar @_); | |||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||
| 424 | 41 | ▶ | Mouse::Util::TypeConstraints::Int($idx) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 425 | or $instance->meta->throw_error( | ||||||||||||||||||||||||||||
| 426 | "The index argument passed to set must be an integer"); | ||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||
| 428 | 41 | my @new_values = @{ $reader->($instance) }; | |||||||||||||||||||||||||||
| 429 | 41 | $new_values[$idx] = $value; | |||||||||||||||||||||||||||
| 430 | 41 | $writer->($instance, \@new_values); # commit | |||||||||||||||||||||||||||
| 431 | 41 | return $value; | |||||||||||||||||||||||||||
| 432 | 16 | }; | |||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||
| 435 | 17 | ▶ | sub generate_accessor { | ||||||||||||||||||||||||||
|
Subroutine
generate_accessor: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 436 | 17 | my($self) = @_; | |||||||||||||||||||||||||||
| 437 | 17 | my $reader = $self->reader; | |||||||||||||||||||||||||||
| 438 | 17 | my $writer = $self->writer; | |||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||
| 440 | 94 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||
| 441 | 94 | my($instance, $idx, $value) = @_; | |||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||
| 444 | 94 | ▶ | if ( @_ == 2 ) { # reader | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 445 | 22 | ▶ | Mouse::Util::TypeConstraints::Int($idx) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 446 | or $instance->meta->throw_error( | ||||||||||||||||||||||||||||
| 447 | "The index argument passed to accessor must be an integer"); | ||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||
| 449 | 22 | return $reader->($instance)->[ $idx ]; | |||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||
| 451 | elsif ( @_ == 3) { # writer | ||||||||||||||||||||||||||||
| 452 | 32 | ▶ | Mouse::Util::TypeConstraints::Int($idx) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 453 | or $instance->meta->throw_error( | ||||||||||||||||||||||||||||
| 454 | "The index argument passed to accessor must be an integer"); | ||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||
| 456 | 32 | my @new_values = @{ $reader->($instance) }; | |||||||||||||||||||||||||||
| 457 | 31 | $new_values[$idx] = $value; | |||||||||||||||||||||||||||
| 458 | 31 | $writer->($instance, \@new_values); # commit | |||||||||||||||||||||||||||
| 459 | 31 | return $value; | |||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||
| 461 | else { | ||||||||||||||||||||||||||||
| 462 | 40 | $self->argument_error('accessor', 2, 3, scalar @_); | |||||||||||||||||||||||||||
| 463 | } | ||||||||||||||||||||||||||||
| 464 | 17 | }; | |||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||
| 467 | 5 | ▶ | sub generate_clear { | ||||||||||||||||||||||||||
|
Subroutine
generate_clear: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 468 | 5 | my($self) = @_; | |||||||||||||||||||||||||||
| 469 | 5 | my $reader = $self->reader; | |||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||
| 471 | 30 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 472 | 30 | my($instance) = @_; | |||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||
| 474 | 30 | ▶ | if(@_ != 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 475 | 10 | $self->argument_error('clear', 1, 1, scalar @_); | |||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||
| 478 | 20 | @{ $reader->( $instance ) } = (); | |||||||||||||||||||||||||||
| 479 | 20 | return $instance; | |||||||||||||||||||||||||||
| 480 | 5 | }; | |||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||
| 483 | 9 | __PACKAGE__->meta->add_method(generate_delete => \&generate_remove); # alias | |||||||||||||||||||||||||||
| 484 | 10 | ▶ | sub generate_remove { | ||||||||||||||||||||||||||
|
Subroutine
generate_remove: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 485 | 10 | my($self) = @_; | |||||||||||||||||||||||||||
| 486 | 10 | my $reader = $self->reader; | |||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||
| 488 | 40 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 489 | 40 | my($instance, $idx) = @_; | |||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||
| 491 | 40 | ▶ | if(@_ != 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 492 | 20 | $self->argument_error('delete', 2, 2, scalar @_); | |||||||||||||||||||||||||||
| 493 | } | ||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||
| 495 | 20 | ▶ | Mouse::Util::TypeConstraints::Int($idx) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 496 | or $instance->meta->throw_error( | ||||||||||||||||||||||||||||
| 497 | "The index argument passed to delete must be an integer"); | ||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||
| 499 | 20 | return splice @{ $reader->( $instance ) }, $idx, 1; | |||||||||||||||||||||||||||
| 500 | 10 | }; | |||||||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||
| 503 | 10 | ▶ | sub generate_insert { | ||||||||||||||||||||||||||
|
Subroutine
generate_insert: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 504 | 10 | my($self) = @_; | |||||||||||||||||||||||||||
| 505 | 10 | my $reader = $self->reader; | |||||||||||||||||||||||||||
| 506 | 10 | my $writer = $self->writer; | |||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||
| 508 | 20 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 509 | 20 | my($instance, $idx, $value) = @_; | |||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||
| 511 | 20 | ▶ | if(@_ != 3) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 512 | 10 | $self->argument_error('insert', 3, 3, scalar @_); | |||||||||||||||||||||||||||
| 513 | } | ||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||
| 515 | 10 | ▶ | Mouse::Util::TypeConstraints::Int($idx) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 516 | or $instance->meta->throw_error( | ||||||||||||||||||||||||||||
| 517 | "The index argument passed to insert must be an integer"); | ||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||
| 519 | 10 | my @new_values = @{ $reader->($instance) }; | |||||||||||||||||||||||||||
| 520 | 10 | splice @new_values, $idx, 0, $value; | |||||||||||||||||||||||||||
| 521 | 10 | $writer->($instance, \@new_values); # commit | |||||||||||||||||||||||||||
| 522 | 10 | return $instance; | |||||||||||||||||||||||||||
| 523 | 10 | }; | |||||||||||||||||||||||||||
| 524 | } | ||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||
| 526 | 20 | ▶ | sub generate_splice { | ||||||||||||||||||||||||||
|
Subroutine
generate_splice: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 527 | 20 | my($self) = @_; | |||||||||||||||||||||||||||
| 528 | 20 | my $reader = $self->reader; | |||||||||||||||||||||||||||
| 529 | 20 | my $writer = $self->writer; | |||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||
| 531 | 90 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=19.6
| |||||||||||||||||||||||||||||
| 532 | 90 | my ( $instance, $idx, $len, @elems ) = @_; | |||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||
| 534 | 90 | ▶ | if(@_ < 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 535 | 10 | $self->argument_error('splice', 2, undef, scalar @_); | |||||||||||||||||||||||||||
| 536 | } | ||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||
| 538 | 80 | ▶ | Mouse::Util::TypeConstraints::Int($idx) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 539 | or $instance->meta->throw_error( | ||||||||||||||||||||||||||||
| 540 | "The index argument passed to splice must be an integer"); | ||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||
| 542 | 80 | ▶ | if(defined $len) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 543 | 80 | ▶ | Mouse::Util::TypeConstraints::Int($len) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 544 | or $instance->meta->throw_error( | ||||||||||||||||||||||||||||
| 545 | "The length argument passed to splice must be an integer"); | ||||||||||||||||||||||||||||
| 546 | } | ||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||
| 548 | 70 | my @new_values = @{ $reader->($instance) }; | |||||||||||||||||||||||||||
| 549 | 70 | ▶ | my @ret_values = defined($len) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 550 | ? splice @new_values, $idx, $len, @elems | ||||||||||||||||||||||||||||
| 551 | : splice @new_values, $idx; | ||||||||||||||||||||||||||||
| 552 | 70 | $writer->($instance, \@new_values); # commit | |||||||||||||||||||||||||||
| 553 | 70 | ▶ | return wantarray ? @ret_values : $ret_values[-1]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 554 | 20 | }; | |||||||||||||||||||||||||||
| 555 | } | ||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||
| 557 | 0 | ▶ | sub generate_for_each { | ||||||||||||||||||||||||||
|
Subroutine
generate_for_each: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 558 | 0 | my($self) = @_; | |||||||||||||||||||||||||||
| 559 | 0 | my $reader = $self->reader; | |||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||
| 561 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 562 | 0 | my ( $instance, $block ) = @_; | |||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||
| 564 | 0 | foreach my $element(@{ $reader->instance($instance) }){ | |||||||||||||||||||||||||||
| 565 | 0 | $block->($element); | |||||||||||||||||||||||||||
| 566 | } | ||||||||||||||||||||||||||||
| 567 | 0 | return $instance; | |||||||||||||||||||||||||||
| 568 | 0 | }; | |||||||||||||||||||||||||||
| 569 | } | ||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||
| 571 | 0 | ▶ | sub generate_for_each_pair { | ||||||||||||||||||||||||||
|
Subroutine
generate_for_each_pair: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 572 | 0 | my($self) = @_; | |||||||||||||||||||||||||||
| 573 | 0 | my $reader = $self->reader; | |||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||
| 575 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 576 | 0 | my ( $instance, $block ) = @_; | |||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||
| 578 | 0 | my $array_ref = $reader->($instance); | |||||||||||||||||||||||||||
| 579 | 0 | ▶ | for(my $i = 0; $i < @{$array_ref}; $i += 2){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 580 | 0 | $block->($array_ref->[$i], $array_ref->[$i + 1]); | |||||||||||||||||||||||||||
| 581 | } | ||||||||||||||||||||||||||||
| 582 | 0 | return $instance; | |||||||||||||||||||||||||||
| 583 | 0 | }; | |||||||||||||||||||||||||||
| 584 | } | ||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||
| 586 | 9 | ▶ | no Mouse; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 587 | 9 | __PACKAGE__->meta->make_immutable(); | |||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||
| 589 | __END__ | ||||||||||||||||||||||||||||