blib/lib/FFI/Platypus/ShareConfig.pm untested

filter: Statementstmt 0.0% 0 / 35 Branchbran 0.0% 0 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 59 CC 9 SCAR 34.4
CC
9
Cov
0%
get
56.0
dist_dir
12.0
BEGIN
2.0
CRAP 31.1
1 package FFI::Platypus::ShareConfig;
2  
3 use strict;
4 use warnings;
5 use 5.008004;
6 use File::Spec;
7  
8 our $VERSION = '2.11'; # VERSION
9  
10 sub dist_dir ($)
11 {
12 my($dist_name) = @_;
13  
14 my @pm = split /-/, $dist_name;
15 $pm[-1] .= ".pm";
16  
17 foreach my $inc (@INC)
18 {
19 if(-f File::Spec->catfile($inc, @pm))
20 {
21 my $share = File::Spec->catdir($inc, qw( auto share dist ), $dist_name );
22 if(-d $share)
23 {
24 return File::Spec->rel2abs($share);
25 }
26 last;
27 }
28 }
29 Carp::croak("unable to find dist share directory for $dist_name");
30 }
31  
32 sub get
33 {
34 my(undef, $name) = @_;
35 my $config;
36  
37 unless($config)
38 {
39 my $fn = File::Spec->catfile(dist_dir('FFI-Platypus'), 'config.pl');
40 $fn = File::Spec->rel2abs($fn) unless File::Spec->file_name_is_absolute($fn);
41 local $@;
42 unless($config = do $fn)
43 {
44 die "couldn't parse configuration $fn $@" if $@;
45 die "couldn't do $fn $!" if $!;
46 die "bad or missing config file $fn";
47 };
48 }
49  
50 defined $name ? $config->{$name} : $config;
51 }
52  
53 1;
54  
55 __END__