blib/lib/HTML/EP/Session/Cookie.pm

filter: Statementstmt 10.3% 8 / 77 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 25.0% 2 / 8 Podpod 0.0% 0 / 6 totaltotal 7.5% 10 / 133 CC 18 SCAR 33.3
CC
18
Cov
7%
Open
56.0
new
30.0
Store
20.0
CRAP 27.9
« blib/lib/HTML/EP/Session/Dumper.pm ↑ Summary blib/lib/HTML/EP/CGIEncryptForm.pm »
1 # -*- perl -*-
2 #
3 # HTML::EP - A Perl based HTML extension.
4 #
5 #
6 # Copyright (C) 1998 Jochen Wiedmann
7 # Am Eisteich 9
8 # 72555 Metzingen
9 # Germany
10 #
11 # Phone: +49 7123 14887
12 # Email: joe@ispsoft.de
13 #
14 # All rights reserved.
15 #
16 # You may distribute this module under the terms of either
17 # the GNU General Public License or the Artistic License, as
18 # specified in the Perl README file.
19 #
20 ############################################################################
21  
22 1 require 5.004;
23 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25  
26 1 ▶use CGI::Cookie ();
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28  
29 package HTML::EP::Session::Cookie;
30  
31  
32 0 ▶sub encode {
Subroutine encode: not called CC=3 SCAR=24.8
Pod undocumented
33 0 my($self, $in, $attr) = @_;
34 0 my $out = Storable::nfreeze($in);
35 0 ▶ if ($attr->{'zlib'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr->{"zlib"}) 0 0 0
36 0 require Compress::Zlib;
37 0 $out = Compress::Zlib::compress($out);
38 }
39 0 ▶ if ($attr->{'base64'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr->{'base64'}) { } 0 0 0
40 0 require MIME::Base64;
41 0 $out = MIME::Base64::encode_base64($out);
42 } else {
43 0 $out = unpack("H*", $out);
44 }
45 0 $out;
46 }
47  
48 0 ▶sub decode {
Subroutine decode: not called CC=3 SCAR=24.8
Pod undocumented
49 0 my($self, $in, $attr) = @_;
50 0 my $out;
51 0 ▶ if ($attr->{'base64'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr->{'base64'}) { } 0 0 0
52 0 require MIME::Base64;
53 0 $out = MIME::Base64::decode_base64($in);
54 } else {
55 0 $out = pack("H*", $in);
56 }
57 0 ▶ if ($attr->{'zlib'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr->{"zlib"}) 0 0 0
58 0 require Compress::Zlib;
59 0 $out = Compress::Zlib::uncompress($out);
60 }
61 0 Storable::thaw($out);
62 }
63  
64 0 ▶sub new {
Subroutine new: not called CC=5 SCAR=34.0
Pod undocumented
65 0 my($proto, $ep, $id, $attr) = @_;
66 0 ▶ my $class = (ref($proto) || $proto);
Condition0%0/3
ref $proto || $proto
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
67 0 my $session = {};
68 0 bless($session, $class);
69 0 my $freezed_session = $proto->encode($session, $attr);
70 0 my %opts;
71 0 $opts{'-name'} = $id;
72 0 ▶ $opts{'-expires'} = $attr->{'expires'} || '+1h';
Condition0%0/2
$attr->{'expires'} || '+1h'
l!l
00
MC/DC0%0/1
$attr->{'expires'} || '+1h'
$attr->{'expires'}
Truth table0%0/2
A
A= $attr->{'expires'}
Aresult
11
00
73 0 ▶ $opts{'-domain'} = $attr->{'domain'} if exists($attr->{'domain'});
Branch: 1 branch
BranchTrueFalseTotal
if exists $attr->{"domain"} 0 0 0
74 0 ▶ $opts{'-path'} = $attr->{'path'} if exists($attr->{'path'});
Branch: 1 branch
BranchTrueFalseTotal
if exists $attr->{"path"} 0 0 0
75 0 my $cookie = CGI::Cookie->new(%opts,
76 '-value' => $freezed_session);
77 0 $ep->{'_ep_cookies'}->{$id} = $cookie;
78 0 $opts{'zlib'} = $attr->{'zlib'};
79 0 $opts{'base64'} = $attr->{'base64'};
80 0 $session->{'_ep_data'} = \%opts;
81 0 $session;
82 }
83  
84 0 ▶sub Open {
Subroutine Open: not called CC=7 SCAR=40.3
Pod undocumented
85 0 my($proto, $ep, $id, $attr) = @_;
86 0 my $cgi = $ep->{'cgi'};
87 0 my $cookie = $cgi->cookie('-name' => $id);
88  
89 0 ▶ return $proto->new($ep, $id, $attr) unless $cookie;
Branch: 1 branch
BranchTrueFalseTotal
unless $cookie 0 0 0
90  
91 0 ▶ my $class = (ref($proto) || $proto);
Condition0%0/3
ref $proto || $proto
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
92 0 my %opts;
93 0 $opts{'-name'} = $id;
94 0 ▶ $opts{'-expires'} = $attr->{'expires'} || '+1h';
Condition0%0/2
$attr->{'expires'} || '+1h'
l!l
00
MC/DC0%0/1
$attr->{'expires'} || '+1h'
$attr->{'expires'}
Truth table0%0/2
A
A= $attr->{'expires'}
Aresult
11
00
95 0 ▶ $opts{'-domain'} = $attr->{'domain'} if exists($attr->{'domain'});
Branch: 1 branch
BranchTrueFalseTotal
if exists $attr->{"domain"} 0 0 0
96 0 ▶ $opts{'-path'} = $attr->{'path'} if exists($attr->{'path'});
Branch: 1 branch
BranchTrueFalseTotal
if exists $attr->{"path"} 0 0 0
97 0 ▶ if (!$cookie) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($cookie) 0 0 0
98 0 die "Missing cookie $id." .
99 " (Perhaps Cookies not enabled in the browser?)";
100 }
101 0 my $session = $proto->decode($cookie, $attr);
102 0 bless($session, $class);
103 0 $opts{'zlib'} = $attr->{'zlib'};
104 0 $opts{'base64'} = $attr->{'base64'};
105 0 $session->{'_ep_data'} = \%opts;
106 0 $session;
107 }
108  
109 0 ▶sub Store {
Subroutine Store: not called CC=4 SCAR=30.0
Pod undocumented
110 0 my($self, $ep, $id, $locked) = @_;
111 0 my $data = delete $self->{'_ep_data'};
112 0 my $freezed_session = $self->encode($self, $data);
113 0 my $zlib = delete $data->{'zlib'};
114 0 my $base64 = delete $data->{'base64'};
115 0 my $cookie = CGI::Cookie->new(%$data,
116 '-value' => $freezed_session);
117 0 $ep->{'_ep_cookies'}->{$id} = $cookie;
118 0 ▶ if ($locked) {
Branch: 1 branch
BranchTrueFalseTotal
if ($locked) 0 0 0
119 0 ▶ $data->{'zlib'} = $zlib if defined $zlib;
Branch: 1 branch
BranchTrueFalseTotal
if defined $zlib 0 0 0
120 0 ▶ $data->{'base64'} = $base64 if defined $base64;
Branch: 1 branch
BranchTrueFalseTotal
if defined $base64 0 0 0
121 0 $self->{'_ep_data'} = $data;
122 }
123 }
124  
125  
126 0 ▶sub Delete {
Subroutine Delete: not called CC=1 SCAR=6.9
Pod undocumented
127 0 my($self, $ep, $id) = @_;
128 0 my $data = delete $self->{'_ep_data'};
129 0 my $cookie = CGI::Cookie->new('-name' => $id,
130 '-expires' => '-1m',
131 '-value' => '');
132 0 $self->{'_ep_cookies'}->{$id} = $cookie;
133 }
134  
135  
136 1 1;
« blib/lib/HTML/EP/Session/Dumper.pm ↑ Summary blib/lib/HTML/EP/CGIEncryptForm.pm »