File Coverage

blib/lib/exact/lib.pm
Criterion Covered Total %
statement 32 32 100.0
branch 7 10 70.0
condition 1 2 50.0
subroutine 7 7 100.0
pod n/a
total 47 51 92.1


line stmt bran cond sub pod time code
1             package exact::lib;
2             # ABSTRACT: Compile-time @INC manipulation extension for exact
3              
4 1     1   265178 use 5.014;
  1         11  
5 1     1   6 use exact;
  1         2  
  1         21  
6 1     1   837 use strict;
  1         3  
  1         24  
7 1     1   501 use FindBin;
  1         1112  
  1         625  
8              
9             our $VERSION = '1.02'; # VERSION
10              
11             sub import {
12 1     1   29 my ( $self, $caller, $input ) = @_;
13              
14 1   50     4 $input //= 'lib';
15 1         13 $input =~ s/(^\s+|\s+$)//g;
16              
17 1         6 for my $dir ( map { s/\\ / /g; $_ } split( /(?
  3         7  
  3         8  
18 3 100       13 if ( index( $dir, '/', 0 ) == 0 ) {
    100          
19 1         2 _add_to_inc($dir);
20             }
21             elsif ( index( $dir, '.', 0 ) == 0 ) {
22 1         5 _add_to_inc( $FindBin::Bin . '/' . $dir );
23             }
24             else {
25 1         3 my $found_dir = _find_dir($dir);
26 1 50       4 _add_to_inc($found_dir) if ($found_dir);
27             }
28             }
29             }
30              
31             sub _add_to_inc {
32 2     2   4 for my $lib (@_) {
33 2 50       5 unshift( @INC, $lib ) unless ( grep { $_ eq $lib } @INC );
  23         41  
34             }
35             }
36              
37             sub _find_dir {
38 1     1   2 my ($suffix) = @_;
39              
40 1         8 my @search_path = split( '/', $FindBin::Bin );
41 1         6 while ( @search_path > 0 ) {
42 6         17 my $dir = join( '/', @search_path, $suffix );
43 6 50       185 return $dir if ( -d $dir );
44 6         24 pop @search_path;
45             }
46              
47 1         5 return;
48             }
49              
50             1;
51              
52             __END__