File Coverage

blib/lib/Shipwright/Util/CleanINC.pm
Criterion Covered Total %
statement 33 33 100.0
branch 4 8 50.0
condition 2 4 50.0
subroutine 5 5 100.0
pod n/a
total 44 50 88.0


line stmt bran cond sub pod time code
1             package Shipwright::Util::CleanINC;
2 1     1   1023 use strict;
  1         2  
  1         30  
3 1     1   4 use warnings;
  1         1  
  1         19  
4 1     1   4 use Config;
  1         1  
  1         317  
5              
6             sub import {
7             # It's expensive to do, but we need to find out what's in @INC now that
8             # should be kept (because it was specified on the commandline with -I)
9             # and what we should drop because it's baked into perl as a local lib
10            
11 1     1   8 my %skip_lib_path = map { $_ => 1 } _default_inc();
  5         28  
12 1   50     20 my @explicit_libs = grep {!/inc$/} split( /[:;]/,($ENV{'PERL5LIB'} ||''));
  3         14  
13 1   50     24 my @inc_libs = grep {/inc$/} split( /[:;]/,($ENV{'PERL5LIB'} ||''));
  3         9  
14             # if the libs are explicitly specified, don't pull them from @INC
15 1         5 my @new_base_inc = grep { !$skip_lib_path{$_}++ } ( @explicit_libs, @INC,@inc_libs);
  16         51  
16 1         15 @INC = map { /(.+)/; $1 } grep { defined } (
  10         25  
  10         64  
  12         235  
17             @new_base_inc, $Config::Config{updatesarch},
18             $Config::Config{updateslib}, $Config::Config{archlibexp},
19             $Config::Config{privlibexp}, '.'
20             );
21             }
22              
23              
24              
25             {
26              
27             # This code stolen from
28             # http://cpansearch.perl.org/src/ANDYA/Test-Harness-3.15/lib/Test/Harness.pm
29             # Cache this to avoid repeatedly shelling out to Perl.
30             my @inc;
31              
32             sub _default_inc {
33 1 50   1   4 return @inc if @inc;
34 1         7 local $ENV{PERL5LIB} = '';
35 1         4 local $ENV{PERLLIB} = '';
36 1         5 local $ENV{PERL5DB} = '';
37 1         3 local $ENV{PERL5OPT} = '';
38 1         3 local $ENV{PERL5ENV} = '';
39 1 50       10 local $ENV{PATH} = $1 if $ENV{PATH} =~ /^(.*)$/;
40 1         1 my $perl;
41 1 50       4 $perl = $1 if $^X =~ /^(.*)$/;
42             # Avoid using -l for the benefit of Perl 6
43 1 50       6789 chomp( @inc = map { /^(.*)$/ && $1 } `$perl -e "print join qq[\\n], \@INC, q[]"` );
  5         79  
44 1         35 return @inc;
45             }
46             }
47              
48             1;
49              
50             __END__