blib/lib/Module/Build/Pluggable/PDL.pm

filter: Statementstmt 89.1% 74 / 83 Branchbran 66.6% 4 / 6 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 88.2% 15 / 17 Podpod 0.0% 0 / 5 totaltotal 82.7% 96 / 116 CC 7 SCAR 5.8
CC
7
Cov
87%
_convert_to_pm
3.0
HOOK_distdir
3.0
HOOK_configure
2.0
CRAP 1.8
« t/var/Build ↑ Summary t/var/_build/lib/MyModuleBuilder.pm »
1 package Module::Build::Pluggable::PDL;
2  
3 # ABSTRACT: Plugin to Module::Build to build PDL projets
4  
5 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 our $VERSION = '0.23';
8 5 ▶use parent qw(Module::Build::Pluggable::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 5 ▶use PDL::Core::Dev;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use List::MoreUtils qw(first_index);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 5 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 5 ▶use Pod::Perldoc;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 4 ▶sub HOOK_build {
Subroutine HOOK_build: called CC=1 SCAR=0.0
Pod undocumented
16 4 my ($self) = @_;
17  
18 4 $self->add_before_action_modifier( 'distdir', \&HOOK_distdir );
19 4 $self->add_action( 'forcepdlpp', \&ACTION_forcepdlpp );
20  
21 4 $self->process_pd_files;
22  
23 4 return 1;
24 }
25  
26 1 ▶sub HOOK_configure {
Subroutine HOOK_configure: called CC=2 SCAR=7.0
Pod undocumented
27 1 my ($self) = @_;
28  
29 1 $self->_add_include_dirs( PDL::Core::Dev::whereami_any() . '/Core' );
30  
31 $self->_add_extra_linker_flags( $PDL::Config{MALLOCDBG}->{libs} )
32 1 ▶ if $PDL::Config{MALLOCDBG}->{libs};
Branch: 1 branch
BranchTrueFalseTotal
if $PDL::Config{"MALLOCDBG"}{"libs"} 0 1 1
33  
34 1 $self->requires( 'PDL' => '2.006' );
35 1 $self->build_requires( 'PDL' => '2.006' );
36 1 $self->build_requires( 'ExtUtils::CBuilder' => '0.23' );
37  
38 1 return 1;
39 }
40  
41 1 ▶sub _add_include_dirs {
Subroutine _add_include_dirs: called CC=1 SCAR=0.0
42 1 my ( $self, @dirs ) = @_;
43  
44 1 my $include_dirs = $self->builder->include_dirs;
45 1 push @$include_dirs, @dirs;
46 1 $self->builder->include_dirs($include_dirs);
47 }
48  
49 0 ▶sub _add_extra_linker_flags {
Subroutine _add_extra_linker_flags: not called CC=1 SCAR=6.9
50 0 my ( $self, @new_flags ) = @_;
51  
52 0 my $linker_flags = $self->builder->extra_linker_flags;
53 0 push @$linker_flags, @new_flags;
54 0 $self->builder->extra_linker_flags($linker_flags);
55 }
56  
57 # Allow the person installing to force a PDL::PP rebuild
58 0 ▶sub ACTION_forcepdlpp {
Subroutine ACTION_forcepdlpp: not called CC=1 SCAR=6.9
Pod undocumented
59 0 my $self = shift;
60 0 warn "self is " . ref $self;
61 0 $self->log_info("Forcing PDL::PP build\n");
62 0 $self->{FORCE_PDL_PP_BUILD} = 1;
63 0 $self->ACTION_build();
64 }
65  
66 # largely based on process_PL_files and process_xs_files in M::B::Base
67 4 ▶sub process_pd_files {
Subroutine process_pd_files: called CC=2 SCAR=6.9
Pod undocumented
68 4 my $self = shift;
69 4 my $builder = $self->builder;
70  
71 4 warn "# process_pd_files\n";
72  
73 # Get all the .pd files in lib
74 4 my $files = $builder->rscan_dir( 'lib', qr/\.pd$/ );
75  
76 # process each in turn
77 4 for my $file (@$files) {
78 4 my ( $build_prefix, $prefix, $mod_name ) = $self->_filename2info($file);
79  
80 4 $self->_convert_to_pm( $file, $build_prefix, $prefix, $mod_name );
81  
82 4 $self->_add_to_provides( {
83 mod_name => $mod_name,
84 file => $file,
85 version => $builder->dist_version
86 } );
87  
88 4 $builder->add_to_cleanup( "$build_prefix.pm", "$build_prefix.xs" );
89  
90 # Add the newly created .pm and .xs files to the list of such files?
91 # No, because the current build process looks for all such files and
92 # processes them, and it doesn't create that list until it's actually
93 # processing the .pm and .xs files.
94 }
95 }
96  
97 4 ▶sub _convert_to_pm {
Subroutine _convert_to_pm: called CC=3 SCAR=11.0
98 4 my ( $self, $file, $build_prefix, $prefix, $mod_name ) = @_;
99 4 my $builder = $self->builder;
100  
101 # see sub run_perl_command (yet undocumented)
102 # PDL::PP's import argument are, in order:
103 # Module name -> for example, PDL::Graphics::PLplot
104 # Package name -> used in package line of the .pm file; for our purposes,
105 # this is identical to Module name.
106 # Prefix -> the extensionless file name, PDL/Graphics/PLplot
107 # .pm and .xs extensions will be added to this when the files are
108 # produced, so this should include a lib/ prefix
109 # Callpack -> an optional argument used for the XS PACKAGE keyword;
110 # if left blank, it will be identical to the module name
111 4 my $PDL_arg = "-MPDL::PP qw[$mod_name $mod_name $build_prefix]";
112  
113 # Both $self->up_to_date and $self->run_perl_command are undocumented
114 # so they could change in the future:
115 4 my $up_to_date =
116 $builder->up_to_date( $file, [ "$build_prefix.pm", "$build_prefix.xs" ] );
117  
118 4 ▶ if ( $builder->{FORCE_PDL_PP_BUILD} or not $up_to_date ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($builder->{"FORCE_PDL_PP_BUILD"} or not $up_to_date) 1 3 4
Condition66%2/3
$builder->{"FORCE_PDL_PP_BUILD"} or not $up_to_date
l!l&&r!l&&!r
013
MC/DC50%1/2
$builder->{"FORCE_PDL_PP_BUILD"} or not $up_to_date
$builder->{"FORCE_PDL_PP_BUILD"} not $up_to_date
Truth table66%2/3
A or not(B)
A= $builder->{"FORCE_PDL_PP_BUILD"}B= not $up_to_date
ABresult
1X1
011
000
119 1 $builder->run_perl_command( [ $PDL_arg, $file ] );
120 }
121 }
122  
123 4 ▶sub _add_to_provides {
Subroutine _add_to_provides: called CC=1 SCAR=0.0
124 4 my ( $self, $info ) = @_;
125  
126 4 warn "# provides....$info->{file}\n";
127 $self->builder->meta_merge(
128 'provides',
129 {
130 $info->{mod_name} =>
131 { file => $info->{file}, version => $info->{version} },
132 4 } );
133 }
134  
135 4 ▶sub _filename2info {
Subroutine _filename2info: called CC=1 SCAR=0.0
136 4 my ( $self, $file ) = @_;
137  
138 # Remove the .pd extension to get the build file prefix, which
139 # says where the .xs and .pm files should be placed when we run
140 # PDL::PP on the .pd file
141 4 ( my $build_prefix = $file ) =~ s/\.[^.]+$//;
142  
143 # Figure out the file's lib-less prefix, which tells perl where it
144 # will be installed _within_ lib:
145 4 ( my $prefix = $build_prefix ) =~ s|.*lib/||;
146  
147 # Build the module name (Surely there's a M::B function for this?)
148 4 ( my $mod_name = $prefix ) =~ s|/|::|g;
149  
150 4 return ( $build_prefix, $prefix, $mod_name );
151 }
152  
153 1 ▶sub HOOK_distdir {
Subroutine HOOK_distdir: called CC=3 SCAR=11.0
Pod undocumented
154 1 my ($self) = @_; # $self is MyModuleBuilder (not MBP::PDL)
155  
156 1 my $files = $self->rscan_dir( 'lib', qr/\.pd$/ );
157 1 for my $file (@$files) {
158 1 ( my $build_prefix = $file ) =~ s{\.pd$}{};
159 1 ( my $prefix = $build_prefix ) =~ s{/?lib/}{};
160 1 ( my $package = $build_prefix ) =~ s{/}{::}g;
161  
162 # Process .pd into a .pm file with embedded POD
163 # perl -MPDL::PP=PDL::Opt::QP,PDL::Opt::QP,lib/PDL/Opt/QP lib/PDL/Opt/QP.pd
164 my $cmd = sprintf "%s -MPDL::PP=%s,%s,%s %s",
165 1 $Config{perlpath}, $package, $package, $build_prefix, $file;
166 1 ▶ $self->do_system($cmd) or die "Error running PDL::PP : $@";
Branch: 1 branch
BranchTrueFalseTotal
$self->do_system($cmd) or die "Error running PDL::PP : $@" 1 0 1
167  
168 # Process .pm into .pod using perldoc as an object
169 # && perldoc -u lib/PDL/Opt/QP.pm > lib/PDL/Opt/QP.pod
170 1 my $poddoc =
171 Pod::Perldoc->new(
172 args => ['-u', '-d', "$build_prefix.pod", "$build_prefix.pm"] );
173 1 $poddoc->process();
174  
175 1 $self->add_to_cleanup("$build_prefix.pod");
176 }
177  
178 1 return 1;
179 }
180  
181 5 1;
182  
183 __END__
« t/var/Build ↑ Summary t/var/_build/lib/MyModuleBuilder.pm »