| 1 | package Web::Session::Store::File; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 6 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 6 | ▶ | use Fcntl qw(O_RDWR O_CREAT O_EXCL); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 6 | ▶ | use Errno qw(EEXIST); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 6 | ▶ | use Apache::Session::Store::File; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 6 | our @ISA = qw(Apache::Session::Store::File); | |||||||||||||||||||
| 8 | 6 | our $VERSION = '1.0.0'; | |||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | # The inherited insert() and update() print the serialized session as is, so | ||||||||||||||||||||
| 11 | # Perl writes Latin-1 bytes when every character fits in a byte and UTF-8 | ||||||||||||||||||||
| 12 | # otherwise. Reading then has to guess which one it was, and the two are | ||||||||||||||||||||
| 13 | # indistinguishable when the Latin-1 bytes also form a valid UTF-8 sequence | ||||||||||||||||||||
| 14 | # ("\x{c3}\x{a9}" comes back as "\x{e9}"). The JSON serializer documents its | ||||||||||||||||||||
| 15 | # output as UTF-8 text, so always write UTF-8 bytes, whatever the internal | ||||||||||||||||||||
| 16 | # form of the string | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 36 | ▶ | sub insert { | ||||||||||||||||||
|
Subroutine
insert: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 19 | 36 | my $self = shift; | |||||||||||||||||||
| 20 | 36 | my $session = shift; | |||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | # Like the parent store, never overwrite an existing session (O_EXCL | ||||||||||||||||||||
| 23 | # also closes the race between the existence check and the open) | ||||||||||||||||||||
| 24 | 36 | $self->_open( $session, 1 ); | |||||||||||||||||||
| 25 | 35 | $self->_write($session); | |||||||||||||||||||
| 26 | } | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 39 | ▶ | sub update { | ||||||||||||||||||
|
Subroutine
update: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||
| 29 | 39 | my $self = shift; | |||||||||||||||||||
| 30 | 39 | my $session = shift; | |||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 39 | ▶ | $self->_open($session) unless ( $self->{opened} ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 33 | 39 | ▶ | truncate( $self->{fh}, 0 ) || die "Could not truncate file: $!"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 34 | 39 | seek( $self->{fh}, 0, 0 ); | |||||||||||||||||||
| 35 | 39 | $self->_write($session); | |||||||||||||||||||
| 36 | } | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 37 | ▶ | sub _open { | ||||||||||||||||||
|
Subroutine
_open: called CC=5 SCAR=16.8
| |||||||||||||||||||||
| 39 | 37 | my ( $self, $session, $exclusive ) = @_; | |||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | my $directory = $session->{args}->{Directory} | ||||||||||||||||||||
| 42 | 37 | ▶ | || $Apache::Session::Store::File::Directory; | ||||||||||||||||||
|
Condition33%1/3
$session->{'args'}{'Directory'} || $Apache::Session::Store::File::Directory
MC/DC0%0/2
$session->{'args'}{'Directory'} || $Apache::Session::Store::File::Directory
$session->{'args'}{'Directory'}
$Apache::Session::Store::File::Directory
Truth table33%1/3
A || B
A= $session->{'args'}{'Directory'}B= $Apache::Session::Store::File::Directory
| |||||||||||||||||||||
| 43 | 37 | my $file = $directory . '/' . $session->{data}->{_session_id}; | |||||||||||||||||||
| 44 | 37 | ▶ | unless ( | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 45 | sysopen( $self->{fh}, $file, | ||||||||||||||||||||
| 46 | O_RDWR | O_CREAT | ( $exclusive ? O_EXCL : 0 ) ) | ||||||||||||||||||||
| 47 | ) | ||||||||||||||||||||
| 48 | { | ||||||||||||||||||||
| 49 | 1 | ▶ | die "Object already exists in the data store" if ( $! == EEXIST ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 50 | 0 | die "Could not open file $file: $!"; | |||||||||||||||||||
| 51 | } | ||||||||||||||||||||
| 52 | 36 | $self->{opened} = 1; | |||||||||||||||||||
| 53 | } | ||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 74 | ▶ | sub _write { | ||||||||||||||||||
|
Subroutine
_write: called CC=2 SCAR=6.9
| |||||||||||||||||||||
| 56 | 74 | my ( $self, $session ) = @_; | |||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | # Work on a copy: {serialized} is reused by the caller and other stores | ||||||||||||||||||||
| 59 | 74 | my $data = $session->{serialized}; | |||||||||||||||||||
| 60 | 74 | ▶ | utf8::encode($data) if ( utf8::is_utf8($data) ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 61 | 74 | print { $self->{fh} } $data; | |||||||||||||||||||
| 62 | 74 | $self->{fh}->flush(); | |||||||||||||||||||
| 63 | } | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | 6 | 1; | |||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | __END__ | ||||||||||||||||||||