| 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
| |||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
defined $typemap_code and $typemap_code =~ /\S/
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/
| |||||||||||||||||||||||||||||||||
| 34 | 3 | ▶ | if (exists $generated->{'-'} and $generated->{'-'} ne '') { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
exists $generated->{"-"} and $generated->{"-"} ne ""
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 ""
| |||||||||||||||||||||||||||||||||
| 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]} || ''
MC/DC0%0/1
$$generated{$files[0]} || ''
$$generated{$files[0]}
Truth table0%0/2
A
A= $$generated{$files[0]}
| |||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||
| 40 | else { | ||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | $generated->{'-'} = $typemap_code . ($generated->{'-'}||''); | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$generated->{'-'} || ''
MC/DC0%0/1
$generated->{'-'} || ''
$generated->{'-'}
Truth table0%0/2
A
A= $generated->{'-'}
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 61 | 1 | ▶ | if( $self->xsubpp ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 62 | 0 | require IPC::Open2; | |||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | my $cmd = $self->xsubpp . ' ' . ( $self->xsubpp_args || '' ) | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->xsubpp_args || ''
MC/DC0%0/1
$self->xsubpp_args || ''
$self->xsubpp_args
Truth table0%0/2
A
A= $self->xsubpp_args
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | close $fh or die "Error writing to xsubpp: $!"; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 70 | 0 | waitpid( $pid, 0 ); | |||||||||||||||||||||||||||||||
| 71 | 0 | my $exit_code = $? >> 8; | |||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | return 0 if $exit_code; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 74 | } else { | ||||||||||||||||||||||||||||||||
| 75 | 1 | ▶ | print $$out{$f} or die "Error writing output"; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 81 | 1 | binmode $fh; | |||||||||||||||||||||||||||||||
| 82 | 1 | ▶ | print $fh $$out{$f} or die "Error writing to '$f': $!"; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 83 | 1 | ▶ | close $fh or die "close '$f': $!"; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 106 | 82 | $state{current_module} = $e; | |||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||
| 108 | 264 | ▶ | if( $e->isa( 'ExtUtils::XSpp::Node::File' ) ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 109 | 8 | $out_file = $e->file; | |||||||||||||||||||||||||||||||
| 110 | 8 | ▶ | $out{$out_file} ||= preamble(); | ||||||||||||||||||||||||||||||
|
Condition66%2/3
$out{$out_file} ||= preamble()
MC/DC0%0/2
$out{$out_file} ||= preamble()
$out{$out_file}
preamble()
Truth table66%2/3
A ||= B
A= $out{$out_file}B= preamble()
| |||||||||||||||||||||||||||||||||
| 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'} || []
MC/DC100%1/1
$_[0]{'typemaps'} || []
$_[0]{'typemaps'}
Truth table100%2/2
A
A= $_[0]{'typemaps'}
| |||||||||||||||||||||||||||||||||
| 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; | |||||||||||||||||||||||||||||||