blib/lib/Furl/Cookies.pm

filter: Statementstmt 24.0% 12 / 50 Branchbran 0.0% 0 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 3 / 6 Podpod 0.0% 0 / 3 totaltotal 20.0% 15 / 75 CC 13 SCAR 44.2
CC
13
Cov
18%
extract_cookies
132.0
add_cookie_header
12.0
new
2.0
CRAP 82.9
↑ Summary Cookies.c »
1 package Furl::Cookies;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Time::Local;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 #use Data::Dumper::Concise;
6  
7 1 our $VERSION = '0.03';
8  
9 1 my $month = {
10 Jan => 1,Feb => 2,Mar => 3,Apr => 4,May => 5,Jun => 6,
11 Jul => 7,Aug => 8,Sep => 9,Oct => 10,Nov => 11,Dec => 12,
12 };
13  
14 0 ▶sub new{
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
15 0 return bless({COOKIES => {},},shift);
16 }
17  
18 0 ▶sub extract_cookies{
Subroutine extract_cookies: not called CC=11 SCAR=48.8
Pod undocumented
19 0 my ($self,$res,$req) = @_;
20 0 $req->uri =~ /^http[s]*:\/\/([^:\/]*)[:]*[0-9]*/;
21 0 my $default_domain = $1;
22 0 for my $cookie (@{$res->headers->{'set-cookie'}}){
23 #print $cookie . "\n";
24 0 my ($expires,$domain,$path,$secure,$key,$value);
25 0 for (split(/;/,$cookie)){
26 0 $_ =~ s/^[\s]*//;
27 0 ▶ $secure = ($_ =~ /secure/)?1:0;
Branch: 1 branch
BranchTrueFalseTotal
$_ =~ /secure/ ? : 0 0 0
28 0 ▶ if($_ =~ /domain/){
Branch: 1 branch
BranchTrueFalseTotal
if ($_ =~ /domain/) 0 0 0
29 0 my @tmp = split(/=/,$_);
30 0 $domain = $tmp[1];
31 }
32 0 ▶ if($_ =~ /path/){
Branch: 1 branch
BranchTrueFalseTotal
if ($_ =~ /path/) 0 0 0
33 0 my @tmp = split(/=/,$_);
34 0 $path = $tmp[1];
35 }
36 0 ▶ if($_ =~ /expires/){
Branch: 1 branch
BranchTrueFalseTotal
if ($_ =~ /expires/) 0 0 0
37 0 my @tmp = split(/=/,$_);
38 0 $tmp[1] =~ /([a-zA-Z]*), ([\w]*)-([\w]*)-([\w]*) ([\w]*):([\w]*):([\w]*) GMT/;
39 0 my ($w,$D,$M,$Y,$h,$m,$s) = ($1,$2,$3,$4,$5,$6,$7);
40 0 $expires = timegm($s,$m,$h,$D,$month->{$M}-1,$Y);
41 }
42 0 ▶ if($_ !~ /expires|path|domain|secure/){
Branch: 1 branch
BranchTrueFalseTotal
unless ($_ =~ /expires|path|domain|secure/) 0 0 0
43 0 my @tmp = split(/=/,$_);
44 0 $key = $tmp[0];
45 0 $value = $tmp[1];
46 }
47 }
48 0 ▶ $domain = $domain?$domain:$default_domain;
Branch: 1 branch
BranchTrueFalseTotal
$domain ? : 0 0 0
49 0 ▶ $path = $path?$path:'/';
Branch: 1 branch
BranchTrueFalseTotal
$path ? : 0 0 0
50 0 ▶ $expires = $expires?$expires:undef;
Branch: 1 branch
BranchTrueFalseTotal
$expires ? : 0 0 0
51 #next if($expires lt time() && $expires);
52 #next if($default_domain !~ /$domain/ && $domain);
53  
54 0 $self->{COOKIES}->{$domain}->{$path}->{$key} = {
55 value => $value,
56 expires => $expires,
57 secure => $secure,
58 };
59 }
60 }
61  
62 0 ▶sub add_cookie_header{
Subroutine add_cookie_header: not called CC=3 SCAR=24.8
Pod undocumented
63 0 my ($self,$req) = @_;
64 0 my $cookies;
65 0 for my $domain (keys %{$self->{COOKIES}}){
66 0 for my $path (keys %{$self->{COOKIES}->{$domain}}){
67 $req->headers->{cookie} = join('; ',
68 0 map{$_ . '=' . $self->{COOKIES}->{$domain}->{$path}->{$_}->{value}}
69 0 (keys %{$self->{COOKIES}->{$domain}->{$path}}));
70 }
71 }
72 }
73 1 1;
74 __END__
↑ Summary Cookies.c »