blib/lib/POSIX/RT/SharedMem.pm

filter: Statementstmt 100% 43 / 43 Branchbran 68.1% 15 / 22 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 8 / 8 Podpod 100% 1 / 1 totaltotal 87.3% 69 / 79 CC 13 SCAR 22.6
CC
13
Cov
88%
shared_open
14.3
BEGIN
1.0
BEGIN
1.0
CRAP 9.6
↑ Summary Build »
1 package POSIX::RT::SharedMem;
2 2 $POSIX::RT::SharedMem::VERSION = '0.10';
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use Exporter 5.57 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use XSLoader;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Fcntl qw/O_RDONLY O_WRONLY O_RDWR O_CREAT/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 ▶use File::Map 'map_handle';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 our @EXPORT_OK = qw/shared_open shared_unlink/;
14  
15 2 XSLoader::load(__PACKAGE__, __PACKAGE__->VERSION);
16  
17 2 my $default_perms = oct '600';
18  
19 2 my %flag_for = (
20 '<' => O_RDONLY,
21 '+<' => O_RDWR,
22 '>' => O_WRONLY | O_CREAT,
23 '+>' => O_RDWR | O_CREAT,
24 );
25  
26 sub shared_open { ## no critic (Subroutines::RequireArgUnpacking)
27 4 ▶ my (undef, $name, $mode, %other) = @_;
Subroutine shared_open: called CC=13 SCAR=26.6
Pod documented
28  
29 4 my %options = (
30 perms => $default_perms,
31 offset => 0,
32 flags => 0,
33 %other,
34 );
35 4 ▶ croak 'Not enough arguments for shared_open' if @_ < 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 2 0 4 4
36 4 ▶ $mode = '<' if not defined $mode;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $mode 2 2 4
37 4 ▶ croak 'No such mode' if not defined $flag_for{$mode};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $flag_for{$mode} 0 4 4
38 4 ▶ croak 'Size must be given in creating mode' if $flag_for{$mode} & O_CREAT and $options{size} == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $flag_for{$mode} & 64 and $options{"size"} == 0 0 4 4
Condition66%2/3
$flag_for{$mode} & 64 and $options{"size"} == 0
!ll&&!rl&&r
220
MC/DC0%0/2
$flag_for{$mode} & 64 and $options{"size"} == 0
$flag_for{$mode} & 64 $options{"size"} == 0
Truth table66%2/3
A and B
A= $flag_for{$mode} & 64B= $options{"size"} == 0
ABresult
0X0
100
111
39  
40 4 my $fh = _shm_open($name, $flag_for{$mode} | $options{flags}, $options{perms});
41 2 ▶ $options{after_open}->($fh, \%options) if defined $options{after_open};
Branch: 1 branch
BranchTrueFalseTotal
if defined $options{"after_open"} 0 2 2
42  
43 2 ▶ $options{size} = -s $fh if not defined $options{size};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $options{"size"} 1 1 2
44 2 ▶ croak 'Can\'t map empty file' if $options{size} == 0; # Should never happen
Branch: 1 branch
BranchTrueFalseTotal
if $options{"size"} == 0 0 2 2
45 2 ▶ truncate $fh, $options{size} if $options{size} > -s $fh;
Branch: 1 branch
BranchTrueFalseTotal
if $options{"size"} > -s $fh 1 1 2
46  
47 2 ▶ $options{before_mapping}->($fh, \%options) if defined $options{before_mapping};
Branch: 1 branch
BranchTrueFalseTotal
if defined $options{"before_mapping"} 0 2 2
48 2 map_handle $_[0], $fh, $mode, $options{offset}, $options{size};
49  
50 2 ▶ return $fh if defined wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if defined wantarray 1 1 2
51  
52 1 ▶ close $fh or croak "Could not close shared filehandle: $!";
Branch: 1 branch
BranchTrueFalseTotal
close $fh or croak("Could not close shared filehandle: $!") 0 1 1
53 1 return;
54 }
55  
56 2 1; # End of POSIX::RT::SharedMem
57  
58 #ABSTRACT: Create/open or unlink POSIX shared memory objects in Perl
59  
60 __END__
↑ Summary Build »