File Coverage

blib/lib/Test/Alien/CPP.pm
Criterion Covered Total %
statement 41 43 95.3
branch 9 18 50.0
condition 1 3 33.3
subroutine 8 8 100.0
pod 1 1 100.0
total 60 73 82.1


line stmt bran cond sub pod time code
1             package Test::Alien::CPP;
2              
3 2     2   427965 use strict;
  2         5  
  2         68  
4 2     2   15 use warnings;
  2         3  
  2         85  
5 2     2   36 use 5.008001;
  2         6  
6 2     2   993 use ExtUtils::CppGuess;
  2         72614  
  2         102  
7 2     2   1235 use Test::Alien 1.88 ();
  2         92359  
  2         91  
8 2     2   22 use Text::ParseWords qw( shellwords );
  2         4  
  2         155  
9 2     2   13 use base qw( Exporter );
  2         9  
  2         1444  
10              
11             # ABSTRACT: Testing tools for Alien modules for projects that use C++
12             our $VERSION = '1.04'; # VERSION
13              
14              
15             our @EXPORT = @Test::Alien::EXPORT;
16              
17             Test::Alien->import(grep !/^xs_ok$/, @EXPORT);
18              
19              
20             sub xs_ok
21             {
22 1     1 1 275406 my $cb;
23 1 50 33     11 $cb = pop if defined $_[-1] && ref $_[-1] eq 'CODE';
24 1         4 my($xs, $message) = @_;
25              
26 1 50       4 if(ref($xs))
27             {
28 1         6 my %xs = %$xs;
29 1         4 $xs = \%xs;
30             }
31             else
32             {
33 0 0       0 $xs = { xs => $xs } unless ref $xs;
34             }
35 1         4 $xs->{pxs}->{'C++'} = 1;
36 1         4 $xs->{c_ext} = 'cpp';
37              
38 1         6 my %stage = (
39             extra_compiler_flags => 'cbuilder_compile',
40             extra_linker_flags => 'cbuilder_link',
41             );
42              
43 1         11 my %cppguess = ExtUtils::CppGuess->new->module_build_options;
44 1         148322 foreach my $name (qw( extra_compiler_flags extra_linker_flags ))
45             {
46 2 50       17 next unless defined $cppguess{$name};
47 2 50       62 my @new = ref($cppguess{$name}) eq 'ARRAY' ? @{ delete $cppguess{$name} } : shellwords(delete $cppguess{$name});
  0         0  
48 2         420 my @old = do {
49 2         30 my $value = delete $xs->{$stage{$name}}->{$name};
50 2 50       20 !defined $value ? ()
    100          
51             : ref($value) eq 'ARRAY' ? @$value
52             : shellwords($value);
53             };
54 2         72 $xs->{$stage{$name}}->{$name} = [@old, @new];
55             }
56              
57 1 50       25 $xs->{cbuilder_config} = delete $cppguess{config} if defined $cppguess{config};
58 1         8 $xs->{cbuilder_check} = 'have_cplusplus';
59              
60 1         4 warn "extra Module::Build option: $_" for keys %cppguess;
61              
62 1 50       37 $cb ? Test::Alien::xs_ok($xs, $message, $cb) : Test::Alien::xs_ok($xs, $message);
63             }
64              
65             1;
66              
67             __END__