Session/Store/File.pm

filter: Statementstmt 83.3% 30 / 36 Branchbran 66.6% 4 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 72.7% 8 / 11 Podpod 83.3% 5 / 6 totaltotal 79.6% 47 / 59 CC 5 SCAR 8.1
CC
5
Cov
81%
new
4.4
select
2.0
update
2.0
CRAP 2.2
« Session/State/Test.pm ↑ Summary Session/ID/MD5.pm »
1 package HTTP::Session::Store::File;
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 base qw/Class::Accessor::Fast/;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Storable;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 __PACKAGE__->mk_ro_accessors(qw/dir/);
8  
9 2 ▶sub new {
Subroutine new: called CC=4 SCAR=14.9
Pod documented
10 2 my $class = shift;
11 0 ▶ my %args = ref($_[0]) ? %{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 2 2
12 # check requried parameters
13 2 for (qw/dir/) {
14 2 ▶ Carp::croak "missing parameter $_" unless $args{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{$_} 0 2 2
15 }
16 # set default values
17 2 bless {%args}, $class;
18 }
19  
20 2 ▶sub select {
Subroutine select: called CC=2 SCAR=6.9
Pod documented
21 2 my ($self, $key) = @_;
22 2 ▶ if (open my $fh, '<', $self->_to_path($key)) {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $fh, "<", $self->_to_path($key)) 1 1 2
23 1 my $value = Storable::fd_retrieve($fh);
24 1 close $fh;
25 1 return $value;
26 }
27 1 undef;
28 }
29  
30 1 ▶sub insert {
Subroutine insert: called CC=1 SCAR=0.0
Pod documented
31 1 my ($self, $key, $value) = @_;
32 1 Storable::nstore $value, $self->_to_path($key);
33 }
34  
35 0 ▶sub update {
Subroutine update: not called CC=1 SCAR=6.9
Pod documented
36 0 shift->insert(@_);
37 }
38  
39 0 ▶sub delete {
Subroutine delete: not called CC=1 SCAR=6.9
Pod documented
40 0 my ($self, $key) = @_;
41 0 unlink $self->_to_path($key);
42 }
43  
44 3 ▶sub _to_path {
Subroutine _to_path: called CC=1 SCAR=0.2
45 3 my ($self, $key) = @_;
46 0 $key =~ s/([^A-Za-pr-z0-9_])/sprintf("q%02x", ord $1)/eg;
47 3 $self->dir . '/' . $key . '.dat';
48 }
49  
50 0 ▶sub cleanup { Carp::croak "This storage doesn't support cleanup" }
Subroutine cleanup: not called CC=1 SCAR=6.9
Pod undocumented
51  
52 1 1;
53 __END__
« Session/State/Test.pm ↑ Summary Session/ID/MD5.pm »