File Coverage

blib/lib/Perl/Build/Built.pm
Criterion Covered Total %
statement 39 43 90.7
branch 10 16 62.5
condition 2 3 66.6
subroutine 12 13 92.3
pod 7 7 100.0
total 70 82 85.3


line stmt bran cond sub pod time code
1             package Perl::Build::Built;
2              
3 4     4   54831 use strict;
  4         15  
  4         113  
4 4     4   26 use warnings;
  4         7  
  4         102  
5 4     4   477 use utf8;
  4         17  
  4         23  
6              
7 4     4   147 use 5.008001;
  4         13  
8             our $VERSION = '1.33';
9              
10 4     4   28 use Carp ();
  4         7  
  4         89  
11 4     4   405 use File::Spec::Functions qw( catdir catfile );
  4         726  
  4         1804  
12              
13             sub run_env {
14 2     2 1 650 my ( $self, @args ) = @_;
15 2         3 my $config = {};
16 2 50       7 if ( ref $args[0] eq 'HASH' ) {
17 0         0 $config = %{ shift @args };
  0         0  
18             }
19 2 100 66     8 if ( $args[0] and ref $args[0] eq 'CODE' ) {
20 1         2 $config->{code} = shift @args;
21             }
22 2 100       6 if (@args) {
23 1         118 Carp::croak( '->run_env(\%config,\&code)'
24             . ' or ->run_env(\&code)'
25             . ' or ->run_env(\%config)' );
26             }
27 1         4 local $ENV{PATH} = $self->combined_bin_path;
28 1         3 my $combined_man_path = $self->combined_man_path;
29 1 50       3 local $ENV{MANPATH} = $combined_man_path if $combined_man_path;
30 1         5 delete local $ENV{PERL5LIB};
31 1         3 return $config->{code}->();
32             }
33              
34             sub new {
35 1     1 1 541 my ( $self, $args ) = @_;
36 1 50       3 $args = {} unless defined $args;
37 1 50       3 Carp::croak '->new(\%config) required' if not ref $args eq 'HASH';
38             Carp::croak 'installed_path is a mandatory parameter'
39 1 50       2 unless exists $args->{installed_path};
40 1         3 return bless $args, $self;
41             }
42              
43             sub installed_path {
44 0     0 1 0 return $_[0]->{installed_path};
45             }
46              
47             sub bin_path {
48 1     1 1 14 return catdir( $_[0]->{installed_path}, 'bin' );
49             }
50              
51             sub man_path {
52 2     2 1 68 return catdir( $_[0]->{installed_path}, 'man' );
53             }
54              
55             sub combined_bin_path {
56 1     1 1 2 return $_[0]->bin_path . ':' . $ENV{PATH};
57             }
58              
59             sub combined_man_path {
60 2 50   2 1 864 if ( -d $_[0]->man_path ) {
61 0         0 return $_[0]->man_path . ':' . $ENV{MANPATH};
62             }
63 2         9 return $ENV{MANPATH};
64             }
65              
66             1;
67              
68             __END__