File Coverage

blib/lib/Alien/Base/Wrapper.pm
Criterion Covered Total %
statement 51 51 100.0
branch 7 10 70.0
condition 4 6 66.6
subroutine 10 10 100.0
pod 2 2 100.0
total 74 79 93.6


line stmt bran cond sub pod time code
1             package Alien::Base::Wrapper;
2              
3 2     2   176340 use strict;
  2         4  
  2         63  
4 2     2   9 use warnings;
  2         3  
  2         55  
5 2     2   56 use 5.008001;
  2         6  
6 2     2   17 use Config;
  2         3  
  2         88  
7 2     2   893 use Text::ParseWords qw( shellwords );
  2         2257  
  2         455  
8              
9             # ABSTRACT: Compiler and linker wrapper for late optional Alien utilization
10             our $VERSION = '0.03'; # VERSION
11              
12              
13             my @cflags_I;
14             my @cflags;
15             my @ldflags_L;
16             my @libs;
17              
18             sub _reset
19             {
20 3     3   14517 @cflags_I = ();
21 3         9 @cflags = ();
22 3         6 @ldflags_L = ();
23 3         8 @libs = ();
24             }
25              
26              
27             sub cc
28             {
29             my @command = (
30             $Config{cc},
31 3     3 1 578 @cflags_I,
32             @cflags,
33             @ARGV,
34             );
35 3 50       99 print "@command\n" unless $ENV{ALIEN_BASE_WRAPPER_QUIET};
36 3         13 exec @command;
37             }
38              
39              
40             sub ld
41             {
42             my @command = (
43             $Config{ld},
44 3     3 1 3604 @ldflags_L,
45             @ARGV,
46             @libs,
47             );
48 3 50       13 print "@command\n" unless $ENV{ALIEN_BASE_WRAPPER_QUIET};
49 3         11 exec @command;
50             }
51              
52             sub import
53             {
54 5     5   154 my(undef, @aliens) = @_;
55             {
56 5         10 my $caller = caller;
  5         13  
57 2     2   10 no strict 'refs';
  2         2  
  2         510  
58 5         10 *{"${caller}::cc"} = \&cc;
  5         31  
59 5         11 *{"${caller}::ld"} = \&ld;
  5         31  
60             }
61            
62 5         26 foreach my $alien (@aliens)
63             {
64 5 100       36 $alien = "Alien::$alien" unless $alien =~ /::/;
65 5         9 my $alien_pm = $alien . '.pm';
66 5         22 $alien_pm =~ s/::/\//g;
67 5 50 33     7 require $alien_pm unless eval { $alien->can('cflags') } && eval { $alien->can('libs') };
  5         66  
  5         33  
68 5         10 my $cflags;
69             my $libs;
70 5 100 100     14 if($alien->install_type eq 'share' && $alien->can('cflags_static'))
71             {
72 1         15 $cflags = $alien->cflags_static;
73 1         8 $libs = $alien->libs_static;
74             }
75             else
76             {
77 4         40 $cflags = $alien->cflags;
78 4         14 $libs = $alien->libs;
79             }
80            
81 5         25 @cflags_I = grep /^-I/, shellwords $cflags;
82 5         601 @cflags = grep !/^-I/, shellwords $cflags;
83            
84 5         351 @ldflags_L = grep /^-L/, shellwords $libs;
85 5         295 @libs = grep !/^-L/, shellwords $libs;
86             }
87             }
88              
89             1;
90              
91             __END__