| 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
| |||||||||||
| 28 | 0 | ▶ | if($_ =~ /domain/){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | 0 | my @tmp = split(/=/,$_); | |||||||||
| 30 | 0 | $domain = $tmp[1]; | |||||||||
| 31 | } | ||||||||||
| 32 | 0 | ▶ | if($_ =~ /path/){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | 0 | my @tmp = split(/=/,$_); | |||||||||
| 34 | 0 | $path = $tmp[1]; | |||||||||
| 35 | } | ||||||||||
| 36 | 0 | ▶ | if($_ =~ /expires/){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 49 | 0 | ▶ | $path = $path?$path:'/'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | 0 | ▶ | $expires = $expires?$expires:undef; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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__ | ||||||||||