Carmel/Runtime.pm untested

filter: Statementstmt 0.0% 0 / 31 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 54 CC 5 SCAR 18.2
CC
5
Cov
0%
Carmel::Runtime::FastINC::INC
12.0
bootstrap
6.0
Carmel::Runtime::SiteINC::INC
6.0
CRAP 6.2
1 package Carmel::Runtime;
2 use strict;
3 use Config;
4  
5 sub bootstrap {
6 my($class, $modules, $inc) = @_;
7  
8 my %allows = map { $_ => 1 } qw(
9 Carmel/Preload.pm
10 Carmel/Runner.pm
11 Carmel/Setup.pm
12 Module/Runtime.pm
13 );
14  
15 my %site = map { $_ => 1 } @Config{qw(sitearchexp sitelibexp)};
16  
17 for (@INC) {
18 $_ = Carmel::Runtime::SiteINC->new($_, \%allows)
19 if $site{$_};
20 }
21  
22 unshift @INC,
23 Carmel::Runtime::FastINC->new(%$modules),
24 @{$inc};
25 }
26  
27 package Carmel::Runtime::SiteINC;
28  
29 sub new {
30 my($class, $path, $allows) = @_;
31 bless {
32 path => $path,
33 allows => $allows,
34 }, $class;
35 }
36  
37 sub Carmel::Runtime::SiteINC::INC {
38 my($self, $file) = @_;
39  
40 if ($self->{allows}{$file}) {
41 open my $fh, '<', "$self->{path}/$file"
42 or return;
43 $INC{$file} = "$self->{path}/$file";
44 return $fh;
45 }
46 }
47  
48 package Carmel::Runtime::FastINC;
49  
50 sub new {
51 my($class, %modules) = @_;
52 bless \%modules, $class;
53 }
54  
55 sub Carmel::Runtime::FastINC::INC {
56 my($self, $file) = @_;
57  
58 if ($self->{$file}) {
59 if (open my $fh, '<', $self->{$file}) {
60 $INC{$file} = $self->{$file};
61 return $fh;
62 }
63 warn "Can't locate $file in $self->{$file}: $!";
64 return;
65 }
66 }
67  
68 1;