| 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
| |||||||||||||
| 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
| |||||||||||||
| 40 | 0 | ▶ | fatal('tts.cache.id.generate.data') if ! defined $data; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 41 | 0 | ▶ | LOG( IDGEN => 'Generating ID from empty data' ) if DEBUG; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 42 | } | ||||||||||||
| 43 | |||||||||||||
| 44 | $self->set( | ||||||||||||
| 45 | 21 | ▶ | $custom ? $self->_custom( $data, $regex ) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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
| |||||||||||||
| 55 | 8 | ▶ | my $regex = shift || RE_INVALID_CID; | ||||||||||
|
Condition50%1/2
shift() || \'(?^msx:[^A-Za-z_0-9])'
MC/DC0%0/1
shift() || \'(?^msx:[^A-Za-z_0-9])'
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||
| 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
| |||||||||||||
| 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)
MC/DC0%0/1
shift() || (return)
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||
| 71 | 21 | ▶ | LOG( DESTROY => ref $self ) if DEBUG; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 72 | 21 | return; | |||||||||||
| 73 | } | ||||||||||||
| 74 | |||||||||||||
| 75 | 32 | 1; | |||||||||||
| 76 | |||||||||||||
| 77 | __END__ | ||||||||||||