Labyrinth/CookieLib.pm

filter: Statementstmt 31.8% 21 / 66 Branchbran 0.0% 0 / 30 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 30.7% 4 / 13 Podpod 100% 9 / 9 totaltotal 26.5% 34 / 128 CC 21 SCAR 33.8
CC
21
Cov
21%
GetCompressedCookies
72.0
SetCookieDomain
30.0
SetCookie
30.0
CRAP 29.4
« Labyrinth/IPAddr.pm ↑ Summary Labyrinth/Writer/Parser/TT.pm »
1 package Labyrinth::CookieLib;
2  
3 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 12 ▶use vars qw(%cookie_config $VERSION @ISA %EXPORT_TAGS @EXPORT @EXPORT_OK);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 12 $VERSION = '5.32';
8  
9 =head1 NAME
10  
11 Labyrinth::CookieLib - Cookie Management for Labyrinth
12  
13 =head1 DESCRIPTION
14  
15 This collection of functions provides the cookie functionality within
16 the Labyrinth framework.
17  
18 Based on the NMS cookielib script.
19  
20 =cut
21  
22 # -------------------------------------
23 # Library Modules
24  
25 12 ▶use Labyrinth::Variables;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 # -------------------------------------
28 # Export Details
29  
30 12 require Exporter;
31 12 @ISA = qw(Exporter);
32  
33 12 %EXPORT_TAGS = (
34 'all' => [ qw(
35 SetCookieExpDate SetCookiePath SetCookieDomain SetSecureCookie
36 GetCookies SetCookie SetCookies GetCompressedCookies SetCompressedCookies
37 ) ]
38 );
39  
40 12 @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
41 12 @EXPORT = ( @{ $EXPORT_TAGS{'all'} } );
42  
43 # -------------------------------------
44 # The Subs
45  
46 =head1 FUNCTIONS
47  
48 =over 4
49  
50 =item SetCookieExpDate
51  
52 Set the cookie expiration date.
53  
54 =item SetCookiePath
55  
56 Set the cookie path.
57  
58 =item SetCookieDomain
59  
60 Set the cookie domain.
61  
62 =item SetSecureCookie
63  
64 Set the cookie security.
65  
66 =item GetCookies
67  
68 Get all existing cookies.
69  
70 =item SetCookie
71  
72 Set a single cookie.
73  
74 =item SetCookies
75  
76 Set all given cookies.
77  
78 =item GetCompressedCookies
79  
80 Get all compressed cookies.
81  
82 =item SetCompressedCookies
83  
84 Set all given cookies as compressed cookies.
85  
86 =back
87  
88 =cut
89  
90 0 ▶sub SetCookieExpDate {
Subroutine SetCookieExpDate: not called CC=1 SCAR=6.9
Pod documented
91 0 $cookie_config{expires} = $_[0];
92 }
93  
94 0 ▶sub SetCookiePath {
Subroutine SetCookiePath: not called CC=1 SCAR=6.9
Pod documented
95 0 $cookie_config{path} = $_[0];
96 }
97  
98 0 ▶sub SetCookieDomain {
Subroutine SetCookieDomain: not called CC=5 SCAR=34.0
Pod documented
99  
100 0 ▶ if ($_[0] =~ /(.com|.edu|.net|.org|.gov|.mil|.int)$/i &&
Branch: 2 branches
BranchTrueFalseTotal
if ($_[0] =~ /(.com|.edu|.net|.org|.gov|.mil|.int)$/i and $_[0] =~ /\.[^.]+\.\w{3}$/) { } 0 0 0
elsif (not $_[0] =~ /(.com|.edu|.net|.org|.gov|.mil|.int)$/i and $_[0] =~ /\.[^.]+\.[^.]+\./) { } 0 0 0
Condition0%0/3
$_[0] =~ /(.com|.edu|.net|.org|.gov|.mil|.int)$/i and $_[0] =~ /\.[^.]+\.\w{3}$/
!ll&&!rl&&r
000
MC/DC0%0/2
$_[0] =~ /(.com|.edu|.net|.org|.gov|.mil|.int)$/i and $_[0] =~ /\.[^.]+\.\w{3}$/
$_[0] =~ /(.com|.edu|.net|.org|.gov|.mil|.int)$/i $_[0] =~ /\.[^.]+\.\w{3}$/
Truth table0%0/3
A and B
A= $_[0] =~ /(.com|.edu|.net|.org|.gov|.mil|.int)$/iB= $_[0] =~ /\.[^.]+\.\w{3}$/
ABresult
0X0
100
111
101 $_[0] =~ /\.[^.]+\.\w{3}$/) {
102 0 $cookie_config{domain} = $_[0];
103 0 return 1;
104 ▶ } elsif ($_[0] !~ /(.com|.edu|.net|.org|.gov|.mil|.int)$/i &&
Condition0%0/3
not $_[0] =~ /(.com|.edu|.net|.org|.gov|.mil|.int)$/i and $_[0] =~ /\.[^.]+\.[^.]+\./
!ll&&!rl&&r
000
MC/DC0%0/2
not $_[0] =~ /(.com|.edu|.net|.org|.gov|.mil|.int)$/i and $_[0] =~ /\.[^.]+\.[^.]+\./
not $_[0] =~ /(.com|.edu|.net|.org|.gov|.mil|.int)$/i $_[0] =~ /\.[^.]+\.[^.]+\./
Truth table0%0/3
not(A) and B
A= not $_[0] =~ /(.com|.edu|.net|.org|.gov|.mil|.int)$/iB= $_[0] =~ /\.[^.]+\.[^.]+\./
ABresult
0X0
100
111
105 $_[0] =~ /\.[^.]+\.[^.]+\./) {
106 0 $cookie_config{domain} = $_[0];
107 0 return 1;
108 } else {
109 0 return 0;
110 }
111 }
112  
113 0 ▶sub SetSecureCookie {
Subroutine SetSecureCookie: not called CC=1 SCAR=6.9
Pod documented
114 0 $cookie_config{secure} = $_[0];
115 }
116  
117 0 ▶sub GetCookies {
Subroutine GetCookies: not called CC=3 SCAR=24.8
Pod documented
118 0 my @cookies = @_;
119  
120 0 my $exists = 0;
121 0 foreach my $name (@cookies)
122 {
123 0 my $value = $cgi->cookie($name);
124 0 $main::Cookies{$name} = $value;
125 0 ▶ $exists = 1 if $value;
Branch: 1 branch
BranchTrueFalseTotal
if $value 0 0 0
126 }
127 0 return $exists;
128 }
129  
130 0 ▶sub SetCookie {
Subroutine SetCookie: not called CC=5 SCAR=34.0
Pod documented
131 0 my ($name,$value) = @_;
132 my $c = $cgi->cookie (
133 -name => $name,
134 -value => $value,
135 -expires => (exists($cookie_config{expires}) ? $cookie_config{expires} : undef),
136 -domain => (exists($cookie_config{domain}) ? $cookie_config{domain} : undef),
137 -secure => (exists($cookie_config{secure}) ? $cookie_config{secure} : undef),
138 0 ▶ -path => (exists($cookie_config{path}) ? $cookie_config{path} : undef),
Branch: 4 branches
BranchTrueFalseTotal
exists $Labyrinth::CookieLib::cookie_config{'expires'} ? : 0 0 0
exists $Labyrinth::CookieLib::cookie_config{'domain'} ? : 0 0 0
exists $Labyrinth::CookieLib::cookie_config{'secure'} ? : 0 0 0
exists $Labyrinth::CookieLib::cookie_config{'path'} ? : 0 0 0
139 );
140 0 return $c;
141 }
142  
143 0 ▶sub SetCookies {
Subroutine SetCookies: not called CC=2 SCAR=17.9
Pod documented
144 0 my (%input) = @_;
145 0 ▶ while( my($name,$value) = each %input ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %input) 0 0 0
146 0 my $c = SetCookie($name,$value);
147 0 print "Set-Cookie: ", $c, "\n";
148 }
149 }
150  
151 0 ▶sub GetCompressedCookies {
Subroutine GetCompressedCookies: not called CC=8 SCAR=42.8
Pod documented
152 0 my($cookie_name,@cookies) = @_;
153 0 my $exists = 0;
154  
155 0 ▶ return unless( GetCookies(@_) );
Branch: 1 branch
BranchTrueFalseTotal
unless GetCookies(@_) 0 0 0
156  
157 # extract specified cookies
158 0 ▶ if( @cookies ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@cookies) { } 0 0 0
159 0 foreach my $name (@cookies) {
160 0 ▶ if($main::Cookies{$cookie_name} =~ /$name\:\:([^&]+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::Cookies{$cookie_name} =~ /$name\:\:([^&]+)/) 0 0 0
161 0 my $value = $1;
162 0 $main::Cookies{$name} = $value;
163 0 ▶ $exists = 1 if $value;
Branch: 1 branch
BranchTrueFalseTotal
if $value 0 0 0
164 }
165 }
166  
167 # extract all cookies
168 } else {
169 0 foreach my $cookie (split /&/, $main::Cookies{$cookie_name}) {
170 0 my ($name,$value) = (split /::/, $cookie);
171 0 $main::Cookies{$name} = $value;
172 0 ▶ $exists = 1 if $value;
Branch: 1 branch
BranchTrueFalseTotal
if $value 0 0 0
173 }
174 }
175  
176 0 return $exists;
177 }
178  
179 0 ▶sub SetCompressedCookies {
Subroutine SetCompressedCookies: not called CC=3 SCAR=24.8
Pod documented
180 0 my($cookie_name,@cookies) = @_;
181 0 my $cookie_value = "";
182  
183 0 my %input = (@cookies);
184 0 ▶ while( my($name,$value) = each %input ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %input) 0 0 0
185 0 ▶ if ($cookie_value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cookie_value) { } 0 0 0
186 0 $cookie_value .= '&'.$name.'::'.$value;
187 } else {
188 0 $cookie_value = $name.'::'.$value;
189 }
190 }
191 0 SetCookies($cookie_name,$cookie_value);
192 }
193  
194 12 1;
195  
196 __END__
« Labyrinth/IPAddr.pm ↑ Summary Labyrinth/Writer/Parser/TT.pm »