blib/lib/Class/PseudoHash.pm

filter: Statementstmt 81.6% 58 / 71 Branchbran 22.2% 4 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 76.0% 19 / 25 Podpod 0.0% 0 / 1 totaltotal 70.4% 81 / 115 CC 11 SCAR 10.9
CC
11
Cov
70%
FETCH
6.7
STORE
6.7
new
4.9
CRAP 3.0
↑ Summary
1 package Class::PseudoHash;
2 1 $Class::PseudoHash::VERSION = '1.10';
3  
4 1 ▶use 5.005;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use vars qw/$FixedKeys $Obj $Proxy/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use constant NO_SUCH_FIELD => 'No such pseudohash field "%s"';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use constant NO_SUCH_INDEX => 'Bad index while coercing array into hash';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use overload (
Subroutine BEGIN: called CC=1 SCAR=0.1
10 4 ▶ '%{}' => sub { $$Obj = $_[0]; return $Proxy },
Subroutine __ANON__: called CC=1 SCAR=0.0
11 1 ▶ '""' => sub { overload::AddrRef($_[0]) },
Subroutine __ANON__: called CC=1 SCAR=0.0
12 1 ▶ '0+' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
13 1 my $str = overload::AddrRef($_[0]);
14 1 hex(substr($str, index($str, '(') + 1, -1));
15 },
16 1 ▶ 'bool' => sub { 1 },
Subroutine __ANON__: called CC=1 SCAR=0.0
17 0 ▶ 'cmp' => sub { "$_[0]" cmp "$_[1]" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
18 0 ▶ '<=>' => sub { "$_[0]" cmp "$_[1]" }, # for completeness' sake
Subroutine __ANON__: not called CC=1 SCAR=6.9
19 1 'fallback' => 1,
20 1 );
21  
22 1 $FixedKeys = 1;
23  
24 1 ▶sub import {
Subroutine import: called CC=2 SCAR=6.9
25 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 1 my $class = shift;
28 1 tie %{$Proxy}, $class;
29  
30 1 ▶ *{'fields::phash'} = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
31 1 $class->new(@_);
32 1 ▶ } unless defined $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 1 0 1
33 }
34  
35 2 ▶sub new {
Subroutine new: called CC=4 SCAR=15.9
Pod undocumented
36 2 my $class = shift;
37 2 my @array = undef;
38  
39 2 ▶ if (UNIVERSAL::isa($_[0], 'ARRAY')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($_[0], 'ARRAY')) { } 2 0 2
40 2 foreach my $k (@{$_[0]}) {
41 8 $array[$array[0]{$k} = @array] = $_[1][$#array];
42 }
43 }
44 else {
45 0 ▶ while (my ($k, $v) = splice(@_, 0, 2)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@_, 0, 2)) 0 0 0
46 0 $array[$array[0]{$k} = @array] = $v;
47 }
48 }
49  
50 2 bless(\@array, $class);
51 }
52  
53 1 ▶sub FETCH {
Subroutine FETCH: called CC=4 SCAR=19.1
54 1 my ($self, $key) = @_;
55  
56 1 $self = $$$self;
57  
58 return $self->[
59 $self->[0]{$key} >= 1
60 ? $self->[0]{$key} :
61 1 ▶ defined($self->[0]{$key})
Branch: 3 branches
BranchTrueFalseTotal
$self->[0]{$key} >= 1 ? : 1 0 1
defined $self->[0]{$key} ? : 0 0 0
$Class::PseudoHash::FixedKeys ? : 0 0 0
62 ? _croak(NO_SUCH_INDEX) :
63 $FixedKeys
64 ? _croak(NO_SUCH_FIELD, $key) :
65 @$self
66 ];
67 }
68  
69 2 ▶sub STORE {
Subroutine STORE: called CC=4 SCAR=19.1
70 2 my ($self, $key, $value) = @_;
71  
72 2 $self = $$$self;
73  
74 return $self->[
75 $self->[0]{$key} >= 1
76 ? $self->[0]{$key} :
77 2 ▶ defined($self->[0]{$key})
Branch: 3 branches
BranchTrueFalseTotal
$self->[0]{$key} >= 1 ? : 2 0 2
defined $self->[0]{$key} ? : 0 0 0
$Class::PseudoHash::FixedKeys ? : 0 0 0
78 ? _croak(NO_SUCH_INDEX) :
79 $FixedKeys
80 ? _croak(NO_SUCH_FIELD, $key) :
81 @$self
82 ] = $value;
83 }
84  
85 0 ▶sub _croak {
Subroutine _croak: not called CC=1 SCAR=6.9
86 0 require Carp;
87 0 Carp::croak(sprintf(shift, @_));
88 }
89  
90 1 ▶sub TIEHASH {
Subroutine TIEHASH: called CC=1 SCAR=0.0
91 1 bless \$Obj => shift;
92 }
93  
94 1 ▶sub FIRSTKEY {
Subroutine FIRSTKEY: called CC=1 SCAR=0.0
95 1 scalar keys %{$${$_[0]}->[0]};
96 1 each %{$${$_[0]}->[0]};
97 }
98  
99 4 ▶sub NEXTKEY {
Subroutine NEXTKEY: called CC=1 SCAR=0.0
100 4 each %{$${$_[0]}->[0]};
101 }
102  
103 0 ▶sub EXISTS {
Subroutine EXISTS: not called CC=1 SCAR=6.9
104 0 exists $${$_[0]}->[0]{$_[1]};
105 }
106  
107 0 ▶sub DELETE {
Subroutine DELETE: not called CC=1 SCAR=6.9
108 0 delete $${$_[0]}->[0]{$_[1]};
109 }
110  
111 0 ▶sub CLEAR {
Subroutine CLEAR: not called CC=1 SCAR=6.9
112 0 @{$${$_[0]}} = ();
113 }
114  
115 1 1;
116  
117 __END__
↑ Summary