File Coverage

lib/FFI/Build/Plugin.pm
Criterion Covered Total %
statement 37 38 97.3
branch 6 8 75.0
condition 1 3 33.3
subroutine 6 6 100.0
pod 0 2 0.0
total 50 57 87.7


line stmt bran cond sub pod time code
1             package FFI::Build::Plugin;
2              
3 11     11   225760 use strict;
  11         21  
  11         369  
4 11     11   43 use warnings;
  11         57  
  11         561  
5 11     11   4958 use autodie;
  11         201174  
  11         62  
6 11     11   86171 use File::Spec::Functions qw( catdir catfile );
  11         9980  
  11         9681  
7              
8             # ABSTRACT: Platform and local customizations of FFI::Build
9             our $VERSION = '2.11'; # VERSION
10              
11              
12             sub new
13             {
14 13     13 0 324759 my($class) = @_;
15              
16 13         23 my %plugins;
17              
18 13         40 foreach my $inc (@INC)
19             {
20             # CAVEAT: won't work with an @INC hook. Plugins must be in a "real" directory.
21 98         385 my $path = catdir($inc, 'FFI', 'Build', 'Plugin');
22 98 100       2024 next unless -d $path;
23 2         3 my $dh;
24 2         9 opendir $dh, $path;
25 2         742 my @list = readdir $dh;
26 2         8 closedir $dh;
27              
28 2         474 foreach my $name (map { my $x = $_; $x =~ s/\.pm$//; $x } grep /\.pm$/, @list)
  4         9  
  4         8  
  4         9  
29             {
30 4 50       10 next if defined $plugins{$name};
31 4         19 my $pm = catfile('FFI', 'Build', 'Plugin', "$name.pm");
32 4         1159 require $pm;
33 4         10 my $class = "FFI::Build::Plugin::$name";
34 4 50 33     54 if($class->can("api_version") && $class->api_version == 0)
35             {
36 4         11 $plugins{$name} = $class->new;
37             }
38             else
39             {
40 0         0 warn "$class is not the correct api version. You may need to upgrade the plugin, platypus or uninstall the plugin";
41             }
42             }
43             }
44              
45 13         82 bless \%plugins, $class;
46             }
47              
48             sub call
49             {
50 243     243 0 3031 my($self, $method, @args) = @_;
51              
52 243         1528 foreach my $name (sort keys %$self)
53             {
54 2         3 my $plugin = $self->{$name};
55 2 100       10 $plugin->$method(@args) if $plugin->can($method);
56             }
57              
58 243         1140 1;
59             }
60              
61             1;
62              
63             __END__