StorableDir/Slot.pm

filter: Statementstmt 87.5% 42 / 48 Branchbran 66.6% 8 / 12 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 92.8% 13 / 14 Podpod 0.0% 0 / 6 totaltotal 75.2% 64 / 85 CC 8 SCAR 11.5
CC
8
Cov
81%
translate
7.7
new
2.1
getkey
2.0
CRAP 3.2
« StorableDir.pm ↑ Summary StorableDir/BackedScalar.pm »
1 package Tie::StorableDir::Slot;
2  
3 4 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use Tie::StorableDir::BackedHash;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use Tie::StorableDir::BackedArray;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Tie::StorableDir::BackedScalar;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 # This is an internal class, representing one value out of a key/value
12 # entry in the root hash. It is used to write back data to the filesystem
13 # once it has been modified.
14 # Copyright (C) 2005 by Bryan Donlan
15 #
16 # This library is free software; you can redistribute it and/or modify
17 # it under the same terms as Perl itself, either Perl version 5.8.5 or,
18 # at your option, any later version of Perl 5 you may have available.
19  
20 18 ▶sub new {
Subroutine new: called CC=2 SCAR=7.2
Pod undocumented
21 18 my ($class, $key, $value, $parent) = @_;
22 18 ▶ $class = ref $class || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
0180
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
23 18 my $self = {
24 key => $key,
25 value => $value,
26 parent => $parent,
27 };
28 18 bless $self, $class;
29 18 return $self;
30 }
31  
32 20 ▶sub getvalue {
Subroutine getvalue: called CC=1 SCAR=0.0
Pod undocumented
33 20 return $_[0]->translate($_[0]->{value});
34 }
35  
36 0 ▶sub getkey {
Subroutine getkey: not called CC=1 SCAR=6.9
Pod undocumented
37 0 return $_[0]->{key};
38 }
39  
40 19 ▶sub disconnect {
Subroutine disconnect: called CC=1 SCAR=0.0
Pod undocumented
41 19 delete $_[0]->{parent};
42 }
43  
44 30 ▶sub translate {
Subroutine translate: called CC=6 SCAR=20.4
Pod undocumented
45 30 my ($self, $thing) = @_;
46 30 my $newthing;
47 30 ▶ return $thing unless ref $thing;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $thing 10 20 30
48 20 ▶ return $thing unless $self->{parent};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"parent"} 0 20 20
49 20 ▶ if (UNIVERSAL::isa($thing, 'HASH')) {
Branch: 3 branches
BranchTrueFalseTotal
if (UNIVERSAL::isa($thing, 'HASH')) { } 8 12 20
elsif (UNIVERSAL::isa($thing, 'ARRAY')) { } 12 0 12
elsif (UNIVERSAL::isa($thing, 'SCALAR')) { } 0 0 0
50 8 $newthing = {};
51 8 tie %$newthing, 'Tie::StorableDir::BackedHash', $self, $thing;
52 } elsif (UNIVERSAL::isa($thing, 'ARRAY')) {
53 12 $newthing = [];
54 12 tie @$newthing, 'Tie::StorableDir::BackedArray', $self, $thing;
55 } elsif (UNIVERSAL::isa($thing, 'SCALAR')) {
56 0 my $temp = undef;
57 0 $newthing = \$temp;
58 0 tie $temp, 'Tie::StorableDir::BackedScalar', $self, $thing;
59 } else {
60 0 carp "Can't tie type: ".ref($thing);
61 0 $newthing = $thing;
62 }
63 20 return $newthing;
64 }
65  
66 19 ▶sub writeback {
Subroutine writeback: called CC=2 SCAR=6.9
Pod undocumented
67 19 my $self = $_[0];
68 19 ▶ if (defined $self->{parent}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"parent"}) 17 2 19
69 17 $self->{parent}->STORE($self->{key}, $self->{value});
70 }
71 }
72  
73 18 ▶sub DESTROY {
Subroutine DESTROY: called CC=1 SCAR=0.0
74 18 $_[0]->writeback;
75 }
76  
77 4 1;
« StorableDir.pm ↑ Summary StorableDir/BackedScalar.pm »