Articulate/Role/Storage.pm

filter: Statementstmt 95.7% 45 / 47 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 100% 2 / 2 totaltotal 93.5% 58 / 62 CC 3 SCAR 3.2
CC
3
Cov
92%
get_content_cached
2.0
get_meta_cached
2.0
BEGIN
1.0
CRAP 1.4
« Articulate/Augmentation/Interpreter/Markdown.pm ↑ Summary Articulate/Enrichment.pm »
1 package Articulate::Role::Storage;
2 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 =head1 NAME
7  
8 Articulate::Role::Storage - caching functions
9  
10 =head1 DESCRIPTION
11  
12 This role provides retrieval methods which look for cached versions of
13 the content desired before falling back to the canonical retrieval.
14  
15 =cut
16  
17 =head1 METHODS
18  
19 =cut
20  
21 =head3 get_content_cached
22  
23 $self->get_content_cached( $location );
24  
25 =cut
26  
27 sub get_content_cached {
28 3 ▶ my $self = shift;
Subroutine get_content_cached: called CC=2 SCAR=7.1
Pod documented
29 3 my $location = shift->location;
30 3 my $caching = $self->caching;
31 3 ▶ if ( $caching->is_cached( content => $location ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($caching->is_cached("content", $location)) 0 3 3
32 0 return $caching->get_cached( content => $location );
33 }
34 3 my $content = $self->get_content($location);
35 1 $caching->set_cache( content => $location, $content );
36 1 return $content;
37 }
38  
39 =head3 get_meta_cached
40  
41 $self->get_meta_cached( $location );
42  
43 =cut
44  
45 sub get_meta_cached {
46 3 ▶ my $self = shift;
Subroutine get_meta_cached: called CC=2 SCAR=7.1
Pod documented
47 3 my $location = shift->location;
48 3 my $caching = $self->caching;
49 3 ▶ if ( $caching->is_cached( meta => $location ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($caching->is_cached("meta", $location)) 0 3 3
50 0 return $caching->get_cached( meta => $location );
51 }
52 3 my $meta = $self->get_meta($location);
53 1 $caching->set_cache( meta => $location, $meta );
54 1 return $meta;
55 }
56  
57 around set_content => sub {
58 3 ▶ my ( $orig, $self ) = ( shift, shift );
Subroutine __ANON__: called CC=1 SCAR=0.0
59 3 my $return = $self->$orig(@_);
60 1 $self->caching->set_cache( content => $_[0], $return );
61 1 return $return;
62 5 };
63  
64 around set_meta => sub {
65 3 ▶ my ( $orig, $self ) = ( shift, shift );
Subroutine __ANON__: called CC=1 SCAR=0.0
66 3 my $return = $self->$orig(@_);
67 1 $self->caching->set_cache( meta => $_[0], $return );
68 1 return $return;
69 5 };
70  
71 around delete_item => sub {
72 5 ▶ my ( $orig, $self ) = ( shift, shift );
Subroutine __ANON__: called CC=1 SCAR=0.0
73 5 my $return = $self->$orig(@_);
74 3 $self->caching->clear_cache( meta => $_[0] );
75 3 $self->caching->clear_cache( content => $_[0] );
76  
77 # what about children?
78 # Three possible approaches:
79 # 1. clear cache of anything that looks le it might be a child
80 # 2. storage deletion should recursively delete for all children
81 # 3. storage should return an arrayref of items it deleted
82 3 return $return;
83 5 };
84  
85 around empty_all_content => sub {
86 6 ▶ my ( $orig, $self ) = ( shift, shift );
Subroutine __ANON__: called CC=1 SCAR=0.0
87 6 my $return = $self->$orig(@_);
88 6 $self->caching->empty_cache();
89 6 return $return;
90 5 };
91  
92 5 1;
« Articulate/Augmentation/Interpreter/Markdown.pm ↑ Summary Articulate/Enrichment.pm »