FusqlFS/Cache/Base.pm

filter: Statementstmt 100% 15 / 15 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 100% 2 / 2 totaltotal 95.8% 23 / 24 CC 2 SCAR 2.9
CC
2
Cov
94%
new
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.3
« FusqlFS/Backend/PgSQL.pm ↑ Summary FusqlFS/Backend/SQLite/Table/Test.pm »
1 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 5 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package FusqlFS::Cache::Base;
5 5 ▶use FusqlFS::Version;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 our $VERSION = $FusqlFS::Version::VERSION;
7  
8 =head1 NAME
9  
10 FusqlFS::Cache::Base - base abstract class for cache strategy classes
11 implementation
12  
13 =head1 SYNOPSIS
14  
15 package FusqlFS::Cache::CleverStrategy;
16 use parent 'FusqlFS::Cache::Base';
17  
18 sub TIEHASH
19 {
20 # ...
21 }
22  
23 sub FETCH
24 {
25 # ...
26 }
27  
28 sub STORE
29 {
30 # ...
31 }
32  
33 =head1 DESCRIPTION
34  
35 This is an abstract base class for all cache strategy subclasses.
36  
37 FusqlFS cache is a hash. To implement any cache strategy you need to create
38 a hash tie()-able class (see also L<perltie> for more info) which will be
39 tied to cache hash and should implement cache strategy you want.
40  
41 This class defines main cache class interface. See L</METHODS> section for
42 details on this interface.
43  
44 =head1 METHODS
45  
46 =over
47  
48 =cut
49  
50 =item new
51  
52 Class constructor (so called).
53  
54 Input: @parameters.
55 Output: $cache_hashref.
56  
57 This method is not a real constructor, it's actually a tie()-er.
58  
59 It creates new empty hash, checks if given parameters satisfy this concrete
60 class implementation and tie()s hash to this class if everything ok.
61  
62 The returned value is a hashref tied to the class (or untied if parameters
63 don't satisfy class's requirements). See also L</is_needed> method to learn how
64 criteria for correct cache parameters are defined.
65  
66 =begin testing new
67  
68 #!noinst
69  
70 my $test = $_tcls->new();
71 isa_ok $test, 'HASH';
72 is tied($test), undef;
73  
74 =end testing
75 =cut
76 sub new
77 1 ▶{
Subroutine new: called CC=2 SCAR=7.0
Pod documented
78 1 my $class = shift;
79 1 my %cache;
80 1 ▶ tie %cache, $class, @_ if $class->is_needed(@_);
Branch: 1 branch
BranchTrueFalseTotal
if $class->is_needed(@_) 0 1 1
81 1 return \%cache;
82 }
83  
84 =item is_needed
85  
86 I<Abstract method> called to determine if cache parameters satisfy this cache
87 strategy's criteria.
88  
89 Input: @parameters.
90 Output: $satisfied.
91  
92 This method is called before the class is tied to real cache hash to determine
93 if cache strategy implemented by the class can be used with given parameters.
94  
95 The method is passed the same parameters, as L</new> method, and must return
96 boolean value: true if these parameters have sense for the cache strategy
97 or false otherwise.
98  
99 If this method returns false no cache class instance is created nor tied to
100 cache hash, so cache strategy is fallen back to `memory'.
101  
102 See also L<FusqlFS::Cache> for more info about cache strategies initialization.
103  
104 =cut
105 sub is_needed
106 1 ▶{
Subroutine is_needed: called CC=1 SCAR=0.0
Pod documented
107 1 return;
108 }
109  
110 5 1;
111  
112 __END__
« FusqlFS/Backend/PgSQL.pm ↑ Summary FusqlFS/Backend/SQLite/Table/Test.pm »