| 1 | ##---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | ## Module Generic - ~/lib/Module/Generic/File/Mmap.pm | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | ## Version v0.1.5 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | ## Copyright(c) 2025 DEGUEST Pte. Ltd. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | ## Author: Jacques Deguest <jack@deguest.jp> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | ## Created 2022/07/26 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | ## Modified 2025/04/23 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | ## All rights reserved | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | ## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | ## This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | ## under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | ##---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | package Module::Generic::File::Mmap; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | BEGIN | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 2 | warnings::register_categories( 'Module::Generic' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 2 | ▶ | use parent qw( Module::Generic ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 2 | ▶ | use vars qw( $VERSION $HAS_CACHE_MMAP $HAS_B64 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 2 | ▶ | use Data::UUID; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # This is disruptive for everybody. Bad idea. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | # use JSON 4.03 qw( -convert_blessed_universally ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 2 | ▶ | use JSON 4.03; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 2 | ▶ | use Module::Generic::File qw( file sys_tmpdir ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 2 | our $HAS_CACHE_MMAP = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 2 | our $VERSION = 'v0.1.5'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | sub init | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: not called CC=15 SCAR=54.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | $self->{base64} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | $self->{cache_file} = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | # Default action when accessing a shared file cache? If 1, it will create it if it does not exist already | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | $self->{create} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | $self->{destroy} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | $self->{key} = Data::UUID->new->create_str; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | $self->{mode} = 0666; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | $self->{serial} = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | $self->{size} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | $self->{_packing_method} = 'json'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | $self->{_init_strict_use_sub} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | $self->SUPER::init( @_ ) || return( $self->pass_error ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | unless( $HAS_CACHE_MMAP ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | $self->_load_class( 'Cache::FastMmap' ) || return( $self->pass_error ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | $HAS_CACHE_MMAP = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | return( $self->error( "No key was set." ) ) if( !defined( $self->{key} ) || !length( $self->{key} ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $self->{"key"} and length $self->{"key"}
MC/DC0%0/2
defined $self->{"key"} and length $self->{"key"}
defined $self->{"key"}
length $self->{"key"}
Truth table0%0/3
A and B
A= defined $self->{"key"}B= length $self->{"key"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | $self->SUPER::init( @_ ) || return( $self->pass_error ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | my $tmpdir = sys_tmpdir(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | $self->{_cache_dir} = $tmpdir->child( 'mmap_data' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | if( $self->{_cache_dir}->exists && !$self->{_cache_dir}->can_write ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"_cache_dir"}->exists and not $self->{"_cache_dir"}->can_write
MC/DC0%0/2
$self->{"_cache_dir"}->exists and not $self->{"_cache_dir"}->can_write
$self->{"_cache_dir"}->exists
not $self->{"_cache_dir"}->can_write
Truth table0%0/3
A and not(B)
A= $self->{"_cache_dir"}->existsB= not $self->{"_cache_dir"}->can_write
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | warn( "You do not have write permission to the mmap data directory $self->{_cache_dir}" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | # A cache file will be provided either by the user, either by us with the open() method. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | if( my $f = $self->cache_file ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | # try-catch | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | eval | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | # No serialiser because we manage ths ourself | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | my $cache = Cache::FastMmap->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | ( ( defined( $self->{destroy} ) && length( $self->{destroy} ) ) ? ( unlink_on_exit => $self->{destroy} ) : () ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | share_file => "$f", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | ( $self->{size} ? ( cache_size => $self->{size} ) : () ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | ( $self->{mode} ? ( permissions => $self->{mode} ) : () ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition0%0/3
defined $self->{"destroy"} and length $self->{"destroy"}
MC/DC0%0/2
defined $self->{"destroy"} and length $self->{"destroy"}
defined $self->{"destroy"}
length $self->{"destroy"}
Truth table0%0/3
A and B
A= defined $self->{"destroy"}B= length $self->{"destroy"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | serializer => '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | $self->{_cache} = $cache; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | if( $@ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | return( $self->error( "Error trying to instantiate a Cache::FastMmap object: $@" ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | $self->{owner} = $$; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | $self->{removed} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | return( $self ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # This class does not convert to an HASH | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | sub as_hash { return( $_[0] ); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_hash: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | sub base64 { return( shift->_set_get_scalar( 'base64', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
base64: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | sub cache_file { return( shift->_set_get_file( 'cache_file', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cache_file: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | sub cbor { return( shift->_packing_method( 'cbor' ) ); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cbor: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | sub create { return( shift->_set_get_boolean( 'create', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | sub destroy { return( shift->_set_get_boolean( 'destroy', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
destroy: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | sub exists | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
exists: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | my $cache = $self->_cache || return( $self->error( "No Cache::FastMmap object. It seems it is gone!" ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->_cache || (return $self->error('No Cache::FastMmap object. It seems it is gone!'))
MC/DC0%0/1
$self->_cache || (return $self->error('No Cache::FastMmap object. It seems it is gone!'))
$self->_cache
Truth table0%0/2
A
A= $self->_cache
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | my $file = $cache->{share_file} || return(0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$cache->{'share_file'} || (return 0)
MC/DC0%0/1
$cache->{'share_file'} || (return 0)
$cache->{'share_file'}
Truth table0%0/2
A
A= $cache->{'share_file'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | return( -e( "$file" ) ? 1 : 0 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | sub flags | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
flags: not called CC=5 SCAR=26.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | my $opts = $self->_get_args_as_hash( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 2 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 2 | ▶ | no strict 'subs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | $opts->{create} = $self->create unless( length( $opts->{create} ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | $opts->{mode} = $self->mode unless( length( $opts->{mode} ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | my $flags = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | $flags |= 0600 if( $opts->{create} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | $flags |= ( $opts->{mode} || 0666 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$opts->{'mode'} || 438
MC/DC0%0/1
$opts->{'mode'} || 438
$opts->{'mode'}
Truth table0%0/2
A
A= $opts->{'mode'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | return( $flags ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | sub ftok | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ftok: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | my $id = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | my $f = sys_tmpdir(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | return( int( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | ( int( $f->inode ) & 0xffff ) | | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | int( ( $f->device ) << 16 ) | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | ( ( $id & 0xff ) << 21 ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | sub has_xs { return( shift->_is_class_loadable( 'Cache::FastMmap' ) ); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has_xs: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | sub id { return( shift->_set_get_scalar( 'id', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
id: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | sub json { return( shift->_packing_method( 'json' ) ); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
json: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | # sub key { return( shift->_set_get_scalar( 'key', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | sub key | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
key: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | ▶ | if( @_ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | $self->{key} = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | $self->{serial} = $self->_str2key( $self->{key} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | return( $self->{key} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | # NOTE: lock is a noop | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | sub lock { return(1); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lock: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | # NOTE: locked is a noop | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | sub locked { return(1); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
locked: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | ▶ | sub mode { return( shift->_set_get_scalar( 'mode', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mode: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | sub open | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
open: not called CC=35 SCAR=70.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | my $opts = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | if( ref( $_[0] ) eq 'HASH' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | $opts = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | @$opts{ qw( key mode size ) } = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | ▶ | $opts->{size} = $self->size unless( length( $opts->{size} ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | $opts->{size} = int( $opts->{size} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | ▶ | $opts->{mode} //= ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$opts->{"mode"} //= ""
MC/DC0%0/1
$opts->{"mode"} //= ""
$opts->{"mode"}
Truth table0%0/2
A
A= $opts->{"mode"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | ▶ | $opts->{key} = $opts->{key}->[0] if( ref( $opts->{key} // '' ) eq 'ARRAY' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$opts->{"key"} // ""
MC/DC0%0/1
$opts->{"key"} // ""
$opts->{"key"}
Truth table0%0/2
A
A= $opts->{"key"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | ▶ | $opts->{key} //= ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$opts->{"key"} //= ""
MC/DC0%0/1
$opts->{"key"} //= ""
$opts->{"key"}
Truth table0%0/2
A
A= $opts->{"key"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 2 | ▶ | no strict 'subs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | my $serial; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | ▶ | if( length( $opts->{key} ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | $serial = $self->_str2key( $opts->{key} ) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->_str2key($opts->{'key'}) || (return $self->error("Cannot get serial from key '$opts->{'key'}': ", $self->error))
MC/DC0%0/1
$self->_str2key($opts->{'key'}) || (return $self->error("Cannot get serial from key '$opts->{'key'}': ", $self->error))
$self->_str2key($opts->{'key'})
Truth table0%0/2
A
A= $self->_str2key($opts->{'key'})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | return( $self->error( "Cannot get serial from key '$opts->{key}': ", $self->error ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | $serial = $self->serial; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | ▶ | die( "There is no serial!!\n" ) if( !CORE::length( $serial ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | my $create = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | ▶ | if( $opts->{mode} eq 'w' || $opts->{key} =~ s/^>// ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$opts->{"mode"} eq "w" or $opts->{"key"} =~ s/^>//
MC/DC0%0/2
$opts->{"mode"} eq "w" or $opts->{"key"} =~ s/^>//
$opts->{"mode"} eq "w"
$opts->{"key"} =~ s/^>//
Truth table0%0/3
A or B
A= $opts->{"mode"} eq "w"B= $opts->{"key"} =~ s/^>//
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | $create++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | ▶ | elsif( $opts->{mode} eq 'r' || $opts->{key} =~ s/^<// ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$opts->{"mode"} eq "r" or $opts->{"key"} =~ s/^<//
MC/DC0%0/2
$opts->{"mode"} eq "r" or $opts->{"key"} =~ s/^<//
$opts->{"mode"} eq "r"
$opts->{"key"} =~ s/^<//
Truth table0%0/3
A or B
A= $opts->{"mode"} eq "r"B= $opts->{"key"} =~ s/^<//
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | $create = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | $create = $self->create; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | ▶ | my $flags = $self->flags( create => $create, ( $opts->{mode} =~ /^\d+$/ ? $opts->{mode} : () ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | ▶ | my $cache_dir = $self->{_cache_dir} || return( $self->error( "Cache directory object is gone!" ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'_cache_dir'} || (return $self->error('Cache directory object is gone!'))
MC/DC0%0/1
$self->{'_cache_dir'} || (return $self->error('Cache directory object is gone!'))
$self->{'_cache_dir'}
Truth table0%0/2
A
A= $self->{'_cache_dir'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | ▶ | return( $self->error( "Cache directory is not a Module::Generic::File object!" ) ) if( !$self->_is_a( $cache_dir => 'Module::Generic::File' ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | ▶ | if( $cache_dir->exists ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | ▶ | return( $self->error( "Cache directory exists, but is not a directory!" ) ) if( !$cache_dir->is_dir ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | $cache_dir->makepath || return( $self->pass_error( $cache_dir->error ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | my $fo = $cache_dir->child( $serial ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | my $cache_file = "$fo"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | my $io; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | if( $fo->exists ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | # Need to find a way to make that more efficient | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | ▶ | if( ( $flags & 0600 ) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$flags & 384 or $flags & 48 or $flags & 6
$flags & 384 or $flags & 48
MC/DC0%0/3
$flags & 384 or $flags & 48 or $flags & 6
$flags & 384
$flags & 48
$flags & 6
Truth table0%0/4
A or B or C
A= $flags & 384B= $flags & 48C= $flags & 6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | ( $flags & 0060 ) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | ( $flags & 0006 ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | ▶ | return( $self->error( "Requested mode ($flags) requires writing, but uid $> is missing write privilege to the cache file \"$cache_file\"." ) ) if( !$fo->can_write ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | ▶ | $io = $fo->open( '<', { binmode => 'raw', autoflush => 1 } ) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$fo->open('<', {'binmode', 'raw', 'autoflush', 1}) || (return $self->pass_error($fo->error))
MC/DC0%0/1
$fo->open('<', {'binmode', 'raw', 'autoflush', 1}) || (return $self->pass_error($fo->error))
$fo->open('<', {'binmode', 'raw', 'autoflush', 1})
Truth table0%0/2
A
A= $fo->open('<', {'binmode', 'raw', 'autoflush', 1})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | return( $self->pass_error( $fo->error ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | ▶ | return( $self->error( "Requested mode ($flags) require reading, but missing access privilege to the cache file \"$cache_file\"." ) ) if( !$fo->can_read ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | ▶ | $io = $fo->open( '<', { binmode => $opts->{binmode}, autoflush => 1 } ) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$fo->open('<', {'binmode', $opts->{'binmode'}, 'autoflush', 1}) || (return $self->pass_error($fo->error))
MC/DC0%0/1
$fo->open('<', {'binmode', $opts->{'binmode'}, 'autoflush', 1}) || (return $self->pass_error($fo->error))
$fo->open('<', {'binmode', $opts->{'binmode'}, 'autoflush', 1})
Truth table0%0/2
A
A= $fo->open('<', {'binmode', $opts->{'binmode'}, 'autoflush', 1})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | return( $self->pass_error( $fo->error ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | $io->close; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | if( ( $flags & 0600 ) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$flags & 384 or $flags & 48 or $flags & 6
$flags & 384 or $flags & 48
MC/DC0%0/3
$flags & 384 or $flags & 48 or $flags & 6
$flags & 384
$flags & 48
$flags & 6
Truth table0%0/4
A or B or C
A= $flags & 384B= $flags & 48C= $flags & 6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | ( $flags & 0060 ) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | ( $flags & 0006 ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | ▶ | $io = $fo->open( '+>', { binmode => 'raw', autoflush => 1 } ) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$fo->open('+>', {'binmode', 'raw', 'autoflush', 1}) || (return $self->pass_error($fo->error))
MC/DC0%0/1
$fo->open('+>', {'binmode', 'raw', 'autoflush', 1}) || (return $self->pass_error($fo->error))
$fo->open('+>', {'binmode', 'raw', 'autoflush', 1})
Truth table0%0/2
A
A= $fo->open('+>', {'binmode', 'raw', 'autoflush', 1})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | return( $self->pass_error( $fo->error ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | $fo->close; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | return( $self->error( "Requested mode ($flags) require reading, but the cache file \"$cache_file\" does not exist yet." ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | $self->serial( $serial ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | my $new = $self->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | key => ( $opts->{key} || $self->key ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | debug => $self->debug, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | mode => $flags, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | destroy => $self->destroy, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | cache_file => $fo, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | _packing_method => $self->_packing_method, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | ▶ | ) || return( $self->error( "Cannot create object with key '", ( $opts->{key} || $self->key ), "': ", $self->error ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/8
$self->new('key', $opts->{'key'} || $self->key, 'debug', $self->debug, 'mode', $flags, 'destroy', $self->destroy, 'cache_file', $fo, '_packing_method', $self->_packing_method) || (return $self->error(q[Cannot create object with key '], $opts->{'key'} || $self->key, q[': ], $self->error))
$opts->{'key'} || $self->key
$opts->{'key'} || $self->key
MC/DC0%0/1
$self->new('key', $opts->{'key'} || $self->key, 'debug', $self->debug, 'mode', $flags, 'destroy', $self->destroy, 'cache_file', $fo, '_packing_method', $self->_packing_method) || (return $self->error(q[Cannot create object with key '], $opts->{'key'} || $self->key, q[': ], $self->error))
$self->new('key', $opts->{'key'} || $self->key, 'debug', $self->debug, 'mode', $flags, 'destroy', $self->destroy, 'cache_file', $fo, '_packing_method', $self->_packing_method)
MC/DC0%0/2
$opts->{'key'} || $self->key
$opts->{'key'}
$self->key
MC/DC0%0/2
$opts->{'key'} || $self->key
$opts->{'key'}
$self->key
Truth table0%0/2
A
A= $self->new('key', $opts->{'key'} || $self->key, 'debug', $self->debug, 'mode', $flags, 'destroy', $self->destroy, 'cache_file', $fo, '_packing_method', $self->_packing_method)
Truth table0%0/3
A || B
A= $opts->{'key'}B= $self->key
Truth table0%0/3
A || B
A= $opts->{'key'}B= $self->key
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | $new->{base64} = $self->base64; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | $new->key( $self->key ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | $new->serial( $serial ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | $new->id( Scalar::Util::refaddr( $new ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | $new->size( $opts->{size} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | return( $new ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | ▶ | sub owner { return( shift->_set_get_scalar( 'owner', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
owner: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | sub rand | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rand: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | return( Data::UUID->new->create_str ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | # $self->read( $buffer, $size ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | # $self->read( $buffer ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | # my $data = $self->read; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | sub read | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read: not called CC=22 SCAR=62.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | my( $self, $buf ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | ▶ | my $key = $self->key || return( $self->error( "No key set." ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->key || (return $self->error('No key set.'))
MC/DC0%0/1
$self->key || (return $self->error('No key set.'))
$self->key
Truth table0%0/2
A
A= $self->key
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | ▶ | my $cache = $self->_cache || return( $self->error( "No Cache::FastMmap object. It seems it is gone!" ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->_cache || (return $self->error('No Cache::FastMmap object. It seems it is gone!'))
MC/DC0%0/1
$self->_cache || (return $self->error('No Cache::FastMmap object. It seems it is gone!'))
$self->_cache
Truth table0%0/2
A
A= $self->_cache
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | my $buffer; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | # try-catch | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | eval | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | $buffer = $cache->get( $key ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | ▶ | if( $@ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | return( $self->error( "Error retrieving data in MMap file for key '$key': $@" ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | ▶ | my $bytes = CORE::length( $buffer // '' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$buffer // ""
MC/DC0%0/1
$buffer // ""
$buffer
Truth table0%0/2
A
A= $buffer
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | my $packing = $self->_packing_method; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | ▶ | $packing = lc( $packing ) if( defined( $packing ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | my $data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | ▶ | if( CORE::defined( $buffer ) && CORE::length( $buffer ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $buffer and length $buffer
MC/DC0%0/2
defined $buffer and length $buffer
defined $buffer
length $buffer
Truth table0%0/3
A and B
A= defined $bufferB= length $buffer
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | # There may be encapsulation of data before writing data to memory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | # e.g.: MG[14]something here | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | ▶ | if( index( $buffer, 'MG[' ) == 0 ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | my $def = substr( $buffer, 0, index( $buffer, ']' ) + 1, '' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | # Get the string length stored | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | my $len = int( substr( $def, 3, -1 ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | # Remove any possible remaining unwanted data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | substr( $buffer, $len, length( $buffer ), '' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | # try-catch | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | eval | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | ▶ | if( $packing eq 'json' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | $data = $self->_decode_json( $buffer ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | elsif( $packing eq 'cbor' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | $data = $self->deserialise( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | data => $buffer, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | serialiser => 'CBOR::XS', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | allow_sharing => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | ▶ | ( defined( $self->{base64} ) ? ( base64 => $self->{base64} ) : () ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | elsif( $packing eq 'sereal' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | $data = $self->deserialise( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | data => $buffer, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | serialiser => 'Sereal', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | freeze_callbacks => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | ▶ | ( defined( $self->{base64} ) ? ( base64 => $self->{base64} ) : () ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | # By default Storable::Improved | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | # $data = Storable::Improved::thaw( $buffer ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | $data = $self->deserialise( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | data => $buffer, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | serialiser => 'Storable::Improved', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | ▶ | ( defined( $self->{base64} ) ? ( base64 => $self->{base64} ) : () ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | ▶ | if( $@ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | ▶ | return( $self->error( "An error occured while decoding data using $packing with base64 set to '", ( $self->{base64} // '' ), "': $@" ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"base64"} // ""
MC/DC0%0/1
$self->{"base64"} // ""
$self->{"base64"}
Truth table0%0/2
A
A= $self->{"base64"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | $data = $buffer; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | # data decoded is not a reference and size was provided and is greater than 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | ▶ | if( !ref( $data ) && scalar( @_ ) > 2 && int( $_[2] ) > 0 ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
not ref $data and scalar @_ > 2 and int $_[2] > 0
not ref $data and scalar @_ > 2
MC/DC0%0/3
not ref $data and scalar @_ > 2 and int $_[2] > 0
not ref $data
scalar @_ > 2
int $_[2] > 0
Truth table0%0/4
not(A) and B and C
A= not ref $dataB= scalar @_ > 2C= int $_[2] > 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | $data = substr( $data, 0, $_[2] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | ▶ | if( scalar( @_ ) > 1 ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | $_[1] = $data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | ▶ | return( CORE::length( $_[1] ) || "0E0" ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
length $_[1] || '0E0'
MC/DC0%0/1
length $_[1] || '0E0'
length $_[1]
Truth table0%0/2
A
A= length $_[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | return( $data ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | sub remove | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
remove: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | ▶ | my $cache = $self->_cache || return( $self->error( "No Cache::FastMmap object. It seems it is gone!" ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->_cache || (return $self->error('No Cache::FastMmap object. It seems it is gone!'))
MC/DC0%0/1
$self->_cache || (return $self->error('No Cache::FastMmap object. It seems it is gone!'))
$self->_cache
Truth table0%0/2
A
A= $self->_cache
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | $cache->cleanup( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | undef( $cache ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | $self->_cache( undef ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | ▶ | if( my $f = $self->cache_file ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | ▶ | $f->unlink if( $f->exists ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | $self->removed(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | ▶ | sub removed { return( shift->_set_get_boolean( 'removed', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
removed: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | sub reset | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reset: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | my $default; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | ▶ | if( @_ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | $default = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | $default = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | ▶ | if( my $cache = $self->_cache ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | # my $key = $self->key || return( $self->error( "Could not find the mmap key!" ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | # $cache->set( $key => $default ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | $self->write( $default ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 0 | return( $self ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | ▶ | sub sereal { return( shift->_packing_method( 'sereal' ) ); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sereal: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 0 | ▶ | sub serial { return( shift->_set_get_scalar( 'serial', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
serial: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | ▶ | sub serialiser { return( shift->_set_get_scalar( '_packing_method', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
serialiser: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 2 | ▶ | no warnings 'once'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 2 | *serializer = \&serialiser; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | ▶ | sub size { return( shift->_set_get_scalar( 'size', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
size: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | sub stat | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stat: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | ▶ | my $file = $self->cache_file || return(0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->cache_file || (return 0)
MC/DC0%0/1
$self->cache_file || (return 0)
$self->cache_file
Truth table0%0/2
A
A= $self->cache_file
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | ▶ | return( $self->error( "Mmap cache file found in our object is not a Module::Generic::File object." ) ) if( !$self->_is_a( $file => 'Module::Generic::File' ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | return( $file->stat ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 0 | ▶ | sub storable { return( shift->_packing_method( 'storable' ) ); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
storable: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | # NOTE: unlock is a noop | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | ▶ | sub unlock { return(1); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unlock: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | sub write | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write: not called CC=22 SCAR=62.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | my $data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | ▶ | if( scalar( @_ ) == 1 && ref( $_[0] ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
scalar @_ == 1 and ref $_[0]
MC/DC0%0/2
scalar @_ == 1 and ref $_[0]
scalar @_ == 1
ref $_[0]
Truth table0%0/3
A and B
A= scalar @_ == 1B= ref $_[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 0 | $data = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | $data = \join( '', @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 0 | ▶ | my $key = $self->key || return( $self->error( "No key set." ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->key || (return $self->error('No key set.'))
MC/DC0%0/1
$self->key || (return $self->error('No key set.'))
$self->key
Truth table0%0/2
A
A= $self->key
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 0 | ▶ | my $cache = $self->_cache || return( $self->error( "No Cache::FastMmap object. It seems it is gone!" ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->_cache || (return $self->error('No Cache::FastMmap object. It seems it is gone!'))
MC/DC0%0/1
$self->_cache || (return $self->error('No Cache::FastMmap object. It seems it is gone!'))
$self->_cache
Truth table0%0/2
A
A= $self->_cache
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | my $packing = $self->_packing_method; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 0 | my $encoded; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 0 | ▶ | if( $packing eq 'json' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | # try-catch | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | eval | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 0 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | $encoded = $self->_encode_json( $data ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 0 | ▶ | if( $@ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 0 | return( $self->error( "An error occured encoding data provided using $packing: $@. Data was: '$data'" ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | elsif( $packing eq 'cbor' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | # try-catch | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | eval | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 0 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | $encoded = $self->serialise( $data, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | serialiser => 'CBOR::XS', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | allow_sharing => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 0 | ▶ | ( defined( $self->{base64} ) ? ( base64 => $self->{base64} ) : () ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 0 | ▶ | if( $@ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 0 | return( $self->error( "An error occured encoding data provided using $packing: $@. Data was: '$data'" ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 0 | ▶ | return( $self->pass_error ) if( !defined( $encoded ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | elsif( $packing eq 'sereal' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 0 | ▶ | $self->_load_class( 'Sereal::Encoder' ) || return( $self->pass_error ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 0 | my $const; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 0 | ▶ | $const = \&{"Sereal\::Encoder::SRL_ZLIB"} if( defined( &{"Sereal\::Encoder::SRL_ZLIB"} ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | # try-catch | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | eval | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 0 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | $encoded = $self->serialise( $data, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | serialiser => 'Sereal', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | freeze_callbacks => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | ( defined( $const ) ? ( compress => $const->() ) : () ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 0 | ▶ | ( defined( $self->{base64} ) ? ( base64 => $self->{base64} ) : () ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 0 | ▶ | if( $@ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 0 | return( $self->error( "An error occured encoding data provided using $packing: $@. Data was: '$data'" ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 0 | ▶ | return( $self->pass_error ) if( !defined( $encoded ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | # Default to Storable::Improved | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | # try-catch | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | # local $Storable::forgive_me = 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | # $encoded = Storable::Improved::freeze( $data ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | eval | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 0 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | $encoded = $self->serialise( $data, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | serialiser => 'Storable::Improved', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 0 | ▶ | ( defined( $self->{base64} ) ? ( base64 => $self->{base64} ) : () ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 0 | ▶ | if( $@ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 0 | return( $self->error( "An error occured encoding data provided using $packing: $@. Data was: '$data'" ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 0 | ▶ | return( $self->pass_error ) if( !defined( $encoded ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | # Simple encapsulation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | # FYI: MG = Module::Generic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 0 | substr( $encoded, 0, 0, 'MG[' . length( $encoded ) . ']' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | # try-catch | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | eval | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 0 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 0 | $cache->set( $key => $encoded ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 0 | ▶ | if( $@ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 0 | return( $self->error( "Error writing data to MMap file for key '$key': $@" ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 0 | return( $self ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 0 | ▶ | sub _cache { return( shift->_set_get_object_without_init( '_cache', 'Cache::FastMmap', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_cache: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | sub _decode_json | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_decode_json: not called CC=4 SCAR=28.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | 0 | my $data = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | # Nothing to do | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 0 | ▶ | return( $data ) if( !defined( $data ) || !CORE::length( $data ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $data and length $data
MC/DC0%0/2
defined $data and length $data
defined $data
length $data
Truth table0%0/3
A and B
A= defined $dataB= length $data
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | 2 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 0 | my $j = JSON->new->utf8->relaxed->allow_nonref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 0 | my $seen = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 0 | my $crawl; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | $crawl = sub | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=11 SCAR=48.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 0 | my $this = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 0 | my $type = Scalar::Util::reftype( $this ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 0 | ▶ | return( $this ) if( ( $type eq 'HASH' || $type eq 'ARRAY' ) && ++$seen->{ Scalar::Util::refaddr( $this ) } > 1 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$type eq "HASH" || $type eq "ARRAY" and ++$$seen{builtin::refaddr($this)} > 1
$type eq "HASH" or $type eq "ARRAY"
MC/DC0%0/3
$type eq "HASH" || $type eq "ARRAY" and ++$$seen{builtin::refaddr($this)} > 1
$type eq "HASH"
$type eq "ARRAY"
++$$seen{builtin::refaddr($this)} > 1
Truth table0%0/5
A or B and C
A= $type eq "HASH"B= $type eq "ARRAY"C= ++$$seen{builtin::refaddr($this)} > 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 0 | ▶ | if( $type eq 'HASH' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | # Found a former scalar reference, restore it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | 0 | ▶ | if( CORE::exists( $this->{__scalar_gen_shm} ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 0 | return( \$this->{__scalar_gen_shm} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 0 | foreach my $k ( keys( %$this ) ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 0 | ▶ | next if( !ref( $this->{ $k } ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | 0 | $this->{ $k } = $crawl->( $this->{ $k } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | elsif( $type eq 'ARRAY' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 0 | ▶ | for( my $i = 0; $i < scalar( @$this ); $i++ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 0 | ▶ | next if( !ref( $this->[$i] ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | 0 | $this->[$i] = $crawl->( $this->[$i] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 0 | return( $this ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 0 | my $decoded; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | # try-catch | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | eval | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | 0 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | 0 | $decoded = $j->decode( $data ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 0 | ▶ | if( $@ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 0 | return( $self->error( "An error occurred while trying to decode JSON data: $@" ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 0 | my $result = $crawl->( $decoded ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 0 | return( $result ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | # Purpose of this method is to recursively check the given data and change scalar reference if they are anything else than 1 or 0, otherwise JSON would complain | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | sub _encode_json | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_encode_json: not called CC=2 SCAR=17.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 0 | my $data = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | 0 | my $seen = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | 0 | my $crawl; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | 2 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | $crawl = sub | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=15 SCAR=54.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | 0 | my $this = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | 0 | my $type = Scalar::Util::reftype( $this ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | # Skip this reference if it is either hash or array and we have already seen it in order to avoid looping. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 0 | ▶ | return( $this ) if( ( $type eq 'HASH' || $type eq 'ARRAY' ) && ++$seen->{ Scalar::Util::refaddr( $this ) } > 1 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$type eq "HASH" || $type eq "ARRAY" and ++$$seen{builtin::refaddr($this)} > 1
$type eq "HASH" or $type eq "ARRAY"
MC/DC0%0/3
$type eq "HASH" || $type eq "ARRAY" and ++$$seen{builtin::refaddr($this)} > 1
$type eq "HASH"
$type eq "ARRAY"
++$$seen{builtin::refaddr($this)} > 1
Truth table0%0/5
A or B and C
A= $type eq "HASH"B= $type eq "ARRAY"C= ++$$seen{builtin::refaddr($this)} > 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 0 | ▶ | if( $type eq 'HASH' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 0 | foreach my $k ( keys( %$this ) ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | 0 | ▶ | next if( !ref( $this->{ $k } ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 0 | $this->{ $k } = $crawl->( $this->{ $k } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | elsif( $type eq 'ARRAY' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | 0 | ▶ | for( my $i = 0; $i < scalar( @$this ); $i++ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 0 | ▶ | next if( !ref( $this->[$i] ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | 0 | $this->[$i] = $crawl->( $this->[$i] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | elsif( $type eq 'SCALAR' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | # The only supported value by JSON for a scalar reference | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | 0 | ▶ | return( $this ) if( $$this eq "1" or $$this eq "0" ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$$this eq 1 or $$this eq 0
MC/DC0%0/2
$$this eq 1 or $$this eq 0
$$this eq 1
$$this eq 0
Truth table0%0/3
A or B
A= $$this eq 1B= $$this eq 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 0 | my $pkg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | 0 | ▶ | if( ( $pkg = Scalar::Util::blessed( $this ) ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | 0 | ▶ | if( overload::Method( $this => '""' ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | 0 | $this = { __scalar_gen_shm => "$this", __package => $pkg }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 0 | $this = { __scalar_gen_shm => $$this, __package => $pkg }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | 0 | $this = { __scalar_gen_shm => $$this }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | 0 | return( $this ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | 0 | my $ref = $crawl->( $data ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | 0 | my $j = JSON->new->utf8->relaxed->allow_nonref->convert_blessed; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | 0 | my $encoded; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | # try-catch | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | eval | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | 0 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | 0 | $encoded = $j->encode( $ref ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | 0 | ▶ | if( $@ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | 0 | return( $self->error( "An error occurred while trying to JSON encode data: $@" ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | 0 | return( $encoded ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | 0 | ▶ | sub _packing_method { return( shift->_set_get_scalar( '_packing_method', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_packing_method: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | sub _str2key | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_str2key: not called CC=8 SCAR=40.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | 0 | my $key = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | 2 | ▶ | no strict 'subs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | 0 | ▶ | if( !defined( $key ) || $key eq '' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $key or $key eq ""
MC/DC0%0/2
not defined $key or $key eq ""
not defined $key
$key eq ""
Truth table0%0/3
not(A) or B
A= not defined $keyB= $key eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | 0 | return( Data::UUID->new->create_str ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | # We do not actually use any path, but this is for standardisation with Module::Generic::SharedMem | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | 0 | my $path; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | 0 | ▶ | ( $key, $path ) = ref( $key ) eq 'ARRAY' ? @$key : ( $key, [getpwuid($>)]->[7] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | 0 | ▶ | $path = [getpwuid($path)]->[7] if( $path =~ /^\d+$/ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | 0 | ▶ | if( $key =~ /^\d+$/ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | 0 | ▶ | my $id = $self->ftok( $key ) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->ftok($key) || (return $self->error("Unable to get a key using ftok: $!"))
MC/DC0%0/1
$self->ftok($key) || (return $self->error("Unable to get a key using ftok: $!"))
$self->ftok($key)
Truth table0%0/2
A
A= $self->ftok($key)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | return( $self->error( "Unable to get a key using ftok: $!" ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | 0 | return( $id ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | 0 | my $id = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | 0 | $id += $_ for( unpack( "C*", $key ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | 0 | my $val = $self->ftok( $id ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | 0 | return( $val ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | sub FREEZE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
FREEZE: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | 0 | my $self = CORE::shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | 0 | ▶ | my $serialiser = CORE::shift( @_ ) // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift @_ // ""
MC/DC0%0/1
shift @_ // ""
shift @_
Truth table0%0/2
A
A= shift @_
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | 0 | my $class = CORE::ref( $self ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | 0 | my @props = qw( base64 create destroy key mode serial size _packing_method ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | 0 | my $hash = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | 0 | foreach my $prop ( @props ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | 0 | ▶ | if( exists( $self->{ $prop } ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | 0 | $hash->{ $prop } = $self->{ $prop }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | 0 | ▶ | if( my $cache = $self->{_cache} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | 0 | my $file = $self->cache_file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | 0 | my $cache_data = $cache->get( $self->key ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | 0 | $hash->{__cache_file} = "$file"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | 0 | $hash->{__cache_data} = $cache_data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | # Return an array reference rather than a list so this works with Sereal and CBOR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | # On or before Sereal version 4.023, Sereal did not support multiple values returned | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | 0 | ▶ | if( $serialiser eq 'Sereal' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | 0 | require Sereal::Encoder; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | 0 | require version; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | 0 | ▶ | if( version->parse( Sereal::Encoder->VERSION ) <= version->parse( '4.023' ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | 0 | CORE::return( [$class, $hash] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | # But Storable want a list with the first element being the serialised element | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | 0 | CORE::return( $class, $hash ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | 0 | ▶ | sub STORABLE_freeze { return( shift->FREEZE( @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
STORABLE_freeze: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | 0 | ▶ | sub STORABLE_thaw { return( shift->THAW( @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
STORABLE_thaw: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | # NOTE: CBOR will call the THAW method with the stored classname as first argument, the constant string CBOR as second argument, and all values returned by FREEZE as remaining arguments. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | # NOTE: Storable calls it with a blessed object it created followed with $cloning and any other arguments initially provided by STORABLE_freeze | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | sub THAW | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
THAW: not called CC=22 SCAR=62.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | 0 | my( $self, undef, @args ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | 0 | ▶ | my $ref = ( CORE::scalar( @args ) == 1 && CORE::ref( $args[0] ) eq 'ARRAY' ) ? CORE::shift( @args ) : \@args; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
scalar @args == 1 and ref $args[0] eq "ARRAY"
MC/DC0%0/2
scalar @args == 1 and ref $args[0] eq "ARRAY"
scalar @args == 1
ref $args[0] eq "ARRAY"
Truth table0%0/3
A and B
A= scalar @args == 1B= ref $args[0] eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | 0 | ▶ | my $class = ( CORE::defined( $ref ) && CORE::ref( $ref ) eq 'ARRAY' && CORE::scalar( @$ref ) > 1 ) ? CORE::shift( @$ref ) : ( CORE::ref( $self ) || $self ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
defined $ref and ref $ref eq "ARRAY" and scalar @$ref > 1
defined $ref and ref $ref eq "ARRAY"
ref $self or $self
MC/DC0%0/3
defined $ref and ref $ref eq "ARRAY" and scalar @$ref > 1
defined $ref
ref $ref eq "ARRAY"
scalar @$ref > 1
MC/DC0%0/2
ref $self or $self
ref $self
$self
Truth table0%0/4
A and B and C
A= defined $refB= ref $ref eq "ARRAY"C= scalar @$ref > 1
Truth table0%0/3
A or B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | 0 | ▶ | my $hash = CORE::ref( $ref ) eq 'ARRAY' ? CORE::shift( @$ref ) : {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | 0 | my $new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | 0 | my( $cache_data, $cache_file ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | 0 | ▶ | if( CORE::exists( $hash->{__cache_data} ) && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $hash->{"__cache_data"} and exists $hash->{"__cache_file"}
MC/DC0%0/2
exists $hash->{"__cache_data"} and exists $hash->{"__cache_file"}
exists $hash->{"__cache_data"}
exists $hash->{"__cache_file"}
Truth table0%0/3
A and B
A= exists $hash->{"__cache_data"}B= exists $hash->{"__cache_file"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | CORE::exists( $hash->{__cache_file} ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | 0 | ( $cache_data, $cache_file ) = CORE::delete( @$hash{qw( __cache_data __cache_file )} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | # Storable pattern requires to modify the object it created rather than returning a new one | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | 0 | ▶ | if( CORE::ref( $self ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | 0 | foreach( CORE::keys( %$hash ) ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | 0 | $self->{ $_ } = CORE::delete( $hash->{ $_ } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | 0 | $new = $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | 0 | $new = CORE::bless( $hash => $class ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | 0 | ▶ | if( CORE::defined( $cache_data ) && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $cache_data and defined $cache_file
MC/DC0%0/2
defined $cache_data and defined $cache_file
defined $cache_data
defined $cache_file
Truth table0%0/3
A and B
A= defined $cache_dataB= defined $cache_file
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | CORE::defined( $cache_file ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | my $f = Module::Generic::File->new( $cache_file ) || do | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
'Module::Generic::File'->new($cache_file) || do {
warn qq[Unable to get a file object for "$cache_file": ], 'Module::Generic::File'->error, "\n" if $self->_warnings_is_enabled('Module::Generic');
return $new
}
MC/DC0%0/2
'Module::Generic::File'->new($cache_file) || do {
warn qq[Unable to get a file object for "$cache_file": ], 'Module::Generic::File'->error, "\n" if $self->_warnings_is_enabled('Module::Generic');
return $new
}
'Module::Generic::File'->new($cache_file)
do {
warn qq[Unable to get a file object for "$cache_file": ], 'Module::Generic::File'->error, "\n" if $self->_warnings_is_enabled('Module::Generic');
return $new
}
Truth table0%0/3
A || B
A= 'Module::Generic::File'->new($cache_file)B= do {
warn qq[Unable to get a file object for "$cache_file": ], 'Module::Generic::File'->error, "\n" if $self->_warnings_is_enabled('Module::Generic');
return $new
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | 0 | ▶ | warn( "Unable to get a file object for \"$cache_file\": ", Module::Generic::File->error, "\n" ) if( $self->_warnings_is_enabled( 'Module::Generic' ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | 0 | return( $new ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | 0 | $new->{cache_file} = $f; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | $new->{_cache} = Cache::FastMmap->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | ( ( defined( $new->{destroy} ) && length( $new->{destroy} ) ) ? ( unlink_on_exit => $new->{destroy} ) : () ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | share_file => "$f", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | ( $new->{size} ? ( cache_size => $new->{size} ) : () ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | ( $new->{mode} ? ( permissions => $new->{mode} ) : () ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | serializer => '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | ) || do | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition0%0/6
'Cache::FastMmap'->new(defined $new->{'destroy'} && length $new->{'destroy'} ? ('unlink_on_exit', $new->{'destroy'}) : (), 'share_file', "$f", $new->{'size'} ? ('cache_size', $new->{'size'}) : (), $new->{'mode'} ? ('permissions', $new->{'mode'}) : (), 'serializer', '') || do {
warn "Unable to instantiate a Cache::FastMmap object.\n" if $self->_warnings_is_enabled('Module::Generic');
return $new
}
defined $new->{"destroy"} and length $new->{"destroy"}
MC/DC0%0/2
'Cache::FastMmap'->new(defined $new->{'destroy'} && length $new->{'destroy'} ? ('unlink_on_exit', $new->{'destroy'}) : (), 'share_file', "$f", $new->{'size'} ? ('cache_size', $new->{'size'}) : (), $new->{'mode'} ? ('permissions', $new->{'mode'}) : (), 'serializer', '') || do {
warn "Unable to instantiate a Cache::FastMmap object.\n" if $self->_warnings_is_enabled('Module::Generic');
return $new
}
'Cache::FastMmap'->new(defined $new->{'destroy'} && length $new->{'destroy'} ? ('unlink_on_exit', $new->{'destroy'}) : (), 'share_file', "$f", $new->{'size'} ? ('cache_size', $new->{'size'}) : (), $new->{'mode'} ? ('permissions', $new->{'mode'}) : (), 'serializer', '')
do {
warn "Unable to instantiate a Cache::FastMmap object.\n" if $self->_warnings_is_enabled('Module::Generic');
return $new
}
MC/DC0%0/2
defined $new->{"destroy"} and length $new->{"destroy"}
defined $new->{"destroy"}
length $new->{"destroy"}
Truth table0%0/3
A || B
A= 'Cache::FastMmap'->new(defined $new->{'destroy'} && length $new->{'destroy'} ? ('unlink_on_exit', $new->{'destroy'}) : (), 'share_file', "$f", $new->{'size'} ? ('cache_size', $new->{'size'}) : (), $new->{'mode'} ? ('permissions', $new->{'mode'}) : (), 'serializer', '')B= do {
warn "Unable to instantiate a Cache::FastMmap object.\n" if $self->_warnings_is_enabled('Module::Generic');
return $new
}
Truth table0%0/3
A and B
A= defined $new->{"destroy"}B= length $new->{"destroy"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | 0 | ▶ | warn( "Unable to instantiate a Cache::FastMmap object.\n" ) if( $self->_warnings_is_enabled( 'Module::Generic' ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | 0 | return( $new ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | 0 | $new->{_cache}->set( $new->key => $cache_data ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | 0 | $new->{owner} = $$; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | 0 | CORE::return( $new ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | # NOTE: POD | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||