Session/Serialize/default.pm

filter: Statementstmt 91.1% 62 / 68 Branchbran 67.8% 19 / 28 Conditioncond 25.0% 2 / 8 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 100% 11 / 11 Podpod 100% 2 / 2 totaltotal 79.5% 97 / 122 CC 19 SCAR 21.6
CC
19
Cov
80%
__scan
14.2
__walk
11.2
thaw
2.0
CRAP 8.7
« Session/Driver/db_file.pm ↑ Summary Session/ID/incr.pm »
1 package CGI::Session::Serialize::default;
2  
3 # $Id$
4  
5 21 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 21 ▶use Safe;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 21 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 21 ▶use CGI::Session::ErrorHandler;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 21 ▶use Scalar::Util qw(blessed reftype refaddr);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 21 ▶use Carp "croak";
Subroutine BEGIN: called CC=1 SCAR=0.0
11 21 ▶use vars qw( %overloaded );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 21 require overload;
13  
14 21 @CGI::Session::Serialize::default::ISA = ( "CGI::Session::ErrorHandler" );
15 21 $CGI::Session::Serialize::default::VERSION = '4.43';
16  
17  
18 27 ▶sub freeze {
Subroutine freeze: called CC=1 SCAR=0.0
Pod documented
19 27 my ($class, $data) = @_;
20
21 27 my $d =
22 new Data::Dumper([$data], ["D"]);
23 27 $d->Indent( 0 );
24 27 $d->Purity( 1 );
25 27 $d->Useqq( 0 );
26 27 $d->Deepcopy( 0 );
27 27 $d->Quotekeys( 1 );
28 27 $d->Terse( 0 );
29
30 # ;$D added to make certain we get our data structure back when we thaw
31 27 return $d->Dump() . ';$D';
32 }
33  
34 13 ▶sub thaw {
Subroutine thaw: called CC=2 SCAR=7.1
Pod documented
35 13 my ($class, $string) = @_;
36  
37 # To make -T happy
38 13 my ($safe_string) = $string =~ m/^(.*)$/s;
39 13 my $rv = Safe->new->reval( $safe_string );
40 13 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 13 13
41 0 return $class->set_error("thaw(): couldn't thaw. $@");
42 }
43 13 __walk($rv);
44 13 return $rv;
45 }
46  
47 13 ▶sub __walk {
Subroutine __walk: called CC=10 SCAR=24.1
48 13 my %seen;
49 13 my @filter = __scan(shift);
50 13 local %overloaded;
51  
52 # We allow the value assigned to a key to be undef.
53 # Hence the defined() test is not in the while().
54  
55 13 ▶ while (@filter) {
Branch: 1 branch
BranchTrueFalseTotal
if (@filter) 138 13 151
56 138 ▶ defined(my $x = shift @filter) or next;
Branch: 1 branch
BranchTrueFalseTotal
defined(my $x = shift @filter) or next 136 2 138
57 136 ▶ $seen{refaddr $x || ''}++ and next;
Branch: 1 branch
BranchTrueFalseTotal
$seen{builtin::refaddr($x) or ""}++ and next 91 45 136
Condition100%2/2
builtin::refaddr($x) || ''
l!l
33103
MC/DC100%1/1
builtin::refaddr($x) || ''
builtin::refaddr($x)
Truth table100%2/2
A
A= builtin::refaddr($x)
Aresult
11
00
58
59 45 ▶ my $r = reftype $x or next;
Branch: 1 branch
BranchTrueFalseTotal
my $r = builtin::reftype($x) or next 32 13 45
60 32 ▶ if ($r eq "HASH") {
Branch: 3 branches
BranchTrueFalseTotal
if ($r eq 'HASH') { } 23 9 32
elsif ($r eq 'ARRAY') { } 9 0 9
elsif ($r eq 'SCALAR' or $r eq 'REF') { } 0 0 0
61 # we use this form to make certain we have aliases
62 # to the values in %$x and not copies
63 23 push @filter, __scan(@{$x}{keys %$x});
64 } elsif ($r eq "ARRAY") {
65 9 push @filter, __scan(@$x);
66 ▶ } elsif ($r eq "SCALAR" || $r eq "REF") {
Condition0%0/3
$r eq "SCALAR" or $r eq "REF"
l!l&&r!l&&!r
000
MC/DC0%0/2
$r eq "SCALAR" or $r eq "REF"
$r eq "SCALAR" $r eq "REF"
Truth table0%0/3
A or B
A= $r eq "SCALAR"B= $r eq "REF"
ABresult
1X1
011
000
67 0 push @filter, __scan($$x);
68 }
69 }
70 }
71  
72 # we need to do this because the values we get back from the safe compartment
73 # will have packages defined from the safe compartment's *main instead of
74 # the one we use
75 45 ▶sub __scan {
Subroutine __scan: called CC=9 SCAR=26.5
76 # $_ gets aliased to each value from @_ which are aliases of the values in
77 # the current data structure
78 45 for (@_) {
79 138 ▶ if (blessed $_) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($_)) 7 131 138
80 7 ▶ if (overload::Overloaded($_)) {
Branch: 1 branch
BranchTrueFalseTotal
if (overload::Overloaded($_)) { } 3 4 7
81 3 my $address = refaddr $_;
82  
83 # if we already rebuilt and reblessed this item, use the cached
84 # copy so our ds is consistent with the one we serialized
85 3 ▶ if (exists $overloaded{$address}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $CGI::Session::Serialize::default::overloaded{$address}) { } 1 2 3
86 1 $_ = $overloaded{$address};
87 } else {
88 2 my $reftype = reftype $_;
89 2 ▶ if ($reftype eq "HASH") {
Branch: 3 branches
BranchTrueFalseTotal
if ($reftype eq 'HASH') { } 2 0 2
elsif ($reftype eq 'ARRAY') { } 0 0 0
elsif ($reftype eq 'SCALAR' or $reftype eq 'REF') { } 0 0 0
90 2 $_ = $overloaded{$address} = bless { %$_ }, ref $_;
91 } elsif ($reftype eq "ARRAY") {
92 0 $_ = $overloaded{$address} = bless [ @$_ ], ref $_;
93 ▶ } elsif ($reftype eq "SCALAR" || $reftype eq "REF") {
Condition0%0/3
$reftype eq "SCALAR" or $reftype eq "REF"
l!l&&r!l&&!r
000
MC/DC0%0/2
$reftype eq "SCALAR" or $reftype eq "REF"
$reftype eq "SCALAR" $reftype eq "REF"
Truth table0%0/3
A or B
A= $reftype eq "SCALAR"B= $reftype eq "REF"
ABresult
1X1
011
000
94 0 $_ = $overloaded{$address} = bless \do{my $o = $$_},ref $_;
95 } else {
96 0 croak "Do not know how to reconstitute blessed object of base type $reftype";
97 }
98 }
99 } else {
100 4 bless $_, ref $_;
101 }
102 }
103 }
104 45 return @_;
105 }
106  
107  
108 21 1;
109  
110 __END__;
« Session/Driver/db_file.pm ↑ Summary Session/ID/incr.pm »