Scrappy/Session.pm

filter: Statementstmt 31.1% 14 / 45 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 50.0% 4 / 8 Podpod 75.0% 3 / 4 totaltotal 25.0% 21 / 84 CC 14 SCAR 35.2
CC
14
Cov
20%
stash
72.0
write
20.0
load
12.0
CRAP 33.7
« Scrappy/Action.pm ↑ Summary Scrappy/Project.pm »
1 # ABSTRACT: Scrappy Scraper Session Handling
2 # Dist::Zilla: +PodWeaver
3  
4 package Scrappy::Session;
5  
6 10 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
7 10 $Scrappy::Session::VERSION = '0.94112090';
8 }
9  
10 # load OO System
11 10 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 # load other libraries
14 10 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 10 ▶use YAML::Syck;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 10 $YAML::Syck::ImplicitTyping = 1;
17  
18 10 has 'auto_save' => (is => 'rw', isa => 'Bool', default => 1);
19 10 has 'file' => (is => 'rw', isa => 'Str');
20  
21  
22 0 ▶sub load {
Subroutine load: not called CC=3 SCAR=24.8
Pod documented
23 0 my $self = shift;
24 0 my $file = shift;
25  
26 0 ▶ if ($file) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file) 0 0 0
27  
28 0 $self->file($file);
29  
30 0 ▶ croak("Session file $file does not exist or is not read/writable")
Branch: 1 branch
BranchTrueFalseTotal
unless -f $file 0 0 0
31 unless -f $file;
32  
33 # load session file
34 0 $self->{stash} = LoadFile($file);
35 }
36  
37 0 return $self->{stash};
38 }
39  
40  
41 0 ▶sub stash {
Subroutine stash: not called CC=8 SCAR=42.8
Pod documented
42 0 my $self = shift;
43 0 ▶ $self->{stash} = {} unless defined $self->{stash};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"stash"} 0 0 0
44  
45 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
46 0 ▶ my $stash = @_ > 1 ? {@_} : $_[0];
Branch: 1 branch
BranchTrueFalseTotal
@_ > 1 ? : 0 0 0
47 0 ▶ if ($stash) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stash) 0 0 0
48 0 ▶ if (ref $stash eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $stash eq 'HASH') { } 0 0 0
49 0 for (keys %{$stash}) {
50 0 ▶ if (lc $_ ne ':file') {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $_ ne ':file') { } 0 0 0
51 0 $self->{stash}->{$_} = $stash->{$_};
52 }
53 else {
54 0 $self->{file} = $stash->{$_};
55 }
56 }
57 }
58 else {
59 0 return $self->{stash}->{$stash};
60 }
61 }
62 }
63  
64 0 $self->auto_write;
65 0 return $self->{stash};
66 }
67  
68  
69 0 ▶sub write {
Subroutine write: not called CC=4 SCAR=30.0
Pod documented
70 0 my $self = shift;
71 0 ▶ my $file = shift || $self->file;
Condition0%0/3
shift() || $self->file
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $self->file
shift() $self->file
Truth table0%0/3
A || B
A= shift()B= $self->file
ABresult
1X1
011
000
72  
73 0 $self->file($file);
74  
75 0 ▶ if ($file) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file) 0 0 0
76  
77 # write session file
78 0 DumpFile($file, $self->{stash});
79  
80 # ... ummm
81 0 ▶ croak("Session file $file does not exist or is not read/writable")
Branch: 1 branch
BranchTrueFalseTotal
unless -f $file 0 0 0
82 unless -f $file;
83 }
84  
85 0 return $self->{stash};
86 }
87  
88 0 ▶sub auto_write {
Subroutine auto_write: not called CC=2 SCAR=17.9
Pod undocumented
89 0 my $self = shift;
90 0 ▶ $self->write if $self->auto_save;
Branch: 1 branch
BranchTrueFalseTotal
if $self->auto_save 0 0 0
91  
92 0 return $self;
93 }
94  
95 10 1;
96  
97 __END__
« Scrappy/Action.pm ↑ Summary Scrappy/Project.pm »