Case/Preserve.pm

filter: Statementstmt 97.9% 47 / 48 Branchbran 80.0% 8 / 10 Conditioncond 80.0% 4 / 5 MC/DCmcdc 66.6% 2 / 3 Subroutinesub 100% 13 / 13 Podpod 0.0% 0 / 1 totaltotal 92.5% 74 / 80 SCAR 20.8
CC
8
Cov
94%
init
4.1
NEXTKEY
3.0
STORE
3.0
CRAP 8.0
« Case.pm ↑ Summary Case/Lower.pm »
1 # Copyrights 2002-2020 by [Mark Overmeer <markov@cpan.org>].
2 # For other contributors see ChangeLog.
3 # See the manual pages for details on the licensing terms.
4 # Pod stripped from pm file by OODoc 2.02.
5 # This code is part of distribution Hash::Case. Meta-POD processed with
6 # OODoc into POD and HTML manual-pages. See README.md
7 # Copyright Mark Overmeer. Licensed under the same terms as Perl itself.
8  
9 package Hash::Case::Preserve;
10 2 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 $VERSION = '1.05';
12  
13 2 ▶use base 'Hash::Case';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19  
20 sub init($)
21 6 ▶{ my ($self, $args) = @_;
Subroutine init: called CC=4 SCAR=14.2
Pod undocumented
22  
23 6 $self->{HCP_data} = {};
24 6 $self->{HCP_keys} = {};
25  
26 6 ▶ my $keep = $args->{keep} || 'LAST';
Condition50%1/2
$args->{'keep'} || 'LAST'
l!l
60
MC/DC0%0/1
$args->{'keep'} || 'LAST'
$args->{'keep'}
Truth table50%1/2
A
A= $args->{'keep'}
Aresult
11
00
27 6 ▶ if($keep eq 'LAST') { $self->{HCP_update} = 1 }
Branch: 2 branches
BranchTrueFalseTotal
if ($keep eq 'LAST') { } 3 3 6
elsif ($keep eq 'FIRST') { } 3 0 3
28 3 elsif($keep eq 'FIRST') { $self->{HCP_update} = 0 }
29 else
30 0 { croak "use 'FIRST' or 'LAST' with the option keep";
31 }
32  
33 6 $self->SUPER::native_init($args);
34 }
35  
36 # Maintain two hashes within this object: one to store the values, and
37 # one to preserve the casing. The main object also stores the options.
38 # The data is kept under lower cased keys.
39  
40 30 ▶sub FETCH($) { $_[0]->{HCP_data}{lc $_[1]} }
Subroutine FETCH: called CC=1 SCAR=0.0
41  
42 sub STORE($$)
43 16 ▶{ my ($self, $key, $value) = @_;
Subroutine STORE: called CC=3 SCAR=11.0
44 16 my $lckey = lc $key;
45  
46 $self->{HCP_keys}{$lckey} = $key
47 16 ▶ if $self->{HCP_update} || !exists $self->{HCP_keys}{$lckey};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"HCP_update"} or not exists $self->{"HCP_keys"}{$lckey} 14 2 16
Condition100%3/3
$self->{"HCP_update"} or not exists $self->{"HCP_keys"}{$lckey}
l!l&&r!l&&!r
862
MC/DC100%2/2
$self->{"HCP_update"} or not exists $self->{"HCP_keys"}{$lckey}
$self->{"HCP_update"} not exists $self->{"HCP_keys"}{$lckey}
Truth table100%3/3
A or not(B)
A= $self->{"HCP_update"}B= not exists $self->{"HCP_keys"}{$lckey}
ABresult
1X1
011
000
48  
49 16 $self->{HCP_data}{$lckey} = $value;
50 }
51  
52 sub FIRSTKEY
53 26 ▶{ my $self = shift;
Subroutine FIRSTKEY: called CC=1 SCAR=0.0
54 26 my $a = scalar keys %{$self->{HCP_keys}};
55 26 $self->NEXTKEY;
56 }
57  
58 sub NEXTKEY($)
59 56 ▶{ my $self = shift;
Subroutine NEXTKEY: called CC=3 SCAR=11.0
60 56 ▶ if(my ($k, $v) = each %{$self->{HCP_keys}})
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$self{'HCP_keys'};}) { } 30 26 56
61 30 ▶ { return wantarray ? ($v, $self->{HCP_data}{$k}) : $v;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 30 30
62 }
63 26 else { return () }
64 }
65  
66 2 ▶sub EXISTS($) { exists $_[0]->{HCP_data}{lc $_[1]} }
Subroutine EXISTS: called CC=1 SCAR=0.0
67  
68 sub DELETE($)
69 2 ▶{ my $lckey = lc $_[1];
Subroutine DELETE: called CC=1 SCAR=0.0
70 2 delete $_[0]->{HCP_keys}{$lckey};
71 2 delete $_[0]->{HCP_data}{$lckey};
72 }
73  
74 sub CLEAR()
75 2 ▶{ %{$_[0]->{HCP_data}} = ();
Subroutine CLEAR: called CC=1 SCAR=0.0
76 2 %{$_[0]->{HCP_keys}} = ();
77 }
78  
79 2 1;
« Case.pm ↑ Summary Case/Lower.pm »