| 1 | ##---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 2 | ## Apache2 Server Side Include Parser - ~/lib/Apache2/SSI/SharedMem.pm | ||||||||||||||||||||||||||||||||||||||||||
| 3 | ## Version v0.1.2 | ||||||||||||||||||||||||||||||||||||||||||
| 4 | ## Copyright(c) 2022 DEGUEST Pte. Ltd. | ||||||||||||||||||||||||||||||||||||||||||
| 5 | ## Author: Jacques Deguest <jack@deguest.jp> | ||||||||||||||||||||||||||||||||||||||||||
| 6 | ## Created 2021/01/18 | ||||||||||||||||||||||||||||||||||||||||||
| 7 | ## Modified 2024/09/04 | ||||||||||||||||||||||||||||||||||||||||||
| 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 Apache2::SSI::SharedMem; | ||||||||||||||||||||||||||||||||||||||||||
| 14 | BEGIN | ||||||||||||||||||||||||||||||||||||||||||
| 15 | 9 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 9 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 9 | ▶ | use warnings::register; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 9 | ▶ | use parent qw( Module::Generic ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 9 | ▶ | use vars qw( $VERSION $SUPPORTED_RE $SYSV_SUPPORTED $SEMOP_ARGS @EXPORT_OK %EXPORT_TAGS $N $SHEM_REPO ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 9 | ▶ | use Config; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 9 | ▶ | use JSON (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 9 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 9 | ▶ | use constant SHM_BUFSIZ => 65536; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 9 | ▶ | use constant SEM_LOCKER => 0; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 9 | ▶ | use constant SEM_MARKER => 1; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 9 | ▶ | use constant SHM_LOCK_WAIT => 0; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 9 | ▶ | use constant SHM_LOCK_EX => 1; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 9 | ▶ | use constant SHM_LOCK_UN => -1; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 9 | ▶ | use constant SHM_EXISTS => 1; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 9 | ▶ | use constant LOCK_SH => 1; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 9 | ▶ | use constant LOCK_EX => 2; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 9 | ▶ | use constant LOCK_NB => 4; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 9 | ▶ | use constant LOCK_UN => 8; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | # if( $^O =~ /^(?:Android|cygwin|dos|MSWin32|os2|VMS|riscos)/ ) | ||||||||||||||||||||||||||||||||||||||||||
| 36 | # Even better | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 9 | our $SUPPORTED_RE = qr/\bIPC\/SysV\b/m; | |||||||||||||||||||||||||||||||||||||||||
| 38 | 9 | ▶ | if( $Config{extensions} =~ m/$SUPPORTED_RE/ && | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$Apache2::SSI::SharedMem::Config{"extensions"} =~ /$Apache2::SSI::SharedMem::SUPPORTED_RE/m and not $Apache2::SSI::SharedMem::Config{"useithreads"} and not $^O =~ /^(?:Android|cygwin|dos|MSWin32|os2|VMS|riscos)/i
$Apache2::SSI::SharedMem::Config{"extensions"} =~ /$Apache2::SSI::SharedMem::SUPPORTED_RE/m and not $Apache2::SSI::SharedMem::Config{"useithreads"}
MC/DC0%0/3
$Apache2::SSI::SharedMem::Config{"extensions"} =~ /$Apache2::SSI::SharedMem::SUPPORTED_RE/m and not $Apache2::SSI::SharedMem::Config{"useithreads"} and not $^O =~ /^(?:Android|cygwin|dos|MSWin32|os2|VMS|riscos)/i
$Apache2::SSI::SharedMem::Config{"extensions"} =~ /$Apache2::SSI::SharedMem::SUPPORTED_RE/m
not $Apache2::SSI::SharedMem::Config{"useithreads"}
not $^O =~ /^(?:Android|cygwin|dos|MSWin32|os2|VMS|riscos)/i
Truth table25%1/4
A and not(B) and not(C)
A= $Apache2::SSI::SharedMem::Config{"extensions"} =~ /$Apache2::SSI::SharedMem::SUPPORTED_RE/mB= not $Apache2::SSI::SharedMem::Config{"useithreads"}C= not $^O =~ /^(?:Android|cygwin|dos|MSWin32|os2|VMS|riscos)/i
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | # No support for threads | ||||||||||||||||||||||||||||||||||||||||||
| 40 | !$Config{useithreads} && | ||||||||||||||||||||||||||||||||||||||||||
| 41 | $^O !~ /^(?:Android|cygwin|dos|MSWin32|os2|VMS|riscos)/i ) | ||||||||||||||||||||||||||||||||||||||||||
| 42 | { | ||||||||||||||||||||||||||||||||||||||||||
| 43 | 9 | require IPC::SysV; | |||||||||||||||||||||||||||||||||||||||||
| 44 | 9 | IPC::SysV->import( qw( IPC_RMID IPC_PRIVATE IPC_SET IPC_STAT IPC_CREAT IPC_EXCL IPC_NOWAIT | |||||||||||||||||||||||||||||||||||||||||
| 45 | SEM_UNDO S_IRWXU S_IRWXG S_IRWXO | ||||||||||||||||||||||||||||||||||||||||||
| 46 | GETNCNT GETZCNT GETVAL SETVAL GETPID GETALL SETALL | ||||||||||||||||||||||||||||||||||||||||||
| 47 | shmat shmdt memread memwrite ftok ) ); | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 9 | our $SYSV_SUPPORTED = 1; | |||||||||||||||||||||||||||||||||||||||||
| 49 | 9 | eval( <<'EOT' ); | |||||||||||||||||||||||||||||||||||||||||
| 50 | our $SEMOP_ARGS = | ||||||||||||||||||||||||||||||||||||||||||
| 51 | { | ||||||||||||||||||||||||||||||||||||||||||
| 52 | (LOCK_EX) => | ||||||||||||||||||||||||||||||||||||||||||
| 53 | [ | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 1, 0, 0, # wait for readers to finish | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 2, 0, 0, # wait for writers to finish | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 2, 1, SEM_UNDO, # assert write lock | ||||||||||||||||||||||||||||||||||||||||||
| 57 | ], | ||||||||||||||||||||||||||||||||||||||||||
| 58 | (LOCK_EX | LOCK_NB) => | ||||||||||||||||||||||||||||||||||||||||||
| 59 | [ | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 1, 0, IPC_NOWAIT, # wait for readers to finish | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 2, 0, IPC_NOWAIT, # wait for writers to finish | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 2, 1, (SEM_UNDO | IPC_NOWAIT), # assert write lock | ||||||||||||||||||||||||||||||||||||||||||
| 63 | ], | ||||||||||||||||||||||||||||||||||||||||||
| 64 | (LOCK_EX | LOCK_UN) => | ||||||||||||||||||||||||||||||||||||||||||
| 65 | [ | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 2, -1, (SEM_UNDO | IPC_NOWAIT), | ||||||||||||||||||||||||||||||||||||||||||
| 67 | ], | ||||||||||||||||||||||||||||||||||||||||||
| 68 | (LOCK_SH) => | ||||||||||||||||||||||||||||||||||||||||||
| 69 | [ | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 2, 0, 0, # wait for writers to finish | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 1, 1, SEM_UNDO, # assert shared read lock | ||||||||||||||||||||||||||||||||||||||||||
| 72 | ], | ||||||||||||||||||||||||||||||||||||||||||
| 73 | (LOCK_SH | LOCK_NB) => | ||||||||||||||||||||||||||||||||||||||||||
| 74 | [ | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 2, 0, IPC_NOWAIT, # wait for writers to finish | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 1, 1, (SEM_UNDO | IPC_NOWAIT), # assert shared read lock | ||||||||||||||||||||||||||||||||||||||||||
| 77 | ], | ||||||||||||||||||||||||||||||||||||||||||
| 78 | (LOCK_SH | LOCK_UN) => | ||||||||||||||||||||||||||||||||||||||||||
| 79 | [ | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 1, -1, (SEM_UNDO | IPC_NOWAIT), # remove shared read lock | ||||||||||||||||||||||||||||||||||||||||||
| 81 | ], | ||||||||||||||||||||||||||||||||||||||||||
| 82 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 83 | EOT | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 9 | ▶ | if( $@ ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | { | ||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | warn( "Error while trying to evel \$SEMOP_ARGS: $@\n" ); | |||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | else | ||||||||||||||||||||||||||||||||||||||||||
| 90 | { | ||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | our $SYSV_SUPPORTED = 0; | |||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | 9 | our @EXPORT_OK = qw(LOCK_EX LOCK_SH LOCK_NB LOCK_UN); | |||||||||||||||||||||||||||||||||||||||||
| 94 | 9 | our %EXPORT_TAGS = ( | |||||||||||||||||||||||||||||||||||||||||
| 95 | all => [qw( LOCK_EX LOCK_SH LOCK_NB LOCK_UN )], | ||||||||||||||||||||||||||||||||||||||||||
| 96 | lock => [qw( LOCK_EX LOCK_SH LOCK_NB LOCK_UN )], | ||||||||||||||||||||||||||||||||||||||||||
| 97 | 'flock' => [qw( LOCK_EX LOCK_SH LOCK_NB LOCK_UN )], | ||||||||||||||||||||||||||||||||||||||||||
| 98 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 99 | # Credits IPC::Shareable | ||||||||||||||||||||||||||||||||||||||||||
| 100 | 9 | ▶ | our $N = do { my $foo = eval { pack "L!", 0 }; $@ ? '' : '!' }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 9 | our $SHEM_REPO = {}; | |||||||||||||||||||||||||||||||||||||||||
| 102 | 9 | our $VERSION = 'v0.1.2'; | |||||||||||||||||||||||||||||||||||||||||
| 103 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 9 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | sub init | ||||||||||||||||||||||||||||||||||||||||||
| 109 | 64 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 64 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 111 | # Default action when accessing a shared memory? If 1, it will create it if it does not exist already | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 64 | $self->{create} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 113 | 64 | $self->{destroy} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 114 | 64 | $self->{exclusive} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 115 | 64 | $self->{key} = &IPC::SysV::IPC_PRIVATE; | |||||||||||||||||||||||||||||||||||||||||
| 116 | 64 | $self->{mode} = 0666; | |||||||||||||||||||||||||||||||||||||||||
| 117 | 64 | $self->{serial} = ''; | |||||||||||||||||||||||||||||||||||||||||
| 118 | # SHM_BUFSIZ | ||||||||||||||||||||||||||||||||||||||||||
| 119 | 64 | $self->{size} = SHM_BUFSIZ; | |||||||||||||||||||||||||||||||||||||||||
| 120 | 64 | $self->{_init_strict_use_sub} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 121 | 64 | ▶ | $self->SUPER::init( @_ ) || return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | 64 | $self->{addr} = undef(); | |||||||||||||||||||||||||||||||||||||||||
| 123 | 64 | $self->{id} = undef(); | |||||||||||||||||||||||||||||||||||||||||
| 124 | 64 | $self->{locked} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 125 | 64 | $self->{owner} = $$; | |||||||||||||||||||||||||||||||||||||||||
| 126 | 64 | $self->{removed} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 127 | 64 | $self->{semid} = undef(); | |||||||||||||||||||||||||||||||||||||||||
| 128 | 64 | return( $self ); | |||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | sub addr { return( shift->_set_get_scalar( 'addr', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
addr: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | sub attach | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
attach: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | my $flags = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | $flags = $self->flags if( !defined( $flags ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | my $addr = $self->addr; | |||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | ▶ | return( $addr ) if( defined( $addr ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | my $id = $self->id; | |||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | return( $self->error( "No shared memory id! Have you opened it first?" ) ) if( !length( $id ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | $addr = shmat( $id, undef(), $flags ); | |||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | ▶ | return( $self->error( "Unable to attach to shared memory: $!" ) ) if( !defined( $addr ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | $self->addr( $addr ); | |||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | return( $addr ); | |||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | 96 | ▶ | sub create { return( shift->_set_get_boolean( 'create', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | 70 | ▶ | sub destroy { return( shift->_set_get_boolean( 'destroy', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
destroy: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | sub detach | ||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
detach: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | my $addr = $self->addr; | |||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | ▶ | return if( !defined( $addr ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | my $rv = shmdt( $addr ); | |||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | return( $self->error( "Unable to detach from shared memory: $!" ) ) if( !defined( $rv ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | $self->addr( undef() ); | |||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | return( $self ); | |||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | 64 | ▶ | sub exclusive { return( shift->_set_get_boolean( 'exclusive', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
exclusive: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | sub exists | ||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
exists: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | my $opts = {}; | |||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | ▶ | if( ref( $_[0] ) eq 'HASH' ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | { | ||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | $opts = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||
| 173 | else | ||||||||||||||||||||||||||||||||||||||||||
| 174 | { | ||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | @$opts{ qw( key mode size ) } = @_; | |||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | ▶ | $opts->{size} = $self->size unless( length( $opts->{size} ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | $opts->{size} = int( $opts->{size} ); | |||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | my $serial; | |||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | ▶ | if( length( $opts->{key} ) ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | { | ||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | $serial = $self->_str2key( $opts->{key} ); | |||||||||||||||||||||||||||||||||||||||||
| 183 | # $serial = $opts->{key}; | ||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||
| 185 | else | ||||||||||||||||||||||||||||||||||||||||||
| 186 | { | ||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | $serial = $self->serial; | |||||||||||||||||||||||||||||||||||||||||
| 188 | # $serial = $self->key; | ||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | my $flags = $self->flags({ mode => 0644 }); | |||||||||||||||||||||||||||||||||||||||||
| 191 | # Remove the create bit | ||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | $flags = ( $flags ^ &IPC::SysV::IPC_CREAT ); | |||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | my $semid; | |||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 195 | # try-catch | ||||||||||||||||||||||||||||||||||||||||||
| 196 | my $rv = eval | ||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | { | |||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | $semid = semget( $serial, 3, $flags ); | |||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | ▶ | if( defined( $semid ) ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | { | ||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | my $found = semctl( $semid, SEM_MARKER, &IPC::SysV::GETVAL, 0 ); | |||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | semctl( $semid, 0, &IPC::SysV::IPC_RMID, 0 ); | |||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | return( $found == SHM_EXISTS ? 1 : 0 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||
| 205 | else | ||||||||||||||||||||||||||||||||||||||||||
| 206 | { | ||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | ▶ | return(0) if( $! =~ /\bNo[[:blank:]]+such[[:blank:]]+file\b/ ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||
| 210 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | ▶ | if( $@ ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 212 | { | ||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | ▶ | semctl( $semid, 0, &IPC::SysV::IPC_RMID, 0 ) if( $semid ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | return(0); | |||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | return( $rv ); | |||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | sub flags | ||||||||||||||||||||||||||||||||||||||||||
| 220 | 64 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
flags: called CC=7 SCAR=19.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 221 | 64 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 222 | 64 | my $opts = $self->_get_args_as_hash( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 223 | 64 | ▶ | $opts->{create} = $self->create unless( length( $opts->{create} ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | 64 | ▶ | $opts->{exclusive} = $self->exclusive unless( length( $opts->{exclusive} ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 225 | 64 | ▶ | $opts->{mode} = $self->mode unless( length( $opts->{mode} ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 226 | 64 | my $flags = 0; | |||||||||||||||||||||||||||||||||||||||||
| 227 | 64 | ▶ | $flags |= &IPC::SysV::IPC_CREAT if( $opts->{create} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | 64 | ▶ | $flags |= &IPC::SysV::IPC_EXCL if( $opts->{exclusive} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 229 | 64 | ▶ | $flags |= ( $opts->{mode} || 0666 ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts->{'mode'} || 438
MC/DC0%0/1
$opts->{'mode'} || 438
$opts->{'mode'}
Truth table50%1/2
A
A= $opts->{'mode'}
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | 64 | return( $flags ); | |||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | # sub id { return( shift->_set_get_scalar( 'id', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||
| 234 | sub id | ||||||||||||||||||||||||||||||||||||||||||
| 235 | 32 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
id: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 236 | 32 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 237 | 32 | my @callinfo = caller; | |||||||||||||||||||||||||||||||||||||||||
| 238 | 9 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 239 | 32 | ▶ | if( @_ ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 240 | { | ||||||||||||||||||||||||||||||||||||||||||
| 241 | 32 | $self->{id} = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||
| 243 | 32 | return( $self->{id} ); | |||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | sub key | ||||||||||||||||||||||||||||||||||||||||||
| 247 | 96 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
key: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 248 | 96 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 249 | 96 | ▶ | if( @_ ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | { | ||||||||||||||||||||||||||||||||||||||||||
| 251 | 64 | $self->{key} = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 252 | 64 | $self->{serial} = $self->_str2key( $self->{key} ); | |||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||
| 254 | 96 | return( $self->{key} ); | |||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||
| 257 | sub lock | ||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lock: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | my $type = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | my $timeout = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 262 | # $type = LOCK_EX if( !defined( $type ) ); | ||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | ▶ | $type = LOCK_SH if( !defined( $type ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | ▶ | return( $self->unlock ) if( ( $type & LOCK_UN ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | ▶ | return( 1 ) if( $self->locked & $type ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | ▶ | $timeout = 0 if( !defined( $timeout ) || $timeout !~ /^\d+$/ ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $timeout and $timeout =~ /^\d+$/
MC/DC0%0/2
defined $timeout and $timeout =~ /^\d+$/
defined $timeout
$timeout =~ /^\d+$/
Truth table0%0/3
A and B
A= defined $timeoutB= $timeout =~ /^\d+$/
| |||||||||||||||||||||||||||||||||||||||||||
| 267 | # If the lock is different, release it first | ||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | ▶ | $self->unlock if( $self->locked ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | ▶ | my $semid = $self->semid || | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->semid || (return $self->error('No semaphore id set yet.'))
MC/DC0%0/1
$self->semid || (return $self->error('No semaphore id set yet.'))
$self->semid
Truth table0%0/2
A
A= $self->semid
| |||||||||||||||||||||||||||||||||||||||||||
| 270 | return( $self->error( "No semaphore id set yet." ) ); | ||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 272 | # try-catch | ||||||||||||||||||||||||||||||||||||||||||
| 273 | my $rv = eval | ||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | { | |||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | local $SIG{ALRM} = sub{ die( "timeout" ); }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | alarm( $timeout ); | |||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | my $rc = $self->op( @{$SEMOP_ARGS->{ $type }} ); | |||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | alarm(0); | |||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | return( $rc ); | |||||||||||||||||||||||||||||||||||||||||
| 280 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | ▶ | if( $@ ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | { | ||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | return( $self->error( "Unable to set a lock: $@" ) ); | |||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | ▶ | if( $rv ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 286 | { | ||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | $self->locked( $type ); | |||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||
| 289 | else | ||||||||||||||||||||||||||||||||||||||||||
| 290 | { | ||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | return( $self->error( "Failed to set a lock on semaphore id \"$semid\": $!" ) ); | |||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | return( $self ); | |||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||
| 296 | 6 | ▶ | sub locked { return( shift->_set_get_scalar( 'locked', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
locked: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||
| 298 | 128 | ▶ | sub mode { return( shift->_set_get_scalar( 'mode', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mode: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | sub op | ||||||||||||||||||||||||||||||||||||||||||
| 301 | 64 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
op: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 302 | 64 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 303 | 64 | ▶ | return( $self->error( "Invalid number of argument: '", join( ', ', @_ ), "'." ) ) if( @_ % 3 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 304 | 64 | my $data = pack( "s$N*", @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 305 | 64 | my $id = $self->semid; | |||||||||||||||||||||||||||||||||||||||||
| 306 | 64 | ▶ | return( $self->error( "No semaphore set yet. You must open the shared memory first to set the semaphore." ) ) if( !length( $id ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 307 | 64 | return( semop( $id, $data ) ); | |||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||
| 310 | sub open | ||||||||||||||||||||||||||||||||||||||||||
| 311 | 32 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
open: called CC=23 SCAR=43.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 312 | 32 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 313 | 32 | my $opts = {}; | |||||||||||||||||||||||||||||||||||||||||
| 314 | 32 | ▶ | if( ref( $_[0] ) eq 'HASH' ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 315 | { | ||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | $opts = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||||||||||
| 318 | else | ||||||||||||||||||||||||||||||||||||||||||
| 319 | { | ||||||||||||||||||||||||||||||||||||||||||
| 320 | 32 | @$opts{ qw( key mode size ) } = @_; | |||||||||||||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||||||||||||
| 322 | 32 | ▶ | $opts->{size} = $self->size unless( length( $opts->{size} ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 323 | 32 | $opts->{size} = int( $opts->{size} ); | |||||||||||||||||||||||||||||||||||||||||
| 324 | 32 | ▶ | $opts->{mode} //= ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts->{"mode"} //= ""
MC/DC0%0/1
$opts->{"mode"} //= ""
$opts->{"mode"}
Truth table50%1/2
A
A= $opts->{"mode"}
| |||||||||||||||||||||||||||||||||||||||||||
| 325 | 32 | ▶ | $opts->{key} //= ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts->{"key"} //= ""
MC/DC0%0/1
$opts->{"key"} //= ""
$opts->{"key"}
Truth table50%1/2
A
A= $opts->{"key"}
| |||||||||||||||||||||||||||||||||||||||||||
| 326 | 32 | my $serial; | |||||||||||||||||||||||||||||||||||||||||
| 327 | 32 | ▶ | if( length( $opts->{key} ) ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 328 | { | ||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | $serial = $self->_str2key( $opts->{key} ); | |||||||||||||||||||||||||||||||||||||||||
| 330 | # $serial = $opts->{key}; | ||||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||
| 332 | else | ||||||||||||||||||||||||||||||||||||||||||
| 333 | { | ||||||||||||||||||||||||||||||||||||||||||
| 334 | 32 | $serial = $self->serial; | |||||||||||||||||||||||||||||||||||||||||
| 335 | # $serial = $self->key; | ||||||||||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||||||||||
| 337 | 32 | my $create = 0; | |||||||||||||||||||||||||||||||||||||||||
| 338 | 32 | ▶ | if( $opts->{mode} eq 'w' || $opts->{key} =~ s/^>// ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/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 table33%1/3
A or B
A= $opts->{"mode"} eq "w"B= $opts->{"key"} =~ s/^>//
| |||||||||||||||||||||||||||||||||||||||||||
| 339 | { | ||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | $create++; | |||||||||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||||||||||
| 342 | ▶ | elsif( $opts->{mode} eq 'r' || $opts->{key} =~ s/^<// ) | |||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/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 table33%1/3
A or B
A= $opts->{"mode"} eq "r"B= $opts->{"key"} =~ s/^<//
| |||||||||||||||||||||||||||||||||||||||||||
| 343 | { | ||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | $create = 0; | |||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||
| 346 | else | ||||||||||||||||||||||||||||||||||||||||||
| 347 | { | ||||||||||||||||||||||||||||||||||||||||||
| 348 | 32 | $create = $self->create; | |||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||
| 350 | 32 | my $flags = $self->flags( create => $create ); | |||||||||||||||||||||||||||||||||||||||||
| 351 | 32 | my $id = shmget( $serial, $opts->{size}, $flags ); | |||||||||||||||||||||||||||||||||||||||||
| 352 | 32 | ▶ | if( defined( $id ) ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 353 | { | ||||||||||||||||||||||||||||||||||||||||||
| 354 | # Got shared memory | ||||||||||||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||||||||||||
| 356 | else | ||||||||||||||||||||||||||||||||||||||||||
| 357 | { | ||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | ▶ | my $newflags = ( $flags & &IPC::SysV::IPC_CREAT ) ? $flags : ( $flags | &IPC::SysV::IPC_CREAT ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | my $limit = ( $serial + 10 ); | |||||||||||||||||||||||||||||||||||||||||
| 360 | # IPC::SysV::ftok has likely made the serial unique, but as stated in the manual page, there is no guarantee | ||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | ▶ | while( $serial <= $limit ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 362 | { | ||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | $id = shmget( $serial, $opts->{size}, $newflags | &IPC::SysV::IPC_CREAT ); | |||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | $serial++; | |||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | ▶ | last if( defined( $id ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||
| 369 | 32 | ▶ | if( !defined( $id ) ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 370 | { | ||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | return( $self->error( "Unable to create shared memory id with key \"$serial\" and flags \"$flags\": $!" ) ); | |||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||
| 373 | 32 | $self->serial( $serial ); | |||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||
| 375 | # The value 3 can be anything above 0 and below the limit set by SEMMSL. On Linux system, this is usually 32,000. Seem semget(2) man page | ||||||||||||||||||||||||||||||||||||||||||
| 376 | 32 | my $semid = semget( $serial, 3, $flags ); | |||||||||||||||||||||||||||||||||||||||||
| 377 | 32 | ▶ | if( !defined( $semid ) ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 378 | { | ||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | my $newflags = ( $flags | &IPC::SysV::IPC_CREAT ); | |||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | $semid = semget( $serial, 3, $newflags ); | |||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | ▶ | return( $self->error( "Unable to get a semaphore for shared memory key \"", ( $opts->{key} || $self->key ), "\" wth id \"$id\": $!" ) ) if( !defined( $semid ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$opts->{'key'} || $self->key
MC/DC0%0/2
$opts->{'key'} || $self->key
$opts->{'key'}
$self->key
Truth table0%0/3
A || B
A= $opts->{'key'}B= $self->key
| |||||||||||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||||||||
| 383 | my $new = $self->new( | ||||||||||||||||||||||||||||||||||||||||||
| 384 | 32 | ▶ | key => $opts->{key} || $self->key, | ||||||||||||||||||||||||||||||||||||||||
|
Condition40%2/5
$self->new('key', $opts->{'key'} || $self->key, 'debug', $self->debug, 'mode', $self->mode, 'destroy', $self->destroy) || (return)
$opts->{'key'} || $self->key
MC/DC0%0/1
$self->new('key', $opts->{'key'} || $self->key, 'debug', $self->debug, 'mode', $self->mode, 'destroy', $self->destroy) || (return)
$self->new('key', $opts->{'key'} || $self->key, 'debug', $self->debug, 'mode', $self->mode, 'destroy', $self->destroy)
MC/DC0%0/2
$opts->{'key'} || $self->key
$opts->{'key'}
$self->key
Truth table50%1/2
A
A= $self->new('key', $opts->{'key'} || $self->key, 'debug', $self->debug, 'mode', $self->mode, 'destroy', $self->destroy)
Truth table33%1/3
A || B
A= $opts->{'key'}B= $self->key
| |||||||||||||||||||||||||||||||||||||||||||
| 385 | debug => $self->debug, | ||||||||||||||||||||||||||||||||||||||||||
| 386 | mode => $self->mode, | ||||||||||||||||||||||||||||||||||||||||||
| 387 | destroy => $self->destroy, | ||||||||||||||||||||||||||||||||||||||||||
| 388 | ) || return; | ||||||||||||||||||||||||||||||||||||||||||
| 389 | 32 | $new->id( $id ); | |||||||||||||||||||||||||||||||||||||||||
| 390 | 32 | $new->semid( $semid ); | |||||||||||||||||||||||||||||||||||||||||
| 391 | 32 | ▶ | if( !defined( $new->op( @{$SEMOP_ARGS->{LOCK_SH}} ) ) ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 392 | { | ||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | return( $self->error( "Unable to set lock on sempahore: $!" ) ); | |||||||||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||
| 396 | 32 | my $there = $new->stat( SEM_MARKER ); | |||||||||||||||||||||||||||||||||||||||||
| 397 | 32 | $new->size( $opts->{size} ); | |||||||||||||||||||||||||||||||||||||||||
| 398 | 32 | $new->flags( $flags ); | |||||||||||||||||||||||||||||||||||||||||
| 399 | 32 | ▶ | if( $there == SHM_EXISTS ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 400 | { | ||||||||||||||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||||||||||||
| 402 | else | ||||||||||||||||||||||||||||||||||||||||||
| 403 | { | ||||||||||||||||||||||||||||||||||||||||||
| 404 | # We initialise the semaphore with value of 1 | ||||||||||||||||||||||||||||||||||||||||||
| 405 | 25 | ▶ | $new->stat( SEM_MARKER, SHM_EXISTS ) || | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 406 | return( $self->error( "Unable to set semaphore during object creation: $!" ) ); | ||||||||||||||||||||||||||||||||||||||||||
| 407 | 25 | $SHEM_REPO->{ $id } = $new; | |||||||||||||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||||||||||||
| 409 | 32 | $new->op( @{$SEMOP_ARGS->{(LOCK_SH | LOCK_UN)}} ); | |||||||||||||||||||||||||||||||||||||||||
| 410 | 32 | return( $new ); | |||||||||||||||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||
| 413 | 0 | ▶ | sub owner { return( shift->_set_get_scalar( 'owner', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
owner: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||
| 415 | sub pid | ||||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pid: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 417 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 418 | 0 | my $sem = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | ▶ | my $semid = $self->semid || | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->semid || (return $self->error('No semaphore set yet. You must open the shared memory first to remove semaphore.'))
MC/DC0%0/1
$self->semid || (return $self->error('No semaphore set yet. You must open the shared memory first to remove semaphore.'))
$self->semid
Truth table0%0/2
A
A= $self->semid
| |||||||||||||||||||||||||||||||||||||||||||
| 420 | return( $self->error( "No semaphore set yet. You must open the shared memory first to remove semaphore." ) ); | ||||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | my $v = semctl( $semid, $sem, &IPC::SysV::GETPID, 0 ); | |||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | ▶ | return( $v ? 0 + $v : undef() ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||
| 425 | sub rand | ||||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rand: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | ▶ | my $size = $self->size || 1024; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->size || 1024
MC/DC0%0/1
$self->size || 1024
$self->size
Truth table0%0/2
A
A= $self->size
| |||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | ▶ | my $key = shmget( &IPC::SysV::IPC_PRIVATE, $size, &IPC::SysV::S_IRWXU|&IPC::SysV::S_IRWXG|&IPC::SysV::S_IRWXO ) || | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shmget(&IPC::SysV::IPC_PRIVATE, $size, &IPC::SysV::S_IRWXU | &IPC::SysV::S_IRWXG | &IPC::SysV::S_IRWXO) || (return $self->error("Unable to generate a share memory key: $!"))
MC/DC0%0/1
shmget(&IPC::SysV::IPC_PRIVATE, $size, &IPC::SysV::S_IRWXU | &IPC::SysV::S_IRWXG | &IPC::SysV::S_IRWXO) || (return $self->error("Unable to generate a share memory key: $!"))
shmget(&IPC::SysV::IPC_PRIVATE, $size, &IPC::SysV::S_IRWXU | &IPC::SysV::S_IRWXG | &IPC::SysV::S_IRWXO)
Truth table0%0/2
A
A= shmget(&IPC::SysV::IPC_PRIVATE, $size, &IPC::SysV::S_IRWXU | &IPC::SysV::S_IRWXG | &IPC::SysV::S_IRWXO)
| |||||||||||||||||||||||||||||||||||||||||||
| 430 | return( $self->error( "Unable to generate a share memory key: $!" ) ); | ||||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | return( $key ); | |||||||||||||||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||
| 434 | # $self->read( $buffer, $size ); | ||||||||||||||||||||||||||||||||||||||||||
| 435 | sub read | ||||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read: not called CC=19 SCAR=59.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 437 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 438 | 0 | my $id = $self->id; | |||||||||||||||||||||||||||||||||||||||||
| 439 | # Optional length parameter for non-reference data only | ||||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | ▶ | my $size = int( $_[1] || $self->size || SHM_BUFSIZ ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/5
$_[1] || $self->size || 65536
$_[1] or $self->size
MC/DC0%0/2
$_[1] || $self->size || 65536
$_[1]
$self->size
Truth table0%0/3
A or B
A= $_[1]B= $self->size
| |||||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | ▶ | return( $self->error( "No shared memory id! Have you opened it first?" ) ) if( !length( $id ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | my $buffer = ''; | |||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | my $addr = $self->addr; | |||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | ▶ | if( $addr ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 445 | { | ||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | ▶ | memread( $addr, $buffer, 0, $size ) || | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 447 | return( $self->error( "Unable to read data from shared memory address \"$addr\" using memread: $!" ) ); | ||||||||||||||||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||||||||||||||||
| 449 | else | ||||||||||||||||||||||||||||||||||||||||||
| 450 | { | ||||||||||||||||||||||||||||||||||||||||||
| 451 | 0 | ▶ | shmread( $id, $buffer, 0, $size ) || | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 452 | return( $self->error( "Unable to read data from shared memory id \"$id\": $!" ) ); | ||||||||||||||||||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||||||||||||||||
| 454 | # Get rid of nulls end padded | ||||||||||||||||||||||||||||||||||||||||||
| 455 | 0 | $buffer = unpack( "A*", $buffer ); | |||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | my $first_char = substr( $buffer, 0, 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 457 | 0 | my $j = JSON->new->utf8->relaxed->allow_nonref; | |||||||||||||||||||||||||||||||||||||||||
| 458 | 0 | my $data; | |||||||||||||||||||||||||||||||||||||||||
| 459 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 460 | # try-catch | ||||||||||||||||||||||||||||||||||||||||||
| 461 | eval | ||||||||||||||||||||||||||||||||||||||||||
| 462 | 0 | { | |||||||||||||||||||||||||||||||||||||||||
| 463 | # Does the value have any typical json format? " for a string, { for an hash and [ for an array | ||||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | ▶ | if( $first_char eq '"' || $first_char eq '{' || $first_char eq '[' ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$first_char eq "\"" or $first_char eq "{" or $first_char eq "["
$first_char eq "\"" or $first_char eq "{"
MC/DC0%0/3
$first_char eq "\"" or $first_char eq "{" or $first_char eq "["
$first_char eq "\""
$first_char eq "{"
$first_char eq "["
Truth table0%0/4
A or B or C
A= $first_char eq "\""B= $first_char eq "{"C= $first_char eq "["
| |||||||||||||||||||||||||||||||||||||||||||
| 465 | { | ||||||||||||||||||||||||||||||||||||||||||
| 466 | 0 | $data = $j->decode( $buffer ); | |||||||||||||||||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||||||||||||||||
| 468 | else | ||||||||||||||||||||||||||||||||||||||||||
| 469 | { | ||||||||||||||||||||||||||||||||||||||||||
| 470 | 0 | $data = $buffer; | |||||||||||||||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||||||||||||||||
| 472 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 473 | 0 | ▶ | if( $@ ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 474 | { | ||||||||||||||||||||||||||||||||||||||||||
| 475 | 0 | ▶ | $self->error( "An error occured while json decoding data: $@", ( length( $buffer ) <= 1024 ? "\nData is: '$buffer'" : '' ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 476 | # Maybe it's a string that starts with '{' or " or [ and triggered an error because it was not actually json data? | ||||||||||||||||||||||||||||||||||||||||||
| 477 | # So we return the data stored as it is | ||||||||||||||||||||||||||||||||||||||||||
| 478 | 0 | ▶ | if( @_ ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 479 | { | ||||||||||||||||||||||||||||||||||||||||||
| 480 | 0 | $_[0] = $buffer; | |||||||||||||||||||||||||||||||||||||||||
| 481 | 0 | ▶ | return( length( $buffer ) || "0E0" ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
length $buffer || '0E0'
MC/DC0%0/1
length $buffer || '0E0'
length $buffer
Truth table0%0/2
A
A= length $buffer
| |||||||||||||||||||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||||||||||||||||
| 483 | else | ||||||||||||||||||||||||||||||||||||||||||
| 484 | { | ||||||||||||||||||||||||||||||||||||||||||
| 485 | 0 | return( $buffer ); | |||||||||||||||||||||||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||
| 489 | 0 | ▶ | if( @_ ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 490 | { | ||||||||||||||||||||||||||||||||||||||||||
| 491 | 0 | my $len = length( $_[0] ); | |||||||||||||||||||||||||||||||||||||||||
| 492 | # If the decoded data is not a reference of any sort, and the length parameter was provided | ||||||||||||||||||||||||||||||||||||||||||
| 493 | 0 | ▶ | if( !ref( $data ) ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 494 | { | ||||||||||||||||||||||||||||||||||||||||||
| 495 | 0 | ▶ | $_[0] = $size > 0 ? substr( $data, 0, $size ) : $data; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 496 | 0 | ▶ | return( length( $_[0] ) || "0E0" ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
length $_[0] || '0E0'
MC/DC0%0/1
length $_[0] || '0E0'
length $_[0]
Truth table0%0/2
A
A= length $_[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 497 | } | ||||||||||||||||||||||||||||||||||||||||||
| 498 | else | ||||||||||||||||||||||||||||||||||||||||||
| 499 | { | ||||||||||||||||||||||||||||||||||||||||||
| 500 | 0 | $_[0] = $data; | |||||||||||||||||||||||||||||||||||||||||
| 501 | 0 | ▶ | return( $len || "0E0" ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$len || '0E0'
MC/DC0%0/1
$len || '0E0'
$len
Truth table0%0/2
A
A= $len
| |||||||||||||||||||||||||||||||||||||||||||
| 502 | } | ||||||||||||||||||||||||||||||||||||||||||
| 503 | } | ||||||||||||||||||||||||||||||||||||||||||
| 504 | else | ||||||||||||||||||||||||||||||||||||||||||
| 505 | { | ||||||||||||||||||||||||||||||||||||||||||
| 506 | 0 | return( $data ); | |||||||||||||||||||||||||||||||||||||||||
| 507 | } | ||||||||||||||||||||||||||||||||||||||||||
| 508 | } | ||||||||||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||||||||
| 510 | sub remove | ||||||||||||||||||||||||||||||||||||||||||
| 511 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
remove: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 512 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 513 | 0 | ▶ | return( 1 ) if( $self->removed ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 514 | 0 | my $id = $self->id(); | |||||||||||||||||||||||||||||||||||||||||
| 515 | 0 | ▶ | return( $self->error( "No shared memory id! Have you opened it first?" ) ) if( !length( $id ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 516 | 0 | my $semid = $self->semid; | |||||||||||||||||||||||||||||||||||||||||
| 517 | 0 | ▶ | return( $self->error( "No semaphore set yet. You must open the shared memory first to remove semaphore." ) ) if( !length( $semid ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 518 | 0 | $self->unlock(); | |||||||||||||||||||||||||||||||||||||||||
| 519 | # Remove share memory segment | ||||||||||||||||||||||||||||||||||||||||||
| 520 | 0 | ▶ | if( !defined( shmctl( $id, &IPC::SysV::IPC_RMID, 0 ) ) ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 521 | { | ||||||||||||||||||||||||||||||||||||||||||
| 522 | 0 | return( $self->error( "Unable to remove share memory segement id '$id' (IPC_RMID is '", &IPC::SysV::IPC_RMID, "'): $!" ) ); | |||||||||||||||||||||||||||||||||||||||||
| 523 | } | ||||||||||||||||||||||||||||||||||||||||||
| 524 | # Remove semaphore | ||||||||||||||||||||||||||||||||||||||||||
| 525 | 0 | my $rv; | |||||||||||||||||||||||||||||||||||||||||
| 526 | 0 | ▶ | if( !defined( $rv = semctl( $semid, 0, &IPC::SysV::IPC_RMID, 0 ) ) ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 527 | { | ||||||||||||||||||||||||||||||||||||||||||
| 528 | 0 | $self->error( "Warning only: could not remove the semaphore id \"$semid\": $!" ); | |||||||||||||||||||||||||||||||||||||||||
| 529 | } | ||||||||||||||||||||||||||||||||||||||||||
| 530 | 0 | ▶ | $self->removed( $rv ? 1 : 0 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 531 | 0 | ▶ | if( $rv ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 532 | { | ||||||||||||||||||||||||||||||||||||||||||
| 533 | 0 | delete( $SHEM_REPO->{ $id } ); | |||||||||||||||||||||||||||||||||||||||||
| 534 | 0 | $self->id( undef() ); | |||||||||||||||||||||||||||||||||||||||||
| 535 | 0 | $self->semid( undef() ); | |||||||||||||||||||||||||||||||||||||||||
| 536 | } | ||||||||||||||||||||||||||||||||||||||||||
| 537 | 0 | ▶ | return( $rv ? 1 : 0 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 538 | } | ||||||||||||||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||||||||||||
| 540 | 0 | ▶ | sub removed { return( shift->_set_get_boolean( 'removed', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
removed: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||||||||||||
| 542 | 153 | ▶ | sub semid { return( shift->_set_get_scalar( 'semid', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
semid: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||||||||||||
| 544 | 64 | ▶ | sub serial { return( shift->_set_get_scalar( 'serial', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
serial: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||||||||||||
| 546 | 96 | ▶ | sub size { return( shift->_set_get_scalar( 'size', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
size: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||||||||||||
| 548 | sub stat | ||||||||||||||||||||||||||||||||||||||||||
| 549 | 57 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stat: called CC=8 SCAR=27.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 550 | 57 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 551 | 57 | my $id = $self->semid; | |||||||||||||||||||||||||||||||||||||||||
| 552 | 57 | ▶ | return( $self->error( "No semaphore set yet. You must open the shared memory first to set the semaphore." ) ) if( !length( $id ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 553 | 57 | ▶ | if( @_ ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 554 | { | ||||||||||||||||||||||||||||||||||||||||||
| 555 | 57 | ▶ | if( @_ == 1 ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 556 | { | ||||||||||||||||||||||||||||||||||||||||||
| 557 | 32 | my $sem = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 558 | 32 | my $v = semctl( $id, $sem, &IPC::SysV::GETVAL, 0 ); | |||||||||||||||||||||||||||||||||||||||||
| 559 | 32 | ▶ | return( $v ? 0 + $v : undef() ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 560 | } | ||||||||||||||||||||||||||||||||||||||||||
| 561 | else | ||||||||||||||||||||||||||||||||||||||||||
| 562 | { | ||||||||||||||||||||||||||||||||||||||||||
| 563 | 25 | my( $sem, $val ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 564 | 25 | return( semctl( $id, $sem, &IPC::SysV::SETVAL, $val ) ); | |||||||||||||||||||||||||||||||||||||||||
| 565 | } | ||||||||||||||||||||||||||||||||||||||||||
| 566 | } | ||||||||||||||||||||||||||||||||||||||||||
| 567 | else | ||||||||||||||||||||||||||||||||||||||||||
| 568 | { | ||||||||||||||||||||||||||||||||||||||||||
| 569 | 0 | my $data = ''; | |||||||||||||||||||||||||||||||||||||||||
| 570 | 0 | ▶ | if( wantarray() ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 571 | { | ||||||||||||||||||||||||||||||||||||||||||
| 572 | 0 | ▶ | semctl( $id, 0, &IPC::SysV::GETALL, $data ) || return( () ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 573 | 0 | return( ( unpack( "s*", $data ) ) ); | |||||||||||||||||||||||||||||||||||||||||
| 574 | } | ||||||||||||||||||||||||||||||||||||||||||
| 575 | else | ||||||||||||||||||||||||||||||||||||||||||
| 576 | { | ||||||||||||||||||||||||||||||||||||||||||
| 577 | 0 | ▶ | semctl( $id, 0, &IPC::SysV::IPC_STAT, $data ) || | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 578 | return( $self->error( "Unable to stat semaphore with id '$id': $!" ) ); | ||||||||||||||||||||||||||||||||||||||||||
| 579 | 0 | return( Apache2::SSI::SemStat->new->unpack( $data ) ); | |||||||||||||||||||||||||||||||||||||||||
| 580 | } | ||||||||||||||||||||||||||||||||||||||||||
| 581 | } | ||||||||||||||||||||||||||||||||||||||||||
| 582 | } | ||||||||||||||||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||||||||||||||||
| 584 | 64 | ▶ | sub supported { return( $SYSV_SUPPORTED ); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
supported: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||||||||||||
| 586 | sub unlock | ||||||||||||||||||||||||||||||||||||||||||
| 587 | 6 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unlock: called CC=5 SCAR=29.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 588 | 6 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 589 | 6 | ▶ | return( 1 ) if( !$self->locked ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 590 | 0 | my $semid = $self->semid; | |||||||||||||||||||||||||||||||||||||||||
| 591 | 0 | ▶ | return( $self->error( "No semaphore set yet. You must open the shared memory first to unlock semaphore." ) ) if( !length( $semid ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 592 | 0 | my $type = $self->locked | LOCK_UN; | |||||||||||||||||||||||||||||||||||||||||
| 593 | 0 | ▶ | $type ^= LOCK_NB if( $type & LOCK_NB ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 594 | 0 | ▶ | if( defined( $self->op( @{$SEMOP_ARGS->{ $type }} ) ) ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 595 | { | ||||||||||||||||||||||||||||||||||||||||||
| 596 | 0 | $self->locked( 0 ); | |||||||||||||||||||||||||||||||||||||||||
| 597 | } | ||||||||||||||||||||||||||||||||||||||||||
| 598 | 0 | return( $self ); | |||||||||||||||||||||||||||||||||||||||||
| 599 | } | ||||||||||||||||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||||||||||||||||
| 601 | sub write | ||||||||||||||||||||||||||||||||||||||||||
| 602 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 603 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 604 | 0 | ▶ | my $data = ( @_ == 1 ) ? shift( @_ ) : join( '', @_ ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 605 | 0 | my $id = $self->id(); | |||||||||||||||||||||||||||||||||||||||||
| 606 | 0 | ▶ | my $size = int( $self->size() ) || SHM_BUFSIZ; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
int $self->size || 65536
MC/DC0%0/1
int $self->size || 65536
int $self->size
Truth table0%0/2
A
A= int $self->size
| |||||||||||||||||||||||||||||||||||||||||||
| 607 | 0 | my @callinfo = caller; | |||||||||||||||||||||||||||||||||||||||||
| 608 | 0 | my $j = JSON->new->utf8->relaxed->allow_nonref->convert_blessed; | |||||||||||||||||||||||||||||||||||||||||
| 609 | 0 | my $encoded; | |||||||||||||||||||||||||||||||||||||||||
| 610 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 611 | # try-catch | ||||||||||||||||||||||||||||||||||||||||||
| 612 | eval | ||||||||||||||||||||||||||||||||||||||||||
| 613 | 0 | { | |||||||||||||||||||||||||||||||||||||||||
| 614 | 0 | $encoded = $j->encode( $data ); | |||||||||||||||||||||||||||||||||||||||||
| 615 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 616 | 0 | ▶ | if( $@ ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 617 | { | ||||||||||||||||||||||||||||||||||||||||||
| 618 | 0 | return( $self->error( "An error occured json encoding data provided: $@" ) ); | |||||||||||||||||||||||||||||||||||||||||
| 619 | } | ||||||||||||||||||||||||||||||||||||||||||
| 620 | |||||||||||||||||||||||||||||||||||||||||||
| 621 | 0 | ▶ | if( length( $encoded ) > $size ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 622 | { | ||||||||||||||||||||||||||||||||||||||||||
| 623 | 0 | return( $self->error( "Data to write are ", length( $encoded ), " bytes long and exceed the maximum you have set of '$size'." ) ); | |||||||||||||||||||||||||||||||||||||||||
| 624 | } | ||||||||||||||||||||||||||||||||||||||||||
| 625 | # $size = length( $encoded ); | ||||||||||||||||||||||||||||||||||||||||||
| 626 | 0 | my $addr = $self->addr; | |||||||||||||||||||||||||||||||||||||||||
| 627 | 0 | ▶ | if( $addr ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 628 | { | ||||||||||||||||||||||||||||||||||||||||||
| 629 | 0 | ▶ | memwrite( $addr, $encoded, 0, $size ) || | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 630 | return( $self->error( "Unable to write to shared memory address '$addr' using memwrite: $!" ) ); | ||||||||||||||||||||||||||||||||||||||||||
| 631 | } | ||||||||||||||||||||||||||||||||||||||||||
| 632 | else | ||||||||||||||||||||||||||||||||||||||||||
| 633 | { | ||||||||||||||||||||||||||||||||||||||||||
| 634 | 0 | ▶ | shmwrite( $id, $encoded, 0, $size ) || | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 635 | return( $self->error( "Unable to write to shared memory id '$id': $!" ) ); | ||||||||||||||||||||||||||||||||||||||||||
| 636 | } | ||||||||||||||||||||||||||||||||||||||||||
| 637 | 0 | return( $self ); | |||||||||||||||||||||||||||||||||||||||||
| 638 | } | ||||||||||||||||||||||||||||||||||||||||||
| 639 | |||||||||||||||||||||||||||||||||||||||||||
| 640 | sub _str2key | ||||||||||||||||||||||||||||||||||||||||||
| 641 | 64 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_str2key: called CC=5 SCAR=18.4
| |||||||||||||||||||||||||||||||||||||||||||
| 642 | 64 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 643 | 64 | my $key = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 644 | 64 | ▶ | if( !defined( $key ) || $key eq '' ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
not defined $key or $key eq ""
MC/DC0%0/2
not defined $key or $key eq ""
not defined $key
$key eq ""
Truth table33%1/3
not(A) or B
A= not defined $keyB= $key eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 645 | { | ||||||||||||||||||||||||||||||||||||||||||
| 646 | 0 | return( &IPC::SysV::IPC_PRIVATE ); | |||||||||||||||||||||||||||||||||||||||||
| 647 | } | ||||||||||||||||||||||||||||||||||||||||||
| 648 | elsif( $key =~ /^\d+$/ ) | ||||||||||||||||||||||||||||||||||||||||||
| 649 | { | ||||||||||||||||||||||||||||||||||||||||||
| 650 | 0 | return( IPC::SysV::ftok( __FILE__, $key ) ); | |||||||||||||||||||||||||||||||||||||||||
| 651 | } | ||||||||||||||||||||||||||||||||||||||||||
| 652 | else | ||||||||||||||||||||||||||||||||||||||||||
| 653 | { | ||||||||||||||||||||||||||||||||||||||||||
| 654 | 64 | my $id = 0; | |||||||||||||||||||||||||||||||||||||||||
| 655 | 64 | $id += $_ for( unpack( "C*", $key ) ); | |||||||||||||||||||||||||||||||||||||||||
| 656 | # We use the root as a reliable and stable path. | ||||||||||||||||||||||||||||||||||||||||||
| 657 | # I initially though about using __FILE__, but during testing this would be in ./blib/lib and beside one user might use a version of this module somewhere while the one used under Apache/mod_perl2 could be somewhere else and this would render the generation of the IPC key unreliable and unrepeatable | ||||||||||||||||||||||||||||||||||||||||||
| 658 | 64 | my $val = IPC::SysV::ftok( '/', $id ); | |||||||||||||||||||||||||||||||||||||||||
| 659 | 64 | return( $val ); | |||||||||||||||||||||||||||||||||||||||||
| 660 | } | ||||||||||||||||||||||||||||||||||||||||||
| 661 | } | ||||||||||||||||||||||||||||||||||||||||||
| 662 | |||||||||||||||||||||||||||||||||||||||||||
| 663 | END | ||||||||||||||||||||||||||||||||||||||||||
| 664 | 9 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
END: called CC=4 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 665 | 9 | foreach my $id ( keys( %$SHEM_REPO ) ) | |||||||||||||||||||||||||||||||||||||||||
| 666 | { | ||||||||||||||||||||||||||||||||||||||||||
| 667 | 6 | my $s = $SHEM_REPO->{ $id }; | |||||||||||||||||||||||||||||||||||||||||
| 668 | 6 | $s->unlock; | |||||||||||||||||||||||||||||||||||||||||
| 669 | 6 | ▶ | next unless( $s->destroy ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 670 | 0 | ▶ | next unless( $s->owner == $$ ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 671 | 0 | $s->remove; | |||||||||||||||||||||||||||||||||||||||||
| 672 | } | ||||||||||||||||||||||||||||||||||||||||||
| 673 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 674 | |||||||||||||||||||||||||||||||||||||||||||
| 675 | # DESTROY | ||||||||||||||||||||||||||||||||||||||||||
| 676 | # { | ||||||||||||||||||||||||||||||||||||||||||
| 677 | # my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||
| 678 | # my @callinfo = caller; | ||||||||||||||||||||||||||||||||||||||||||
| 679 | # ## $self->message( 3, "Got here from package $callinfo[0] in file $callinfo[1] at line $callinfo[2], destroying object for shared memory id \"", $self->id, "\" key \"", $self->key, "\" with destroy flags '", $self->destroy, "'." ); | ||||||||||||||||||||||||||||||||||||||||||
| 680 | # ## $self->message( 3, "Object contains following keys: ", sub{ $self->dump( $self ) } ); | ||||||||||||||||||||||||||||||||||||||||||
| 681 | # $self->unlock; | ||||||||||||||||||||||||||||||||||||||||||
| 682 | # $self->remove if( $self->destroy ); | ||||||||||||||||||||||||||||||||||||||||||
| 683 | # }; | ||||||||||||||||||||||||||||||||||||||||||
| 684 | |||||||||||||||||||||||||||||||||||||||||||
| 685 | |||||||||||||||||||||||||||||||||||||||||||
| 686 | { | ||||||||||||||||||||||||||||||||||||||||||
| 687 | package | ||||||||||||||||||||||||||||||||||||||||||
| 688 | Apache2::SSI::SemStat; | ||||||||||||||||||||||||||||||||||||||||||
| 689 | 9 | our $VERSION = 'v0.1.0'; | |||||||||||||||||||||||||||||||||||||||||
| 690 | |||||||||||||||||||||||||||||||||||||||||||
| 691 | 9 | ▶ | use constant UID => 0; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 692 | 9 | ▶ | use constant GID => 1; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 693 | 9 | ▶ | use constant CUID => 2; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 694 | 9 | ▶ | use constant CGID => 3; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 695 | 9 | ▶ | use constant MODE => 4; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 696 | 9 | ▶ | use constant CTIME => 5; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 697 | 9 | ▶ | use constant OTIME => 6; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 698 | 9 | ▶ | use constant NSEMS => 7; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 699 | |||||||||||||||||||||||||||||||||||||||||||
| 700 | sub new | ||||||||||||||||||||||||||||||||||||||||||
| 701 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 702 | 0 | my $this = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 703 | 0 | my @vals = @_; | |||||||||||||||||||||||||||||||||||||||||
| 704 | 0 | ▶ | return( bless( [ @vals ] => ref( $this ) || $this ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
ref $this || $this
MC/DC0%0/2
ref $this || $this
ref $this
$this
Truth table0%0/3
A || B
A= ref $thisB= $this
| |||||||||||||||||||||||||||||||||||||||||||
| 705 | } | ||||||||||||||||||||||||||||||||||||||||||
| 706 | |||||||||||||||||||||||||||||||||||||||||||
| 707 | 0 | ▶ | sub cgid { return( shift->[CGID] ); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cgid: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 708 | |||||||||||||||||||||||||||||||||||||||||||
| 709 | 0 | ▶ | sub ctime { return( shift->[CTIME] ); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ctime: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 710 | |||||||||||||||||||||||||||||||||||||||||||
| 711 | 0 | ▶ | sub cuid { return( shift->[CUID] ); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cuid: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 712 | |||||||||||||||||||||||||||||||||||||||||||
| 713 | 0 | ▶ | sub gid { return( shift->[GID] ); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
gid: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 714 | |||||||||||||||||||||||||||||||||||||||||||
| 715 | 0 | ▶ | sub mode { return( shift->[MODE] ); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mode: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 716 | |||||||||||||||||||||||||||||||||||||||||||
| 717 | 0 | ▶ | sub nsems { return( shift->[NSEMS] ); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
nsems: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 718 | |||||||||||||||||||||||||||||||||||||||||||
| 719 | 0 | ▶ | sub otime { return( shift->[OTIME] ); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
otime: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 720 | |||||||||||||||||||||||||||||||||||||||||||
| 721 | 0 | ▶ | sub uid { return( shift->[UID] ); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
uid: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 722 | } | ||||||||||||||||||||||||||||||||||||||||||
| 723 | |||||||||||||||||||||||||||||||||||||||||||
| 724 | 9 | 1; | |||||||||||||||||||||||||||||||||||||||||