lib/ExtUtils/Command/MM.pm

filter: Statementstmt 34.0% 31 / 91 Branchbran 22.2% 8 / 36 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 27.2% 3 / 11 Podpod 100% 7 / 7 totaltotal 30.8% 49 / 159 CC 20 SCAR 38.8
CC
20
Cov
29%
pod2man
91.7
perllocal_install
12.0
warn_if_old_packlist
6.0
CRAP 48.5
« lib/ExtUtils/MakeMaker.pm ↑ Summary lib/ExtUtils/MM_Any.pm »
1 package ExtUtils::Command::MM;
2  
3 2 require 5.006;
4  
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 require Exporter;
9 2 our @ISA = qw(Exporter);
10  
11 2 our @EXPORT = qw(test_harness pod2man perllocal_install uninstall
12 warn_if_old_packlist test_s cp_nonempty);
13 2 our $VERSION = '7.13_01';
14 2 $VERSION = eval $VERSION;
15  
16 2 my $Is_VMS = $^O eq 'VMS';
17  
18 2 ▶eval { require Time::HiRes; die unless Time::HiRes->can("stat"); };
Branch: 1 branch
BranchTrueFalseTotal
unless "Time::HiRes"->can("stat") 0 2 2
19 *mtime = $@ ?
20 0 ▶ sub { [ stat($_[0])]->[9] } :
Subroutine __ANON__: not called CC=1 SCAR=6.9
21 0 ▶ sub { [Time::HiRes::stat($_[0])]->[9] } ;
Subroutine __ANON__: not called CC=1 SCAR=1.2
Branch: 1 branch
BranchTrueFalseTotal
$@ ? : 0 2 2
22  
23 =head1 NAME
24  
25 ExtUtils::Command::MM - Commands for the MM's to use in Makefiles
26  
27 =head1 SYNOPSIS
28  
29 perl "-MExtUtils::Command::MM" -e "function" "--" arguments...
30  
31  
32 =head1 DESCRIPTION
33  
34 B<FOR INTERNAL USE ONLY!> The interface is not stable.
35  
36 ExtUtils::Command::MM encapsulates code which would otherwise have to
37 be done with large "one" liners.
38  
39 Any $(FOO) used in the examples are make variables, not Perl.
40  
41 =over 4
42  
43 =item B<test_harness>
44  
45 test_harness($verbose, @test_libs);
46  
47 Runs the tests on @ARGV via Test::Harness passing through the $verbose
48 flag. Any @test_libs will be unshifted onto the test's @INC.
49  
50 @test_libs are run in alphabetical order.
51  
52 =cut
53  
54 sub test_harness {
55 0 ▶ require Test::Harness;
Subroutine test_harness: not called CC=1 SCAR=6.9
Pod documented
56 0 require File::Spec;
57  
58 0 $Test::Harness::verbose = shift;
59  
60 # Because Windows doesn't do this for us and listing all the *.t files
61 # out on the command line can blow over its exec limit.
62 0 require ExtUtils::Command;
63 0 my @argv = ExtUtils::Command::expand_wildcards(@ARGV);
64  
65 0 local @INC = @INC;
66 0 unshift @INC, map { File::Spec->rel2abs($_) } @_;
67 0 Test::Harness::runtests(sort { lc $a cmp lc $b } @argv);
68 }
69  
70  
71  
72 =item B<pod2man>
73  
74 pod2man( '--option=value',
75 $podfile1 => $manpage1,
76 $podfile2 => $manpage2,
77 ...
78 );
79  
80 # or args on @ARGV
81  
82 pod2man() is a function performing most of the duties of the pod2man
83 program. Its arguments are exactly the same as pod2man as of 5.8.0
84 with the addition of:
85  
86 --perm_rw octal permission to set the resulting manpage to
87  
88 And the removal of:
89  
90 --verbose/-v
91 --help/-h
92  
93 If no arguments are given to pod2man it will read from @ARGV.
94  
95 If Pod::Man is unavailable, this function will warn and return undef.
96  
97 =cut
98  
99 sub pod2man {
100 2 ▶ local @ARGV = @_ ? @_ : @ARGV;
Subroutine pod2man: called CC=15 SCAR=45.2
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 1 1 2
101  
102 {
103 2 local $@;
104 2 ▶ if( !eval { require Pod::Man } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { require Pod::Man } }) 1 1 2
105 1 warn "Pod::Man is not available: $@".
106 "Man pages will not be generated during this install.\n";
107 1 return 0;
108 }
109 }
110 1 require Getopt::Long;
111  
112 # We will cheat and just use Getopt::Long. We fool it by putting
113 # our arguments into @ARGV. Should be safe.
114 1 my %options = ();
115 1 Getopt::Long::config ('bundling_override');
116 1 Getopt::Long::GetOptions (\%options,
117 'section|s=s', 'release|r=s', 'center|c=s',
118 'date|d=s', 'fixed=s', 'fixedbold=s', 'fixeditalic=s',
119 'fixedbolditalic=s', 'official|o', 'quotes|q=s', 'lax|l',
120 'name|n=s', 'perm_rw=i', 'utf8|u'
121 );
122 1 ▶ delete $options{utf8} unless $Pod::Man::VERSION >= 2.17;
Branch: 1 branch
BranchTrueFalseTotal
unless $Pod::Man::VERSION >= "2.17" 0 1 1
123  
124 # If there's no files, don't bother going further.
125 1 ▶ return 0 unless @ARGV;
Branch: 1 branch
BranchTrueFalseTotal
unless @ARGV 1 0 1
126  
127 # Official sets --center, but don't override things explicitly set.
128 0 ▶ if ($options{official} && !defined $options{center}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{"official"} and not defined $options{"center"}) 0 0 0
Condition0%0/3
$options{"official"} and not defined $options{"center"}
!ll&&!rl&&r
000
MC/DC0%0/2
$options{"official"} and not defined $options{"center"}
$options{"official"} not defined $options{"center"}
Truth table0%0/3
A and not(B)
A= $options{"official"}B= not defined $options{"center"}
ABresult
0X0
100
111
129 0 $options{center} = q[Perl Programmer's Reference Guide];
130 }
131  
132 # This isn't a valid Pod::Man option and is only accepted for backwards
133 # compatibility.
134 0 delete $options{lax};
135 0 my $count = scalar @ARGV / 2;
136 0 ▶ my $plural = $count == 1 ? 'document' : 'documents';
Branch: 1 branch
BranchTrueFalseTotal
$count == 1 ? : 0 0 0
137 0 print "Manifying $count pod $plural\n";
138  
139 0 ▶ do {{ # so 'next' works
Branch: 1 branch
BranchTrueFalseTotal
@ARGV and do { do { { () = splice(@ARGV, 0, 2); next if -e $man and mtime($man) > mtime($pod) and mtime($man) > mtime("Makefile"); my $parser = "Pod::Man"->new(%options); $parser->parse_from_file($pod, $man) or do { warn "Could not install $man\n"; next }; if (exists $options{"perm_rw"}) { chmod oct $options{"perm_rw"}, $man or do { warn qq[chmod $options{"perm_rw"} ${man}: $!\n]; next }; } ; } } } 0 0 0
140 0 my ($pod, $man) = splice(@ARGV, 0, 2);
141  
142 0 ▶ next if ((-e $man) &&
Branch: 1 branch
BranchTrueFalseTotal
if -e $man and mtime($man) > mtime($pod) and mtime($man) > mtime("Makefile") 0 0 0
Condition0%0/6
-e $man and mtime($man) > mtime($pod) and mtime($man) > mtime("Makefile")
!ll&&!rl&&r
000
-e $man and mtime($man) > mtime($pod)
!ll&&!rl&&r
000
MC/DC0%0/3
-e $man and mtime($man) > mtime($pod) and mtime($man) > mtime("Makefile")
-e $man mtime($man) > mtime($pod) mtime($man) > mtime("Makefile")
Truth table0%0/4
A and B and C
A= -e $manB= mtime($man) > mtime($pod)C= mtime($man) > mtime("Makefile")
ABCresult
0XX0
10X0
1100
1111
143 (mtime($man) > mtime($pod)) &&
144 (mtime($man) > mtime("Makefile")));
145  
146 0 my $parser = Pod::Man->new(%options);
147 $parser->parse_from_file($pod, $man)
148 0 ▶ or do { warn("Could not install $man\n"); next };
Branch: 1 branch
BranchTrueFalseTotal
$parser->parse_from_file($pod, $man) or do { warn "Could not install $man\n"; next } 0 0 0
149  
150 0 ▶ if (exists $options{perm_rw}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $options{"perm_rw"}) 0 0 0
151 chmod(oct($options{perm_rw}), $man)
152 0 ▶ or do { warn("chmod $options{perm_rw} $man: $!\n"); next };
Branch: 1 branch
BranchTrueFalseTotal
chmod oct $options{"perm_rw"}, $man or do { warn qq[chmod $options{"perm_rw"} ${man}: $!\n]; next } 0 0 0
153 }
154 }} while @ARGV;
155  
156 0 return 1;
157 }
158  
159  
160 =item B<warn_if_old_packlist>
161  
162 perl "-MExtUtils::Command::MM" -e warn_if_old_packlist <somefile>
163  
164 Displays a warning that an old packlist file was found. Reads the
165 filename from @ARGV.
166  
167 =cut
168  
169 sub warn_if_old_packlist {
170 0 ▶ my $packlist = $ARGV[0];
Subroutine warn_if_old_packlist: not called CC=2 SCAR=17.9
Pod documented
171  
172 0 ▶ return unless -f $packlist;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $packlist 0 0 0
173 0 print <<"PACKLIST_WARNING";
174 WARNING: I have found an old package in
175 $packlist.
176 Please make sure the two installations are not conflicting
177 PACKLIST_WARNING
178  
179 }
180  
181  
182 =item B<perllocal_install>
183  
184 perl "-MExtUtils::Command::MM" -e perllocal_install
185 <type> <module name> <key> <value> ...
186  
187 # VMS only, key|value pairs come on STDIN
188 perl "-MExtUtils::Command::MM" -e perllocal_install
189 <type> <module name> < <key>|<value> ...
190  
191 Prints a fragment of POD suitable for appending to perllocal.pod.
192 Arguments are read from @ARGV.
193  
194 'type' is the type of what you're installing. Usually 'Module'.
195  
196 'module name' is simply the name of your module. (Foo::Bar)
197  
198 Key/value pairs are extra information about the module. Fields include:
199  
200 installed into which directory your module was out into
201 LINKTYPE dynamic or static linking
202 VERSION module version number
203 EXE_FILES any executables installed in a space seperated
204 list
205  
206 =cut
207  
208 sub perllocal_install {
209 0 ▶ my($type, $name) = splice(@ARGV, 0, 2);
Subroutine perllocal_install: not called CC=3 SCAR=24.8
Pod documented
210  
211 # VMS feeds args as a piped file on STDIN since it usually can't
212 # fit all the args on a single command line.
213 0 ▶ my @mod_info = $Is_VMS ? split /\|/, <STDIN>
Branch: 1 branch
BranchTrueFalseTotal
$Is_VMS ? : 0 0 0
214 : @ARGV;
215  
216 0 my $pod;
217 0 $pod = sprintf <<'POD', scalar(localtime), $type, $name;
218 =head2 %s: C<%s> L<%3$s|%3$s>
219  
220 =over 4
221  
222 POD
223  
224 0 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
@mod_info and do { do { () = splice(@mod_info, 0, 2); $pod .= " =item *\n\n C<${key}: $val>\n\n" } } 0 0 0
225 0 my($key, $val) = splice(@mod_info, 0, 2);
226  
227 0 $pod .= <<POD
228 =item *
229  
230 C<$key: $val>
231  
232 POD
233  
234 } while(@mod_info);
235  
236 0 $pod .= "=back\n\n";
237 0 $pod =~ s/^ //mg;
238 0 print $pod;
239  
240 0 return 1;
241 }
242  
243 =item B<uninstall>
244  
245 perl "-MExtUtils::Command::MM" -e uninstall <packlist>
246  
247 A wrapper around ExtUtils::Install::uninstall(). Warns that
248 uninstallation is deprecated and doesn't actually perform the
249 uninstallation.
250  
251 =cut
252  
253 sub uninstall {
254 0 ▶ my($packlist) = shift @ARGV;
Subroutine uninstall: not called CC=1 SCAR=6.9
Pod documented
255  
256 0 require ExtUtils::Install;
257  
258 0 print <<'WARNING';
259  
260 Uninstall is unsafe and deprecated, the uninstallation was not performed.
261 We will show what would have been done.
262  
263 WARNING
264  
265 0 ExtUtils::Install::uninstall($packlist, 1, 1);
266  
267 0 print <<'WARNING';
268  
269 Uninstall is unsafe and deprecated, the uninstallation was not performed.
270 Please check the list above carefully, there may be errors.
271 Remove the appropriate files manually.
272 Sorry for the inconvenience.
273  
274 WARNING
275  
276 }
277  
278 =item B<test_s>
279  
280 perl "-MExtUtils::Command::MM" -e test_s <file>
281  
282 Tests if a file exists and is not empty (size > 0).
283 I<Exits> with 0 if it does, 1 if it does not.
284  
285 =cut
286  
287 sub test_s {
288 0 ▶ exit(-s $ARGV[0] ? 0 : 1);
Subroutine test_s: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
-s $ARGV[0] ? : 0 0 0
289 }
290  
291 =item B<cp_nonempty>
292  
293 perl "-MExtUtils::Command::MM" -e cp_nonempty <srcfile> <dstfile> <perm>
294  
295 Tests if the source file exists and is not empty (size > 0). If it is not empty
296 it copies it to the given destination with the given permissions.
297  
298 =back
299  
300 =cut
301  
302 sub cp_nonempty {
303 0 ▶ my @args = @ARGV;
Subroutine cp_nonempty: not called CC=2 SCAR=17.9
Pod documented
304 0 ▶ return 0 unless -s $args[0];
Branch: 1 branch
BranchTrueFalseTotal
unless -s $args[0] 0 0 0
305 0 require ExtUtils::Command;
306 {
307 0 local @ARGV = @args[0,1];
308 0 ExtUtils::Command::cp(@ARGV);
309 }
310 {
311 0 local @ARGV = @args[2,1];
312 0 ExtUtils::Command::chmod(@ARGV);
313 }
314 }
315  
316  
317 2 1;
« lib/ExtUtils/MakeMaker.pm ↑ Summary lib/ExtUtils/MM_Any.pm »