| 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
| |||||||||||
| 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
| |||||||||||
| 34 | 3 | my $contents = do { local $/; <$h> }; | |||||||||
| 35 | 3 | ▶ | return undef unless length $contents; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 43 | 0 | print { $h } $value->to_xml; | |||||||||
| 44 | 0 | close $h; | |||||||||
| 45 | 0 | $value; | |||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | |||||||||||
| 49 | 1 | 1; | |||||||||