Data/Frame/Autobox.pm

filter: Statementstmt 70.3% 76 / 108 Branchbran 66.6% 4 / 6 Conditioncond 50.0% 3 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 67.5% 27 / 40 Podpod n/a totaltotal 67.0% 110 / 164 CC 6 SCAR 5.2
CC
6
Cov
69%
merge
6.0
__ANON__
2.3
__ANON__
2.0
CRAP 1.7
« Data/Frame/Partial/Sugar.pm ↑ Summary Data/Frame/Setup.pm »
1 package Data::Frame::Autobox;
2 20 $Data::Frame::Autobox::VERSION = '0.006005';
3 # ABSTRACT: Autobox arrays and hashes for Data::Frame
4  
5 20 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 20 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # VERSION
9  
10 20 ▶use parent 'autobox';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12  
13 145 ▶sub import {
Subroutine import: called CC=1 SCAR=0.0
14 shift->SUPER::import(
15 145 ARRAY => __PACKAGE__ . '::ARRAY',
16 HASH => __PACKAGE__ . '::HASH',
17 @_
18 );
19 }
20  
21  
22 package Data::Frame::Autobox::ARRAY;
23 20 $Data::Frame::Autobox::ARRAY::VERSION = '0.006005';
24 20 ▶use List::AllUtils;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 20 ▶use POSIX qw(ceil);
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27  
28 2 ▶sub isempty { @{$_[0]} == 0 }
Subroutine isempty: called CC=1 SCAR=0.0
29  
30 0 ▶sub grep {
Subroutine grep: not called CC=1 SCAR=6.9
31 0 my ($array, $sub) = @_;
32 0 [ CORE::grep { $sub->($_) } @$array ];
33 }
34
35 510 ▶sub map {
Subroutine map: called CC=1 SCAR=0.0
36 510 my ($array, $sub) = @_;
37 510 [ CORE::map { $sub->($_) } @$array ];
38 }
39  
40 420 ▶sub at {
Subroutine at: called CC=1 SCAR=0.0
41 420 my ($array, $index) = @_;
42 420 $array->[$index];
43 }
44
45 44 ▶sub uniq { [ List::AllUtils::uniq(@{$_[0]}) ] }
Subroutine uniq: called CC=1 SCAR=0.0
46  
47 1 ▶sub set {
Subroutine set: called CC=1 SCAR=0.0
48 1 my ($array, $index, $value) = @_;
49 1 $array->[$index] = $value;
50 }
51  
52 398 ▶sub length { CORE::scalar @{$_[0]} }
Subroutine length: called CC=1 SCAR=0.0
53 0 ▶sub elems { CORE::scalar @{$_[0]} }
Subroutine elems: not called CC=1 SCAR=6.9
54
55 291 ▶sub flatten { @{$_[0]} }
Subroutine flatten: called CC=1 SCAR=0.0
56
57 0 ▶sub slice {
Subroutine slice: not called CC=1 SCAR=6.9
58 0 my ($array, $indices) = @_;
59 0 [ @{$array}[ @{$indices} ] ];
60 }
61  
62  
63 0 ▶sub copy { [ @{$_[0]} ] }
Subroutine copy: not called CC=1 SCAR=6.9
64  
65 4 ▶sub repeat {
Subroutine repeat: called CC=1 SCAR=0.0
66 4 my ($array, $n) = @_;
67 4 return [ (@$array) x $n ];
68 }
69  
70 3 ▶sub repeat_to_length {
Subroutine repeat_to_length: called CC=2 SCAR=6.9
71 3 my ($array, $l) = @_;
72 3 ▶ return $array if @$array == 0;
Branch: 1 branch
BranchTrueFalseTotal
if @$array == 0 1 2 3
73 2 my $x = repeat($array, ceil($l / @$array));
74 2 return [ @$x[0 .. $l-1] ];
75 }
76
77 1 ▶sub intersect {
Subroutine intersect: called CC=1 SCAR=0.0
78 1 my ($array, $other) = @_;
79 1 my %hash = map { $_ => 1 } @$array;
80 1 return [ grep { exists $hash{$_} } @$other ];
81 }
82  
83 1 ▶sub union {
Subroutine union: called CC=1 SCAR=0.0
84 1 my ($array, $other) = @_;
85 1 return [ List::AllUtils::uniq( @$array, @$other ) ];
86 }
87  
88 1 ▶sub setdiff {
Subroutine setdiff: called CC=1 SCAR=0.0
89 1 my ($array, $other) = @_;
90 1 my %hash = map { $_ => 1 } @$other;
91 1 return [ grep { not exists( $hash{$_} ) } @$array ];
92 }
93
94  
95 package Data::Frame::Autobox::HASH;
96 20 $Data::Frame::Autobox::HASH::VERSION = '0.006005';
97 20 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
98 20 ▶use Ref::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
99 20 ▶use List::AllUtils qw(pairmap);
Subroutine BEGIN: called CC=1 SCAR=0.0
100  
101  
102 2 ▶sub isempty { keys %{ $_[0] } == 0 }
Subroutine isempty: called CC=1 SCAR=0.0
103  
104 0 ▶sub delete {
Subroutine delete: not called CC=1 SCAR=6.9
105 0 my ($hash, $key) = @_;
106 0 CORE::delete $hash->{$key};
107 }
108
109 0 ▶sub merge {
Subroutine merge: not called CC=2 SCAR=17.9
110 0 my ($left, $right) = @_;
111 0 ▶ Carp::confess "You must pass a hashref as argument to merge"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $right eq "HASH" 0 0 0
112 unless ref $right eq 'HASH';
113 0 return { %$left, %$right };
114 }
115
116 0 ▶sub hslice {
Subroutine hslice: not called CC=1 SCAR=6.9
117 0 my ($hash, $keys) = @_;
118 0 return { map { $_ => $hash->{$_} } @$keys };
119 }
120  
121 0 ▶sub flatten { %{$_[0]} }
Subroutine flatten: not called CC=1 SCAR=6.9
122  
123 0 ▶sub at {
Subroutine at: not called CC=1 SCAR=6.9
124 0 my ($hash, $index) = @_;
125 0 $hash->{$index};
126 }
127
128 1 ▶sub set {
Subroutine set: called CC=1 SCAR=0.0
129 1 my ($hash, $index, $value) = @_;
130 1 $hash->{$index} = $value;
131 }
132
133 0 ▶sub exists {
Subroutine exists: not called CC=1 SCAR=6.9
134 0 my ($hash, $key) = @_;
135 0 CORE::exists $hash->{$key};
136 }
137
138 0 ▶sub keys { [ CORE::keys %{$_[0]} ] }
Subroutine keys: not called CC=1 SCAR=6.9
139 2 ▶sub names { [ CORE::keys %{$_[0]} ] }
Subroutine names: called CC=1 SCAR=0.0
140
141 0 ▶sub values {
Subroutine values: not called CC=1 SCAR=6.9
142 0 my ($hash) = @_;
143 0 [ CORE::values %$hash ];
144 }
145
146  
147 0 ▶sub copy { { %{ $_[0] } } }
Subroutine copy: not called CC=1 SCAR=6.9
148  
149 2 ▶sub rename {
Subroutine rename: called CC=2 SCAR=7.1
150 2 my ( $hash, $href_or_coderef ) = @_;
151  
152 2 my %new_hash;
153 2 ▶ if ( Ref::Util::is_coderef($href_or_coderef) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (Ref::Util::XS::is_coderef($href_or_coderef)) { } 1 1 2
154 1 ▶ %new_hash = pairmap { ( $href_or_coderef->($a) // $a ) => $b } %$hash;
Subroutine __ANON__: called CC=2 SCAR=8.1
Condition33%1/3
&$href_or_coderef($a) // $a
l!l&&r!l&&!r
300
MC/DC0%0/2
&$href_or_coderef($a) // $a
&$href_or_coderef($a) $a
Truth table33%1/3
A // B
A= &$href_or_coderef($a)B= $a
ABresult
1X1
011
000
155 }
156 else {
157 1 ▶ %new_hash = pairmap { ( $href_or_coderef->{$a} // $a ) => $b } %$hash;
Subroutine __ANON__: called CC=2 SCAR=7.1
Condition66%2/3
$href_or_coderef->{$a} // $a
l!l&&r!l&&!r
210
MC/DC0%0/2
$href_or_coderef->{$a} // $a
$href_or_coderef->{$a} $a
Truth table66%2/3
A // B
A= $href_or_coderef->{$a}B= $a
ABresult
1X1
011
000
158 }
159 2 return \%new_hash;
160 }
161  
162 20 1;
163  
164 __END__
« Data/Frame/Partial/Sugar.pm ↑ Summary Data/Frame/Setup.pm »