blib/lib/CPAN/FindDependencies/MakeMaker.pm

filter: Statementstmt 90.7% 69 / 76 Branchbran 55.5% 10 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 13 / 13 Podpod 100% 1 / 1 totaltotal 86.1% 93 / 108 CC 11 SCAR 12.3
CC
11
Cov
84%
getreqs_from_mm
6.5
_parse_makefile
5.1
__ANON__
2.0
CRAP 3.4
« blib/lib/CPAN/FindDependencies.pm ↑ Summary blib/script/cpandeps-diff »
1 package CPAN::FindDependencies::MakeMaker;
2  
3 34 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 34 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 34 ▶use vars qw($VERSION @ISA @EXPORT_OK);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 34 ▶use File::Temp qw(tempdir);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 34 ▶use Cwd qw(getcwd abs_path);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 34 ▶use Capture::Tiny qw(capture);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 34 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 34 require Exporter;
13 34 @ISA = qw(Exporter);
14 34 @EXPORT_OK = qw( getreqs_from_mm );
15  
16 34 $VERSION = '1.0';
17  
18 =head1 NAME
19  
20 CPAN::FindDependencies::MakeMaker - retrieve dependencies specified in Makefile.PL's
21  
22 =head1 SYNOPSIS
23  
24 Dependencies are also specified in Makefile.PL files used with the ExtUtils::MakeMaker module.
25  
26 =head1 FUNCTIONS
27  
28 =over
29  
30 =item getreqs_from_mm
31  
32 Expects the contents of a Makefile.PL as a string.
33  
34 Returns a hash reference of the form:
35  
36 {
37 Module::Name => 0.1,
38 ...
39 Last::Module => 9.0,
40 }
41  
42 =back
43  
44 =cut
45  
46 9 ▶sub getreqs_from_mm {
Subroutine getreqs_from_mm: called CC=6 SCAR=18.8
Pod documented
47 9 my $MakefilePL = shift;
48 9 local $/ = undef;
49  
50 9 my $cwd = getcwd();
51 9 my $tempdir = tempdir(CLEANUP => 1);
52 9 chdir($tempdir);
53  
54 # write Makefile.PL ...
55 9 ▶ open(my $MKFH, '>Makefile.PL') || die("Can't write Makefile.PL in $tempdir\n");
Branch: 1 branch
BranchTrueFalseTotal
open my $MKFH, ">Makefile.PL" or die "Can't write Makefile.PL in $tempdir\n" 9 0 9
56 9 print $MKFH $MakefilePL;
57 9 close($MKFH);
58  
59 9 ▶ if ($^O eq 'MSWin32') {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq 'MSWin32') { } 0 9 9
60 # NB *not* for Cygwin, hence not Devel::CheckOS MicrosoftWindows
61 0 require Win32::Job;
62 0 my $job = Win32::Job->new;
63 0 $job->spawn($Config{perlpath}, "perl Makefile.PL", {stdin => 'NUL', 'stdout'=>'stdout.log','stderr'=>'stderr.log'});
64 0 ▶ unless ($job->run(10)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($job->run(10)) 0 0 0
65 0 chdir($cwd);
66 0 return "Makefile.PL didn't finish in a reasonable time\n";
67 }
68 } else {
69 # execute, suppressing noise ...
70 9 ▶ eval { capture {
Subroutine __ANON__: called CC=2 SCAR=6.9
71 9 ▶ if(my $pid = fork()) { # parent
Branch: 1 branch
BranchTrueFalseTotal
if (my $pid = fork) { } 5 4 9
72 1 ▶ local $SIG{ALRM} = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
73 1 kill 9, $pid; # quit RIGHT FUCKING NOW
74 1 die("Makefile.PL didn't finish in a reasonable time\n");
75 5 };
76 5 alarm(10);
77 5 waitpid($pid, 0);
78 4 alarm(0);
79 } else {
80 4 exec($Config{perlpath}, 'Makefile.PL');
81 }
82 9 } };
83 5 ▶ if($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 1 4 5
84 1 chdir($cwd);
85 1 return $@;
86 }
87 }
88  
89 # read Makefile
90 4 ▶ open($MKFH, 'Makefile') || warn "Can't read Makefile\n";
Branch: 1 branch
BranchTrueFalseTotal
open $MKFH, "Makefile" or warn "Can't read Makefile\n" 4 0 4
91 4 my $makefile_str = <$MKFH>;
92 4 close($MKFH);
93 4 chdir($cwd);
94  
95 4 return _parse_makefile( $makefile_str );
96 }
97  
98 4 ▶sub _parse_makefile {
Subroutine _parse_makefile: called CC=5 SCAR=16.4
99 4 my $makefile_str = shift;
100 4 ▶ return "Unable to get Makefile" unless defined $makefile_str;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $makefile_str 0 4 4
101 4 my %required_version_for;
102 4 my @prereq_lines = grep { /^\s*#.*PREREQ/ } split /\n/, $makefile_str;
103 4 for my $line ( @prereq_lines ) {
104 4 ▶ if ( $line =~ /PREREQ_PM \s+ => \s+ \{ \s* (.*) \s* \} $/x ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /PREREQ_PM \s+ => \s+ \{ \s* (.*) \s* \} $/x) { } 4 0 4
105 34 ▶ no strict 'subs';
Subroutine BEGIN: called CC=1 SCAR=0.0
106 4 %required_version_for = eval "( $1 )";
107 4 ▶ return "Failed to eval $1: $@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 4 4
108 34 ▶ use strict 'subs';
Subroutine BEGIN: called CC=1 SCAR=0.0
109 } else {
110 0 return "Unrecognized PREREQ line in Makefile.PL:\n$line";
111 }
112 }
113 4 return \%required_version_for;
114 }
115  
116 =head1 SECURITY
117  
118 This module assumes that its input is trustworthy and can be safely
119 executed. The only protection in place is that a vague attempt is made
120 to catch a Makefile.PL that just sits there doing nothing - either if it's
121 in a loop, or sitting at a prompt. But even that can be defeated by
122 an especially naughty person.
123  
124 =head1 BUGS/LIMITATIONS
125  
126 Makefile.PLs that have external dependencies/calls that can fatally die will
127 not be able to be successfully parsed and then scanned for dependencies, e.g.
128 libwww-perl.5808.
129  
130 =head1 SOURCE CODE REPOSITORY
131  
132 L<git://github.com/DrHyde/perl-modules-CPAN-FindDependencies.git>
133  
134 =head1 SEE ALSO
135  
136 L<CPAN::FindDepdendencies>
137  
138 L<CPAN>
139  
140 L<http://deps.cpantesters.org>
141  
142 =head1 AUTHOR, LICENCE and COPYRIGHT
143  
144 Copyright 2009 - 2026 David Cantrell E<lt>F<david@cantrell.org.uk>E<gt> based largely
145 on code by Ian Tegebo (see L<http://rt.cpan.org/Public/Bug/Display.html?id=34814>)
146  
147 This software is free-as-in-speech software, and may be used,
148 distributed, and modified under the terms of either the GNU
149 General Public Licence version 2 or the Artistic Licence. It's
150 up to you which one you use. The full text of the licences can
151 be found in the files GPL2.txt and ARTISTIC.txt, respectively.
152  
153 =head1 CONSPIRACY
154  
155 This module is also free-as-in-mason software.
156  
157 =cut
158  
159 34 1;
« blib/lib/CPAN/FindDependencies.pm ↑ Summary blib/script/cpandeps-diff »