blib/lib/Tie/Array/Packed.pm

filter: Statementstmt 52.0% 38 / 73 Branchbran 9.0% 2 / 22 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 53.8% 7 / 13 Podpod 85.7% 6 / 7 totaltotal 44.1% 53 / 120 CC 15 SCAR 27.5
CC
15
Cov
41%
grep
42.0
sort
20.0
_load_sort_packed
12.0
CRAP 15.7
↑ Summary perl_math_int128.c »
1 package Tie::Array::Packed;
2  
3 1 our $VERSION = '0.13';
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 require XSLoader;
10 1 XSLoader::load('Tie::Array::Packed', $VERSION);
11  
12 1 my @short = qw(c C F f d i I j J s! S! l! L! n N v V q Q e E);
13  
14 1 my %map = ( Char => 'c',
15 UnsignedChar => 'C',
16 Hex => 'h',
17 NV => 'F',
18 Number => 'F',
19 FloatNative => 'f',
20 DoubleNative => 'd',
21 Integer => 'j',
22 UnsignedInteger => 'J',
23 IntegerPerl => 'j',
24 IV => 'j',
25 UnsignedIntegerPerl => 'J',
26 UV => 'J',
27 IntegerNative => 'i',
28 UnsignedIntegerNative => 'I',
29 ShortNative => 's!',
30 UnsignedShortNative => 'S!',
31 LongNative => 'l!',
32 UnsignedLongNative => 'L!',
33 UnsignedShortNet => 'n',
34 UnsignedShortBE => 'n',
35 UnsignedLongNet => 'N',
36 UnsignedLongBE => 'N',
37 UnsignedShortVax => 'v',
38 UnsignedShortLE => 'v',
39 UnsignedLongVax => 'V',
40 UnsignedLongLE => 'V',
41 Quad => 'q',
42 UnsignedQuad => 'Q',
43 LongLong => 'q',
44 UnsignedLongLong => 'Q',
45 Int64 => 'q',
46 UInt64 => 'Q',
47 Int128 => 'e',
48 UInt128 => 'E',
49 );
50  
51  
52 1 @map{@short} = @short;
53  
54 1 for my $name (keys %map) {
55 56 my $type = $map{$name};
56  
57 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
58 56 @{"Tie::Array::Packed::${name}::ISA"} = __PACKAGE__;
59 56 *{"Tie::Array::Packed::${name}::TIEARRAY"} =
60 21 ▶ sub {
Subroutine __ANON__: called CC=3 SCAR=11.2
61 21 my $class = shift;
62 21 my $self;
63 21 ▶ $self = TIEARRAY($class, $type, defined $_[0] ? $_[0] : '');
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] ? : 21 0 21
64 21 ▶ if (@_ > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 21 0 21
65 21 shift;
66 21 $self->SPLICE(0, scalar(@_), @_);
67 }
68 21 $self;
69 56 };
70 }
71  
72 19 ▶sub make {
Subroutine make: called CC=1 SCAR=0.0
Pod documented
73 19 my $class = shift;
74 19 tie my(@self), $class, '', @_;
75 return \@self
76 19 }
77  
78 0 ▶sub make_with_packed {
Subroutine make_with_packed: not called CC=1 SCAR=6.9
Pod documented
79 0 my $class = shift;
80 0 tie my(@self), $class, @_;
81 return \@self
82 0 }
83  
84 0 ▶sub make_clone {
Subroutine make_clone: not called CC=1 SCAR=6.9
Pod documented
85 0 my $self = shift;
86 0 tie my(@clone), ref($self), $$self;
87 0 return \@clone;
88 }
89  
90 1 ▶sub string {
Subroutine string: called CC=1 SCAR=0.0
Pod undocumented
91 1 my $self = shift;
92 1 $$self;
93 }
94  
95 1 my $sort_packed_loaded;
96  
97 0 ▶sub _load_sort_packed {
Subroutine _load_sort_packed: not called CC=3 SCAR=24.8
98 0 eval { require Sort::Packed };
99 0 ▶ croak __PACKAGE__ ."::sort requires package Sort::Packed"
Branch: 1 branch
BranchTrueFalseTotal
if $@ or not $Sort::Packed::VERSION 0 0 0
Condition0%0/3
$@ or not $Sort::Packed::VERSION
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ or not $Sort::Packed::VERSION
$@ not $Sort::Packed::VERSION
Truth table0%0/3
A or not(B)
A= $@B= not $Sort::Packed::VERSION
ABresult
1X1
011
000
100 if ($@ or !$Sort::Packed::VERSION);
101 0 $sort_packed_loaded++
102 }
103  
104 0 ▶sub sort {
Subroutine sort: not called CC=4 SCAR=30.0
Pod documented
105 0 ▶ @_ > 2 and croak 'Usage: tied(@parray)->sort([sub { CMP($a, $b) }])';
Branch: 1 branch
BranchTrueFalseTotal
@_ > 2 and croak("Usage: tied(\@parray)->sort([sub { CMP(\$a, \$b) }])") 0 0 0
106 0 ▶ $sort_packed_loaded or _load_sort_packed;
Branch: 1 branch
BranchTrueFalseTotal
$sort_packed_loaded or _load_sort_packed() 0 0 0
107  
108 0 my $self = shift;
109 0 my $packer = $self->packer;
110 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
111 0 my $cmp = shift;
112 0 &Sort::Packed::sort_packed_custom($cmp, $packer, $$self);
113 }
114 else {
115 0 &Sort::Packed::sort_packed($packer, $$self);
116 }
117 }
118  
119  
120 0 ▶sub shuffle {
Subroutine shuffle: not called CC=3 SCAR=24.8
Pod documented
121 0 ▶ @_ != 1 and croak 'Usage: tied(@parray)->shuffle';
Branch: 1 branch
BranchTrueFalseTotal
@_ != 1 and croak("Usage: tied(\@parray)->shuffle") 0 0 0
122 0 ▶ $sort_packed_loaded or _load_sort_packed;
Branch: 1 branch
BranchTrueFalseTotal
$sort_packed_loaded or _load_sort_packed() 0 0 0
123  
124 0 my $self = shift;
125 0 Sort::Packed::shuffle_packed($self->packer, $$self)
126 }
127  
128 0 ▶sub grep {
Subroutine grep: not called CC=6 SCAR=37.4
Pod documented
129 0 ▶ @_ != 2 and croak 'Usage: tied(@parray)->grep(sub { SELECT($_) })';
Branch: 1 branch
BranchTrueFalseTotal
@_ != 2 and croak("Usage: tied(\@parray)->grep(sub { SELECT(\$_) })") 0 0 0
130  
131 0 my $self = shift;
132 0 my $select = shift;
133  
134 0 my $last = $self->FETCHSIZE - 1;
135 0 my $slow = 0;
136 0 for my $i (0..$last) {
137 0 for ($self->FETCH($i)) {
138 0 my $cp = $_;
139 0 ▶ if (&$select) {
Branch: 1 branch
BranchTrueFalseTotal
if (&$select) 0 0 0
140 0 ▶ $self->STORE($slow, $cp) if $slow < $i;
Branch: 1 branch
BranchTrueFalseTotal
if $slow < $i 0 0 0
141 0 $slow++
142 }
143 }
144 }
145 0 $self->STORESIZE($slow);
146 0 $slow;
147 }
148  
149 1 1;
150 __END__
↑ Summary perl_math_int128.c »