File Coverage

blib/lib/Dir/Self.pm
Criterion Covered Total %
statement 25 32 78.1
branch 2 6 33.3
condition 1 2 50.0
subroutine 7 9 77.7
pod n/a
total 35 49 71.4


line stmt bran cond sub pod time code
1             package Dir::Self;
2              
3             $VERSION = '0.11';
4              
5 1     1   20236 use 5.005;
  1         4  
  1         38  
6 1     1   6 use strict;
  1         1  
  1         35  
7              
8 1     1   4 use File::Spec ();
  1         7  
  1         163  
9              
10              
11             sub __DIR__ () {
12 3   50 3   1806 my $level = shift || 0;
13 3         16 my $file = (caller $level)[1];
14 3         155 File::Spec->rel2abs(join '', (File::Spec->splitpath($file))[0, 1])
15             }
16              
17             sub _const {
18 0     0   0 my $value = shift;
19 0     0   0 sub () { $value }
20 0         0 }
21              
22             sub import {
23 1     1   6 my $class = shift;
24 1         1 my $caller = caller;
25              
26 1 50       5 @_ or @_ = '__DIR__';
27              
28 1         3 for my $item (@_) {
29 1 50       3 if ($item eq '__DIR__') {
    0          
30 1     1   4 no strict 'refs';
  1         1  
  1         139  
31 1         1 *{$caller . '::__DIR__'} = \&__DIR__;
  1         43  
32             } elsif ($item eq ':static') {
33 1     1   5 no strict 'refs';
  1         2  
  1         109  
34 0           *{$caller . '::__DIR__'} = _const &__DIR__(1);
  0            
35             } else {
36 0           require Carp;
37 0           Carp::croak(qq{"$item" is not exported by the $class module});
38             }
39             }
40             }
41              
42             1
43             __END__