File Coverage

lib/FFI/Platypus/ShareConfig.pm
Criterion Covered Total %
statement 29 32 90.6
branch 9 16 56.2
condition n/a
subroutine 6 6 100.0
pod 0 2 0.0
total 44 56 78.5


line stmt bran cond sub pod time code
1             package FFI::Platypus::ShareConfig;
2              
3 62     62   1143605 use strict;
  62         123  
  62         2393  
4 62     62   326 use warnings;
  62         178  
  62         3096  
5 62     62   1085 use 5.008004;
  62         210  
6 62     62   503 use File::Spec;
  62         202  
  62         27608  
7              
8             our $VERSION = '2.11'; # VERSION
9              
10             sub dist_dir ($)
11             {
12 587     587 0 1515 my($dist_name) = @_;
13              
14 587         2363 my @pm = split /-/, $dist_name;
15 587         1231 $pm[-1] .= ".pm";
16              
17 587         2628 foreach my $inc (@INC)
18             {
19 1174 100       37426 if(-f File::Spec->catfile($inc, @pm))
20             {
21 587         4454 my $share = File::Spec->catdir($inc, qw( auto share dist ), $dist_name );
22 587 100       9677 if(-d $share)
23             {
24 551         13530 return File::Spec->rel2abs($share);
25             }
26 36         97 last;
27             }
28             }
29 36         17234 Carp::croak("unable to find dist share directory for $dist_name");
30             }
31              
32             sub get
33             {
34 515     515 0 1106167 my(undef, $name) = @_;
35 515         914 my $config;
36              
37 515 50       1410 unless($config)
38             {
39 515         1578 my $fn = File::Spec->catfile(dist_dir('FFI-Platypus'), 'config.pl');
40 515 50       2851 $fn = File::Spec->rel2abs($fn) unless File::Spec->file_name_is_absolute($fn);
41 515         1029 local $@;
42 515 50       203227 unless($config = do $fn)
43             {
44 0 0       0 die "couldn't parse configuration $fn $@" if $@;
45 0 0       0 die "couldn't do $fn $!" if $!;
46 0         0 die "bad or missing config file $fn";
47             };
48             }
49              
50 515 100       9420 defined $name ? $config->{$name} : $config;
51             }
52              
53             1;
54              
55             __END__