File Coverage

blib/lib/Mutex.pm
Criterion Covered Total %
statement 19 19 100.0
branch 5 6 83.3
condition 1 2 50.0
subroutine 6 6 100.0
pod 2 2 100.0
total 33 35 94.2


line stmt bran cond sub pod time code
1             ###############################################################################
2             ## ----------------------------------------------------------------------------
3             ## Mutex - Various locking implementations supporting processes and threads.
4             ##
5             ###############################################################################
6              
7             package Mutex;
8              
9 3     3   170513 use strict;
  3         22  
  3         74  
10 3     3   13 use warnings;
  3         4  
  3         93  
11              
12             our $VERSION = '1.009';
13              
14             ## no critic (BuiltinFunctions::ProhibitStringyEval)
15             ## no critic (TestingAndDebugging::ProhibitNoStrict)
16              
17 3     3   12 use Carp ();
  3         13  
  3         324  
18              
19             sub new {
20 4     4 1 206 my ($class, %argv) = @_;
21             my $impl = defined($argv{impl})
22 4 100       20 ? $argv{impl} : defined($argv{path}) ? 'Flock' : 'Channel';
    100          
23              
24 4         45 $impl = ucfirst( lc $impl );
25              
26 4 50       228 eval "require Mutex::$impl; 1;" ||
27             Carp::croak("Could not load Mutex implementation '$impl': $@");
28              
29 4         15 my $pkg = 'Mutex::'.$impl;
30 3     3   16 no strict 'refs';
  3         4  
  3         266  
31              
32 4         19 return $pkg->new( %argv );
33             }
34              
35             ## base class method
36              
37             sub impl {
38 4   50 4 1 46 return $_[0]->{impl} || 'Not defined';
39             }
40              
41             1;
42              
43             __END__