blib/lib/ExtUtils/XSpp/Driver.pm

filter: Statementstmt 85.3% 70 / 82 Branchbran 50.0% 16 / 32 Conditioncond 41.1% 7 / 17 MC/DCmcdc 20.0% 2 / 10 Subroutinesub 88.2% 15 / 17 Podpod 0.0% 0 / 10 totaltotal 65.4% 110 / 168 CC 28 SCAR 26.8
CC
28
Cov
71%
_write
34.5
generate
16.7
_emit
6.0
CRAP 14.5
« blib/lib/ExtUtils/XSpp/Node/Function.pm ↑ Summary blib/lib/ExtUtils/XSpp/Cmd.pm »
1 package ExtUtils::XSpp::Driver;
2  
3 21 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 21 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 21 ▶use File::Basename ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 21 ▶use File::Path ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 21 ▶use ExtUtils::XSpp::Parser;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 85 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
12 85 my( $class, %args ) = @_;
13 85 my $self = bless \%args, $class;
14  
15 85 return $self;
16 }
17  
18 85 ▶sub generate {
Subroutine generate: called CC=10 SCAR=28.2
Pod undocumented
19 85 my( $self ) = @_;
20  
21 85 foreach my $typemap ( $self->typemaps ) {
22 1 ExtUtils::XSpp::Parser->new( file => $typemap )->parse;
23 }
24  
25 85 my $parser = ExtUtils::XSpp::Parser->new( file => $self->file,
26 string => $self->string,
27 );
28 85 my $success = $parser->parse;
29 85 ▶ return() if not $success;
Branch: 1 branch
BranchTrueFalseTotal
unless $success 0 85 85
30 85 my $generated = $self->_emit( $parser );
31  
32 85 my $typemap_code = ExtUtils::XSpp::Typemap::get_xs_typemap_code_for_all_typemaps();
33 85 ▶ if (defined $typemap_code && $typemap_code =~ /\S/) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $typemap_code and $typemap_code =~ /\S/) 3 82 85
Condition66%2/3
defined $typemap_code and $typemap_code =~ /\S/
!ll&&!rl&&r
8203
MC/DC50%1/2
defined $typemap_code and $typemap_code =~ /\S/
defined $typemap_code $typemap_code =~ /\S/
Truth table66%2/3
A and B
A= defined $typemap_codeB= $typemap_code =~ /\S/
ABresult
0X0
100
111
34 3 ▶ if (exists $generated->{'-'} and $generated->{'-'} ne '') {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $generated->{'-'} and $generated->{'-'} ne '') { } 3 0 3
elsif (my(@files) = grep((!/^-$/), keys %$generated)) { } 0 0 0
Condition33%1/3
exists $generated->{"-"} and $generated->{"-"} ne ""
!ll&&!rl&&r
003
MC/DC0%0/2
exists $generated->{"-"} and $generated->{"-"} ne ""
exists $generated->{"-"} $generated->{"-"} ne ""
Truth table33%1/3
A and B
A= exists $generated->{"-"}B= $generated->{"-"} ne ""
ABresult
0X0
100
111
35 3 $generated->{'-'} = $typemap_code . $generated->{'-'};
36 }
37 elsif (my @files = grep !/^-$/, keys %$generated) {
38 0 ▶ $generated->{$files[0]} = $typemap_code . ($generated->{$files[0]}||'');
Condition0%0/2
$$generated{$files[0]} || ''
l!l
00
MC/DC0%0/1
$$generated{$files[0]} || ''
$$generated{$files[0]}
Truth table0%0/2
A
A= $$generated{$files[0]}
Aresult
11
00
39 }
40 else {
41 0 ▶ $generated->{'-'} = $typemap_code . ($generated->{'-'}||'');
Condition0%0/2
$generated->{'-'} || ''
l!l
00
MC/DC0%0/1
$generated->{'-'} || ''
$generated->{'-'}
Truth table0%0/2
A
A= $generated->{'-'}
Aresult
11
00
42 }
43 }
44  
45 85 return $generated;
46 }
47  
48 1 ▶sub process {
Subroutine process: called CC=2 SCAR=7.0
Pod undocumented
49 1 my( $self ) = @_;
50  
51 1 my $generated = $self->generate;
52 1 ▶ return () if not $generated;
Branch: 1 branch
BranchTrueFalseTotal
unless $generated 0 1 1
53 1 return $self->_write( $generated );
54 }
55  
56 1 ▶sub _write {
Subroutine _write: called CC=12 SCAR=35.4
57 1 my( $self, $out ) = @_;
58  
59 1 foreach my $f ( keys %$out ) {
60 2 ▶ if( $f eq '-' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f eq '-') { } 1 1 2
61 1 ▶ if( $self->xsubpp ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->xsubpp) { } 0 1 1
62 0 require IPC::Open2;
63  
64 0 ▶ my $cmd = $self->xsubpp . ' ' . ( $self->xsubpp_args || '' )
Condition0%0/2
$self->xsubpp_args || ''
l!l
00
MC/DC0%0/1
$self->xsubpp_args || ''
$self->xsubpp_args
Truth table0%0/2
A
A= $self->xsubpp_args
Aresult
11
00
65 . ' -';
66 0 my $pid = IPC::Open2::open2( '>&STDOUT', my $fh, $cmd );
67  
68 0 ▶ print $fh $$out{$f} or die "Error writing to xsubpp: $!";
Branch: 1 branch
BranchTrueFalseTotal
print $fh $out->{$f} or die "Error writing to xsubpp: $!" 0 0 0
69 0 ▶ close $fh or die "Error writing to xsubpp: $!";
Branch: 1 branch
BranchTrueFalseTotal
close $fh or die "Error writing to xsubpp: $!" 0 0 0
70 0 waitpid( $pid, 0 );
71 0 my $exit_code = $? >> 8;
72  
73 0 ▶ return 0 if $exit_code;
Branch: 1 branch
BranchTrueFalseTotal
if $exit_code 0 0 0
74 } else {
75 1 ▶ print $$out{$f} or die "Error writing output";
Branch: 1 branch
BranchTrueFalseTotal
print $out->{$f} or die "Error writing output" 1 0 1
76 }
77 } else {
78 1 File::Path::mkpath( File::Basename::dirname( $f ) );
79  
80 1 ▶ open my $fh, '>', $f or die "open '$f': $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $f or die "open '${f}': $!" 1 0 1
81 1 binmode $fh;
82 1 ▶ print $fh $$out{$f} or die "Error writing to '$f': $!";
Branch: 1 branch
BranchTrueFalseTotal
print $fh $out->{$f} or die "Error writing to '${f}': $!" 1 0 1
83 1 ▶ close $fh or die "close '$f': $!";
Branch: 1 branch
BranchTrueFalseTotal
close $fh or die "close '${f}': $!" 1 0 1
84 }
85 }
86  
87 1 return 1;
88 }
89  
90 85 ▶sub _emit {
Subroutine _emit: called CC=6 SCAR=17.9
91 85 my( $self, $parser ) = @_;
92 85 my $data = $parser->get_data;
93 85 my %out;
94 85 my $out_file = '-';
95 85 my %state = ( current_module => undef );
96  
97 85 foreach my $plugin ( @{$parser->post_process_plugins} ) {
98 4 my $method = $plugin->{method};
99  
100 4 $plugin->{plugin}->$method( $data );
101 }
102  
103 85 $out{'-'} = preamble();
104 85 foreach my $e ( @$data ) {
105 264 ▶ if( $e->isa( 'ExtUtils::XSpp::Node::Module' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e->isa("ExtUtils::XSpp::Node::Module")) 82 182 264
106 82 $state{current_module} = $e;
107 }
108 264 ▶ if( $e->isa( 'ExtUtils::XSpp::Node::File' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e->isa("ExtUtils::XSpp::Node::File")) 8 256 264
109 8 $out_file = $e->file;
110 8 ▶ $out{$out_file} ||= preamble();
Condition66%2/3
$out{$out_file} ||= preamble()
l!l&&r!l&&!r
440
MC/DC0%0/2
$out{$out_file} ||= preamble()
$out{$out_file} preamble()
Truth table66%2/3
A ||= B
A= $out{$out_file}B= preamble()
ABresult
1X1
011
000
111 }
112 264 $out{$out_file} .= $e->print( \%state );
113 }
114  
115 85 return \%out;
116 }
117  
118 89 ▶sub preamble {
Subroutine preamble: called CC=1 SCAR=0.0
Pod undocumented
119 return <<EOT
120 #include <exception>
121 #undef xsp_constructor_class
122 #define xsp_constructor_class(c) (c)
123  
124  
125 EOT
126 89 }
127  
128 85 ▶sub typemaps { @{$_[0]->{typemaps} || []} }
Subroutine typemaps: called CC=2 SCAR=6.9
Pod undocumented
Condition100%2/2
$_[0]{'typemaps'} || []
l!l
184
MC/DC100%1/1
$_[0]{'typemaps'} || []
$_[0]{'typemaps'}
Truth table100%2/2
A
A= $_[0]{'typemaps'}
Aresult
11
00
129 85 ▶sub file { $_[0]->{file} }
Subroutine file: called CC=1 SCAR=0.0
Pod undocumented
130 85 ▶sub string { $_[0]->{string} }
Subroutine string: called CC=1 SCAR=0.0
Pod undocumented
131 0 ▶sub output { $_[0]->{output} }
Subroutine output: not called CC=1 SCAR=6.9
Pod undocumented
132 1 ▶sub xsubpp { $_[0]->{xsubpp} }
Subroutine xsubpp: called CC=1 SCAR=0.0
Pod undocumented
133 0 ▶sub xsubpp_args { $_[0]->{xsubpp_args} }
Subroutine xsubpp_args: not called CC=1 SCAR=6.9
Pod undocumented
134  
135 21 1;
« blib/lib/ExtUtils/XSpp/Node/Function.pm ↑ Summary blib/lib/ExtUtils/XSpp/Cmd.pm »