blib/lib/ExtUtils/MakeMaker/PPPort.pm

filter: Statementstmt 41.9% 26 / 62 Branchbran 5.0% 1 / 20 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 46.1% 6 / 13 Podpod n/a totaltotal 33.6% 33 / 98 SCAR 41.9
CC
13
Cov
32%
_merge
30.0
_normalize_version
20.0
__ANON__
12.0
CRAP 65.8
↑ Summary Makefile.PL »
1 package ExtUtils::MakeMaker::PPPort;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = '0.01';
7 1 our $AUTHORITY = 'cpan:ATOOMIC';
8  
9 # ABSTRACT: ExtUtils::MakeMaker when using Devel-PPPort
10  
11 1 ▶use ExtUtils::MakeMaker ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 =head1 SYNOPSIS
14  
15 # Makefile.PL
16 use ExtUtils::MakeMaker::PPPort;
17  
18 WriteMakefile(
19 NAME => 'Foo::Bar',
20 ...
21 MIN_PPPORT_VERSION => 3.58, # optional
22 );
23  
24 =head1 DESCRIPTION
25  
26 This module allows you to use an up to date version of ppport.h
27 when using Devel-PPPort.
28  
29 You do not need to ship an old version of `ppport.h` with your codebase.
30  
31  
32 =head1 Migration to ExtUtils::MakeMaker::PPPort
33  
34 You want to remove `ppport.h` from your directory and ignore it in your version control.
35  
36 rm -f ppport.h
37 echo 'ppport.h' >> .gitignore
38  
39 Then you can start using `ExtUtils::MakeMaker::PPPort` instead of `ExtUtils::MakeMaker`.
40  
41 =cut
42  
43 1 ▶use constant LAST_KNOWN_PPPORT_VERSION => 3.58;
Subroutine BEGIN: called CC=1 SCAR=0.0
44  
45 1 our $MIN_PPPORT_VERSION = LAST_KNOWN_PPPORT_VERSION; # last known version
46  
47 sub import {
48 1 ▶ my ( $class, @import_opts ) = @_;
Subroutine import: called CC=2 SCAR=9.2
49 1 ▶ my $orig = 'ExtUtils::MakeMaker'->can('WriteMakefile') or die;
Branch: 1 branch
BranchTrueFalseTotal
my $orig = "ExtUtils::MakeMaker"->can("WriteMakefile") or die 0 1 1
50 1 ExtUtils::MakeMaker->export_to_level( 1, $class, @import_opts );
51  
52 my $writer = sub {
53 0 ▶ my %params = @_;
Subroutine __ANON__: not called CC=3 SCAR=24.8
54  
55 # Do nothing if not called from Makefile.PL
56 #my ($caller, $file, $line) = caller;
57 #(my $root = rel2abs($file)) =~ s/Makefile\.PL$//i or return;
58  
59 0 $MIN_PPPORT_VERSION = delete $params{MIN_PPPORT_VERSION};
60 0 ▶ $MIN_PPPORT_VERSION = LAST_KNOWN_PPPORT_VERSION unless defined $MIN_PPPORT_VERSION;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ExtUtils::MakeMaker::PPPort::MIN_PPPORT_VERSION 0 0 0
61  
62 # Build requires => BUILD_REQUIRES / PREREQ_PM
63 0 ▶ _merge(
Branch: 1 branch
BranchTrueFalseTotal
_eumm('6.56') ? : 0 0 0
64 \%params,
65 { 'Devel-PPPort' => $MIN_PPPORT_VERSION },
66 _eumm('6.56') ? 'BUILD_REQUIRES' : 'PREREQ_PM',
67 );
68  
69 0 $orig->(%params);
70 1 };
71  
72 # redefine the WriteMakefile sub
73 {
74 1 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
75 1 *main::WriteMakefile = *ExtUtils::MakeMaker::WriteMakefile = $writer;
76 }
77 }
78  
79 sub _eumm {
80 0 ▶ my $version = shift;
Subroutine _eumm: not called CC=2 SCAR=17.9
81 0 ▶ eval { ExtUtils::MakeMaker->VERSION($version) } ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
eval { do { 'ExtUtils::MakeMaker'->VERSION($version) } } ? : 0 0 0
82 }
83  
84 sub _merge {
85 0 ▶ my ( $params, $requires, $key ) = @_;
Subroutine _merge: not called CC=5 SCAR=34.0
86  
87 0 ▶ return unless $key;
Branch: 1 branch
BranchTrueFalseTotal
unless $key 0 0 0
88  
89 0 ▶ for ( keys %{ $requires || {} } ) {
Branch: 1 branch
BranchTrueFalseTotal
$requires or {} 0 0 0
90 0 my $version = _normalize_version( $requires->{$_} );
91 0 ▶ next unless defined $version;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $version 0 0 0
92  
93 0 $params->{$key}{$_} = $version;
94 }
95 }
96  
97 sub _normalize_version {
98 0 ▶ my $version = shift;
Subroutine _normalize_version: not called CC=4 SCAR=30.0
99  
100 # shortcuts
101 0 ▶ return unless defined $version;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $version 0 0 0
102 0 ▶ return $version unless $version =~ /\s/;
Branch: 1 branch
BranchTrueFalseTotal
unless $version =~ /\s/ 0 0 0
103  
104 # TODO: better range handling
105 0 $version =~ s/(?:>=|==)\s*//;
106 0 $version =~ s/,.+$//;
107  
108 0 ▶ return $version unless $version =~ /\s/;
Branch: 1 branch
BranchTrueFalseTotal
unless $version =~ /\s/ 0 0 0
109 0 return;
110 }
111  
112 {
113 package # hide from PAUSE
114 MY;
115  
116 sub top_targets {
117  
118 0 ▶ my $content = shift->SUPER::top_targets(@_);
Subroutine top_targets: not called CC=1 SCAR=6.9
119 0 $content =~ s{^(pure_all\s*::\s*)}{${1}ppport }m;
120 0 return $content;
121 }
122  
123 sub clean {
124 0 ▶ my $content = shift->SUPER::clean(@_);
Subroutine clean: not called CC=1 SCAR=6.9
125 0 $content =~ s{^(clean\s*::\s*)}{${1}ppport_clean }m;
126 0 warn $content;
127 0 return $content;
128 }
129  
130 sub postamble {
131 0 ▶ my ( $self, %extra ) = @_;
Subroutine postamble: not called CC=2 SCAR=17.9
132  
133 0 my $post = $self->SUPER::postamble(%extra);
134 0 ▶ my $min_version = $extra{MIN_DEVEL_PPPORT} || 0;
Condition0%0/2
$extra{'MIN_DEVEL_PPPORT'} || 0
l!l
00
MC/DC0%0/1
$extra{'MIN_DEVEL_PPPORT'} || 0
$extra{'MIN_DEVEL_PPPORT'}
Truth table0%0/2
A
A= $extra{'MIN_DEVEL_PPPORT'}
Aresult
11
00
135  
136 0 $post .= <<'POSTAMBLE';
137  
138 # ppport targets
139  
140 .PHONY: ppport ppport_version ppport_clean
141  
142 ppport: ppport_version ppport.h
143 ~TAB~$(NOECHO) $(NOOP)
144  
145 ppport_version:
146 ~TAB~@$(PERL) -I$(INST_LIB) -MDevel::PPPort -e 'die qq[Needs Devel-PPPort version >= ~MIN_DEVEL_PPPORT~ # got $$Devel::PPPort::VERSION] unless $$Devel::PPPort::VERSION >= ~MIN_DEVEL_PPPORT~'
147  
148 ppport_clean:
149 ~TAB~- $(RM_F) ppport.h
150  
151 ppport.h :
152 ~TAB~@$(PERL) -I$(INST_ARCHLIB) -I$(INST_LIB) -I$(PERL_ARCHLIB) -I$(PERL_LIB) -MDevel::PPPort -e'Devel::PPPort::WriteFile'
153  
154 POSTAMBLE
155  
156 0 $post =~ s{~MIN_DEVEL_PPPORT~}{$MIN_PPPORT_VERSION}g;
157 0 $post =~ s{~TAB~}{\t}g;
158  
159 0 return $post;
160 }
161  
162 }
163  
164 1 1;
165  
166 __END__
↑ Summary Makefile.PL »