Simple/Cache/ID.pm

filter: Statementstmt 93.4% 43 / 46 Branchbran 43.7% 7 / 16 Conditioncond 50.0% 2 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 11 / 11 Podpod 100% 4 / 4 totaltotal 80.7% 67 / 83 CC 11 SCAR 13.2
CC
11
Cov
79%
generate
8.1
_custom
4.4
DESTROY
3.2
CRAP 3.8
« Simple/Util.pm ↑ Summary Simple/Dummy.pm »
1 package Text::Template::Simple::Cache::ID;
2 32 $Text::Template::Simple::Cache::ID::VERSION = '0.91';
3 32 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 32 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 32 ▶use overload q{""} => 'get';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 32 ▶use Text::Template::Simple::Constants qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
8 MAX_FILENAME_LENGTH
9 RE_INVALID_CID
10 32 );
11 32 ▶use Text::Template::Simple::Util qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
12 LOG
13 DEBUG
14 DIGEST
15 fatal
16 32 );
17  
18 21 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
19 21 my $class = shift;
20 21 my $self = bless do { \my $anon }, $class;
21 21 return $self;
22 }
23  
24 42 ▶sub get {
Subroutine get: called CC=1 SCAR=0.0
Pod documented
25 42 my $self = shift;
26 42 return ${$self};
27 }
28  
29 21 ▶sub set { ## no critic (ProhibitAmbiguousNames)
Subroutine set: called CC=2 SCAR=7.0
Pod documented
30 21 my $self = shift;
31 21 my $val = shift;
32 21 ▶ ${$self} = $val if defined $val;
Branch: 1 branch
BranchTrueFalseTotal
if defined $val 21 0 21
33 21 return;
34 }
35  
36 21 ▶sub generate { # cache id generator
Subroutine generate: called CC=5 SCAR=20.9
Pod documented
37 21 my($self, $data, $custom, $regex) = @_;
38  
39 21 ▶ if ( ! $data ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($data) 0 21 21
40 0 ▶ fatal('tts.cache.id.generate.data') if ! defined $data;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data 0 0 0
41 0 ▶ LOG( IDGEN => 'Generating ID from empty data' ) if DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if DEBUG() 0 0 0
42 }
43  
44 $self->set(
45 21 ▶ $custom ? $self->_custom( $data, $regex )
Branch: 1 branch
BranchTrueFalseTotal
$custom ? : 8 13 21
46 : $self->DIGEST->add( $data )->hexdigest
47 );
48  
49 21 return $self->get;
50 }
51  
52 8 ▶sub _custom {
Subroutine _custom: called CC=4 SCAR=14.8
53 8 my $self = shift;
54 8 ▶ my $data = shift or fatal('tts.cache.id._custom.data');
Branch: 1 branch
BranchTrueFalseTotal
my $data = shift() or fatal("tts.cache.id._custom.data") 8 0 8
55 8 ▶ my $regex = shift || RE_INVALID_CID;
Condition50%1/2
shift() || \'(?^msx:[^A-Za-z_0-9])'
l!l
08
MC/DC0%0/1
shift() || \'(?^msx:[^A-Za-z_0-9])'
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
56 8 $data =~ s{$regex}{_}xmsg; # remove bogus characters
57 8 my $len = length $data;
58  
59 # limit file name length
60 8 ▶ if ( $len > MAX_FILENAME_LENGTH ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len > 120) 0 8 8
61 0 $data = substr $data,
62 $len - MAX_FILENAME_LENGTH,
63 MAX_FILENAME_LENGTH;
64 }
65  
66 8 return $data;
67 }
68  
69 21 ▶sub DESTROY {
Subroutine DESTROY: called CC=3 SCAR=11.7
70 21 ▶ my $self = shift || return;
Condition50%1/2
shift() || (return)
l!l
210
MC/DC0%0/1
shift() || (return)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
71 21 ▶ LOG( DESTROY => ref $self ) if DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if DEBUG() 0 21 21
72 21 return;
73 }
74  
75 32 1;
76  
77 __END__
« Simple/Util.pm ↑ Summary Simple/Dummy.pm »