lib/WebService/Libris/FileCache.pm

filter: Statementstmt 75.6% 28 / 37 Branchbran 37.5% 3 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 87.5% 7 / 8 Podpod 33.3% 1 / 3 totaltotal 69.6% 39 / 56 CC 5 SCAR 9.4
CC
5
Cov
69%
set
6.0
get
3.0
_init
2.3
CRAP 2.6
« lib/WebService/Libris/Book.pm ↑ Summary lib/WebService/Libris/Utils.pm »
1 1 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package WebService::Libris::FileCache;
3 1 ▶use Mojo::Base -base;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Mojo::DOM;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 has 'directory';
7  
8 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
9 1 my $class = shift;
10 1 my $self = bless {@_}, $class;
11 1 $self->_init;
12 1 $self
13 }
14  
15 1 ▶sub _init {
Subroutine _init: called CC=2 SCAR=8.4
16 1 my $self = shift;
17 1 my $d = $self->directory;
18 1 ▶ unless (-d $d) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $d) 0 1 1
19 0 require File::Path;
20 0 File::Path::make_path($d)
21 }
22 }
23  
24 3 ▶sub _filename {
Subroutine _filename: called CC=1 SCAR=0.0
25 3 my ($self, $key) = @_;
26 3 $key =~ s{/}{_}g;
27 3 $self->directory . $key . '.xml'
28 }
29  
30 3 ▶sub get {
Subroutine get: called CC=3 SCAR=11.1
Pod undocumented
31 3 my ($self, $key) = @_;
32 3 my $filename = $self->_filename($key);
33 3 ▶ return undef unless open my $h, '<:encoding(UTF-8)', $filename;
Branch: 1 branch
BranchTrueFalseTotal
unless open my $h, "<:encoding(UTF-8)", $filename 0 3 3
34 3 my $contents = do { local $/; <$h> };
35 3 ▶ return undef unless length $contents;
Branch: 1 branch
BranchTrueFalseTotal
unless length $contents 0 3 3
36 3 Mojo::DOM->new->xml(1)->parse($contents);
37 }
38  
39 0 ▶sub set {
Subroutine set: not called CC=2 SCAR=17.9
Pod undocumented
40 0 my ($self, $key, $value) = @_;
41 0 my $filename = $self->_filename($key);
42 0 ▶ open my $h, '>', $filename or die "Can't open file '$filename' for writing: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $h, ">", $filename or die "Can't open file '${filename}' for writing: $!" 0 0 0
43 0 print { $h } $value->to_xml;
44 0 close $h;
45 0 $value;
46 }
47  
48  
49 1 1;
« lib/WebService/Libris/Book.pm ↑ Summary lib/WebService/Libris/Utils.pm »