This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
handy.h: add _memEQs() and _memNEs() for use with constant strings
[perl5.git] / utils / perlbug.PL
CommitLineData
37fa004c 1#!/usr/local/bin/perl
2
3use Config;
4use File::Basename qw(&basename &dirname);
8a5546a1 5use Cwd;
1948c06a 6use File::Spec::Functions;
37fa004c 7
8# List explicitly here the variables you want Configure to
9# generate. Metaconfig only looks for shell variables, so you
10# have to mention them as if they were shell variables, not
11# %Config entries. Thus you write
12# $startperl
13# to ensure Configure will look for $Config{startperl}.
84902520 14# $perlpath
37fa004c 15
16# This forces PL files to create target in same directory as PL file.
17# This is so that make depend always knows where to find PL derivatives.
8a5546a1 18$origdir = cwd;
44a8e56a 19chdir dirname($0);
20$file = basename($0, '.PL');
774d564b 21$file .= '.com' if $^O eq 'VMS';
37fa004c 22
55d729e4 23open OUT, ">$file" or die "Can't create $file: $!";
37fa004c 24
3541c11a
NT
25# get patchlevel.h timestamp
26
27-e catfile(updir, "patchlevel.h")
28 or die "Can't find patchlevel.h: $!";
84902520 29
3541c11a 30my $patchlevel_date = (stat _)[9];
84902520 31
e8a97f29 32# TO DO (perhaps): store/embed $Config::config_sh into perlbug. When perlbug is
5edeba26
TB
33# used, compare $Config::config_sh with the stored version. If they differ then
34# append a list of individual differences to the bug report.
35
84902520 36
37fa004c 37print "Extracting $file (with variable substitutions)\n";
38
39# In this section, perl variables will be expanded during extraction.
40# You can use $Config{...} to use Configure variables.
41
fa510083 42my $extract_version = sprintf("%vd", $^V);
1ec03f31 43
37fa004c 44print OUT <<"!GROK!THIS!";
5f05dabc 45$Config{startperl}
46 eval 'exec $Config{perlpath} -S \$0 \${1+"\$@"}'
47 if \$running_under_some_shell;
84902520 48
1ec03f31 49my \$config_tag1 = '$extract_version - $Config{cf_time}';
fb73857a 50
84902520 51my \$patchlevel_date = $patchlevel_date;
37fa004c 52!GROK!THIS!
53
54# In the following, perl variables are not expanded during extraction.
55
56print OUT <<'!NO!SUBS!';
3541c11a
NT
57my @patches = Config::local_patches();
58my $patch_tags = join "", map /(\S+)/ ? "+$1 " : (), @patches;
37fa004c 59
cee96d52 60BEGIN { pop @INC if $INC[-1] eq '.' }
54c90be1 61use warnings;
721e2275 62use strict;
37fa004c 63use Config;
1ec03f31 64use File::Spec; # keep perlbug Perl 5.005 compatible
37fa004c 65use Getopt::Std;
721e2275 66use File::Basename 'basename';
37fa004c 67
68sub paraprint;
69
55d729e4 70BEGIN {
54c90be1 71 eval { require Mail::Send;};
55d729e4 72 $::HaveSend = ($@ eq "");
54c90be1 73 eval { require Mail::Util; } ;
55d729e4 74 $::HaveUtil = ($@ eq "");
003a92ef 75 # use secure tempfiles wherever possible
54c90be1 76 eval { require File::Temp; };
003a92ef 77 $::HaveTemp = ($@ eq "");
13f4c5e4
AC
78 eval { require Module::CoreList; };
79 $::HaveCoreList = ($@ eq "");
c04bead1
NT
80 eval { require Text::Wrap; };
81 $::HaveWrap = ($@ eq "");
55d729e4 82};
c07a80fd 83
2bb62a09 84my $Version = "1.40";
c07a80fd 85
54c90be1
J
86#TODO:
87# make sure failure (transmission-wise) of Mail::Send is accounted for.
88# (This may work now. Unsure of the original author's issue -JESSE 2008-06-08)
1b0e3b9e 89# - Test -b option
37fa004c 90
721e2275
NC
91my( $file, $usefile, $cc, $address, $bugaddress, $testaddress, $thanksaddress,
92 $filename, $messageid, $domain, $subject, $from, $verbose, $ed, $outfile,
54c90be1 93 $fh, $me, $body, $andcc, %REP, $ok, $thanks, $progname,
8ced8222 94 $Is_MSWin32, $Is_Linux, $Is_VMS, $Is_OpenBSD,
54c90be1 95 $report_about_module, $category, $severity,
2bb62a09 96 %opt, $have_attachment, $attachments, $has_patch, $mime_boundary
54c90be1 97);
37fa004c 98
24963b0a
AC
99my $running_noninteractively = !-t STDIN;
100
fa510083 101my $perl_version = $^V ? sprintf("%vd", $^V) : $];
1ec03f31
GS
102
103my $config_tag2 = "$perl_version - $Config{cf_time}";
fb73857a 104
37fa004c 105Init();
106
4c62848c
JC
107if ($opt{h}) { Help(); exit; }
108if ($opt{d}) { Dump(*STDOUT); exit; }
24963b0a 109if ($running_noninteractively && !$opt{t} && !($ok and not $opt{n})) {
721e2275
NC
110 paraprint <<"EOF";
111Please use $progname interactively. If you want to
84478119 112include a file, you can use the -f switch.
113EOF
55d729e4 114 die "\n";
84478119 115}
c07a80fd 116
37fa004c 117Query();
4c62848c 118Edit() unless $usefile || ($ok and not $opt{n});
37fa004c 119NowWhat();
54c90be1
J
120if ($outfile) {
121 save_message_to_disk($outfile);
122} else {
123 Send();
4dbf56a0
NC
124 if ($thanks) {
125 print "\nThank you for taking the time to send a thank-you message!\n\n";
c983ad79
RS
126
127 paraprint <<EOF
128Please note that mailing lists are moderated, your message may take a while to
129show up.
130EOF
4dbf56a0
NC
131 } else {
132 print "\nThank you for taking the time to file a bug report!\n\n";
a9d7774b 133
c983ad79 134 paraprint <<EOF
a9d7774b
MM
135Please note that mailing lists are moderated, your message may take a while to
136show up. If you do not receive an automated response acknowledging your message
137within a few hours (check your SPAM folder and outgoing mail) please consider
23dfa308 138sending an email directly from your mail client to perlbug\@perl.org.
a9d7774b 139EOF
c983ad79
RS
140 }
141
54c90be1 142}
37fa004c 143
144exit;
145
975b416b 146sub ask_for_alternatives { # (category|severity)
50d3c28b 147 my $name = shift;
975b416b
GS
148 my %alts = (
149 'category' => {
150 'default' => 'core',
151 'ok' => 'install',
721e2275
NC
152 # Inevitably some of these will end up in RT whatever we do:
153 'thanks' => 'thanks',
975b416b
GS
154 'opts' => [qw(core docs install library utilities)], # patch, notabug
155 },
156 'severity' => {
157 'default' => 'low',
158 'ok' => 'none',
dda32041 159 'thanks' => 'none',
975b416b 160 'opts' => [qw(critical high medium low wishlist none)], # zero
7f2de2d2 161 },
975b416b 162 );
54c90be1 163 die "Invalid alternative ($name) requested\n" unless grep(/^$name$/, keys %alts);
50d3c28b 164 my $alt = "";
721e2275
NC
165 my $what = $ok || $thanks;
166 if ($what) {
167 $alt = $alts{$name}{$what};
975b416b
GS
168 } else {
169 my @alts = @{$alts{$name}{'opts'}};
54c90be1 170 print "\n\n";
975b416b 171 paraprint <<EOF;
54c90be1 172Please pick a $name from the following list:
50d3c28b
GS
173
174 @alts
50d3c28b 175EOF
975b416b
GS
176 my $err = 0;
177 do {
178 if ($err++ > 5) {
179 die "Invalid $name: aborting.\n";
180 }
54c90be1
J
181 $alt = _prompt('', "\u$name", $alts{$name}{'default'});
182 $alt ||= $alts{$name}{'default'};
975b416b
GS
183 } while !((($alt) = grep(/^$alt/i, @alts)));
184 }
50d3c28b
GS
185 lc $alt;
186}
187
37fa004c 188sub Init {
55d729e4
GS
189 # -------- Setup --------
190
191 $Is_MSWin32 = $^O eq 'MSWin32';
192 $Is_VMS = $^O eq 'VMS';
afc5e478 193 $Is_Linux = lc($^O) eq 'linux';
8843dda6 194 $Is_OpenBSD = lc($^O) eq 'openbsd';
55d729e4 195
2bb62a09 196 if (!getopts("Adhva:s:b:f:F:r:e:SCc:to:n:T:p:", \%opt)) { Help(); exit; };
55d729e4
GS
197
198 # This comment is needed to notify metaconfig that we are
199 # using the $perladmin, $cf_by, and $cf_time definitions.
200
201 # -------- Configuration ---------
202
203 # perlbug address
721e2275 204 $bugaddress = 'perlbug@perl.org';
55d729e4
GS
205
206 # Test address
3e79b69b 207 $testaddress = 'perlbug-test@perl.org';
55d729e4 208
721e2275
NC
209 # Thanks address
210 $thanksaddress = 'perl-thanks@perl.org';
211
212 if (basename ($0) =~ /^perlthanks/i) {
213 # invoked as perlthanks
4c62848c
JC
214 $opt{T} = 1;
215 $opt{C} = 1; # don't send a copy to the local admin
721e2275
NC
216 }
217
4c62848c 218 if ($opt{T}) {
721e2275
NC
219 $thanks = 'thanks';
220 }
221
222 $progname = $thanks ? 'perlthanks' : 'perlbug';
55d729e4 223 # Target address
4c62848c 224 $address = $opt{a} || ($opt{t} ? $testaddress
721e2275 225 : $thanks ? $thanksaddress : $bugaddress);
55d729e4 226
e4ef3332 227 # Users address, used in message and in From and Reply-To headers
4c62848c 228 $from = $opt{r} || "";
55d729e4
GS
229
230 # Include verbose configuration information
4c62848c 231 $verbose = $opt{v} || 0;
55d729e4
GS
232
233 # Subject of bug-report message
4c62848c 234 $subject = $opt{s} || "";
55d729e4
GS
235
236 # Send a file
4c62848c 237 $usefile = ($opt{f} || 0);
55d729e4
GS
238
239 # File to send as report
4c62848c 240 $file = $opt{f} || "";
55d729e4 241
2bb62a09
CB
242 # We have one or more attachments
243 $have_attachment = ($opt{p} || 0);
244 $mime_boundary = ('-' x 12) . "$Version.perlbug" if $have_attachment;
245
246 # Comma-separated list of attachments
247 $attachments = $opt{p} || "";
248 $has_patch = 0; # TBD based on file type
249
250 for my $attachment (split /\s*,\s*/, $attachments) {
251 unless (-f $attachment && -r $attachment) {
252 die "The attachment $attachment is not a readable file: $!\n";
253 }
254 $has_patch = 1 if $attachment =~ m/\.(patch|diff)$/;
255 }
256
105f9295 257 # File to output to
4c62848c 258 $outfile = $opt{F} || "";
105f9295 259
55d729e4 260 # Body of report
4c62848c 261 $body = $opt{b} || "";
de94c9df 262
55d729e4 263 # Editor
4c62848c 264 $ed = $opt{e} || $ENV{VISUAL} || $ENV{EDITOR} || $ENV{EDIT}
55d729e4
GS
265 || ($Is_VMS && "edit/tpu")
266 || ($Is_MSWin32 && "notepad")
267 || "vi";
268
269 # Not OK - provide build failure template by finessing OK report
4c62848c
JC
270 if ($opt{n}) {
271 if (substr($opt{n}, 0, 2) eq 'ok' ) {
272 $opt{o} = substr($opt{n}, 1);
55d729e4
GS
273 } else {
274 Help();
275 exit();
276 }
277 }
278
279 # OK - send "OK" report for build on this system
721e2275 280 $ok = '';
4c62848c
JC
281 if ($opt{o}) {
282 if ($opt{o} eq 'k' or $opt{o} eq 'kay') {
55d729e4 283 my $age = time - $patchlevel_date;
4c62848c 284 if ($opt{o} eq 'k' and $age > 60 * 24 * 60 * 60 ) {
55d729e4
GS
285 my $date = localtime $patchlevel_date;
286 print <<"EOF";
287"perlbug -ok" and "perlbug -nok" do not report on Perl versions which
288are more than 60 days old. This Perl version was constructed on
289$date. If you really want to report this, use
290"perlbug -okay" or "perlbug -nokay".
84902520 291EOF
1b0e3b9e
CR
292 exit();
293 }
55d729e4 294 # force these options
4c62848c
JC
295 unless ($opt{n}) {
296 $opt{S} = 1; # don't prompt for send
297 $opt{b} = 1; # we have a body
55d729e4
GS
298 $body = "Perl reported to build OK on this system.\n";
299 }
4c62848c
JC
300 $opt{C} = 1; # don't send a copy to the local admin
301 $opt{s} = 1; # we have a subject line
302 $subject = ($opt{n} ? 'Not ' : '')
1ec03f31 303 . "OK: perl $perl_version ${patch_tags}on"
55d729e4 304 ." $::Config{'archname'} $::Config{'osvers'} $subject";
721e2275 305 $ok = 'ok';
55d729e4
GS
306 } else {
307 Help();
308 exit();
1b0e3b9e 309 }
55d729e4 310 }
37fa004c 311
55d729e4
GS
312 # Possible administrator addresses, in order of confidence
313 # (Note that cf_email is not mentioned to metaconfig, since
314 # we don't really want it. We'll just take it if we have to.)
315 #
316 # This has to be after the $ok stuff above because of the way
4c62848c
JC
317 # that $opt{C} is forced.
318 $cc = $opt{C} ? "" : (
319 $opt{c} || $::Config{'perladmin'}
55d729e4
GS
320 || $::Config{'cf_email'} || $::Config{'cf_by'}
321 );
322
de94c9df
RF
323 if ($::HaveUtil) {
324 $domain = Mail::Util::maildomain();
325 } elsif ($Is_MSWin32) {
326 $domain = $ENV{'USERDOMAIN'};
327 } else {
328 require Sys::Hostname;
329 $domain = Sys::Hostname::hostname();
330 }
331
332 # Message-Id - rjsf
333 $messageid = "<$::Config{'version'}_${$}_".time."\@$domain>";
334
55d729e4
GS
335 # My username
336 $me = $Is_MSWin32 ? $ENV{'USERNAME'}
337 : $^O eq 'os2' ? $ENV{'USER'} || $ENV{'LOGNAME'}
338 : eval { getpwuid($<) }; # May be missing
c0830f08
RB
339
340 $from = $::Config{'cf_email'}
341 if !$from && $::Config{'cf_email'} && $::Config{'cf_by'} && $me &&
342 ($me eq $::Config{'cf_by'});
55d729e4 343} # sub Init
37fa004c 344
345sub Query {
55d729e4
GS
346 # Explain what perlbug is
347 unless ($ok) {
721e2275
NC
348 if ($thanks) {
349 paraprint <<'EOF';
350This program provides an easy way to send a thank-you message back to the
351authors and maintainers of perl.
352
353If you wish to submit a bug report, please run it without the -T flag
354(or run the program perlbug rather than perlthanks)
355EOF
356 } else {
357 paraprint <<"EOF";
54c90be1
J
358This program provides an easy way to create a message reporting a
359bug in the core perl distribution (along with tests or patches)
360to the volunteers who maintain perl at $address. To send a thank-you
361note to $thanksaddress instead of a bug report, please run 'perlthanks'.
362
363Please do not use $0 to send test messages, test whether perl
364works, or to report bugs in perl modules from CPAN.
365
a152f763
AC
366Suggestions for how to find help using Perl can be found at
367http://perldoc.perl.org/perlcommunity.html
37fa004c 368EOF
721e2275 369 }
1b0e3b9e 370 }
37fa004c 371
55d729e4 372 # Prompt for subject of message, if needed
2e7f46bf 373
54c90be1 374 if ($subject && TrivialSubject($subject)) {
2e7f46bf
JH
375 $subject = '';
376 }
377
55d729e4 378 unless ($subject) {
54c90be1
J
379 print
380"First of all, please provide a subject for the message.\n";
381 if ( not $thanks) {
721e2275 382 paraprint <<EOF;
54c90be1
J
383This should be a concise description of your bug or problem
384which will help the volunteers working to improve perl to categorize
385and resolve the issue. Be as specific and descriptive as
386you can. A subject like "perl bug" or "perl problem" will make it
387much less likely that your issue gets the attention it deserves.
37fa004c 388EOF
721e2275 389 }
55d729e4
GS
390
391 my $err = 0;
2e7f46bf 392 do {
54c90be1 393 $subject = _prompt('','Subject');
2e7f46bf 394 if ($err++ == 5) {
721e2275
NC
395 if ($thanks) {
396 $subject = 'Thanks for Perl';
397 } else {
398 die "Aborting.\n";
399 }
55d729e4 400 }
2e7f46bf 401 } while (TrivialSubject($subject));
55d729e4 402 }
2bb62a09
CB
403 $subject = '[PATCH] ' . $subject
404 if $has_patch && ($subject !~ m/^\[PATCH/i);
55d729e4
GS
405
406 # Prompt for return address, if needed
4c62848c 407 unless ($opt{r}) {
55d729e4
GS
408 # Try and guess return address
409 my $guess;
410
e6eb9020
DM
411 $guess = $ENV{'REPLY-TO'} || $ENV{'REPLYTO'} || $ENV{'EMAIL'}
412 || $from || '';
1948c06a 413
55d729e4 414 unless ($guess) {
de94c9df
RF
415 # move $domain to where we can use it elsewhere
416 if ($domain) {
55d729e4
GS
417 if ($Is_VMS && !$::Config{'d_socket'}) {
418 $guess = "$domain\:\:$me";
41f926b8 419 } else {
55d729e4 420 $guess = "$me\@$domain" if $domain;
c07a80fd 421 }
55d729e4
GS
422 }
423 }
37fa004c 424
55d729e4
GS
425 if ($guess) {
426 unless ($ok) {
427 paraprint <<EOF;
54c90be1
J
428Perl's developers may need your email address to contact you for
429further information about your issue or to inform you when it is
430resolved. If the default shown is not your email address, please
431correct it.
37fa004c 432EOF
55d729e4
GS
433 }
434 } else {
435 paraprint <<EOF;
54c90be1
J
436Please enter your full internet email address so that Perl's
437developers can contact you with questions about your issue or to
438inform you that it has been resolved.
37fa004c 439EOF
37fa004c 440 }
37fa004c 441
55d729e4
GS
442 if ($ok && $guess) {
443 # use it
444 $from = $guess;
445 } else {
446 # verify it
54c90be1 447 $from = _prompt('','Your address',$guess);
55d729e4
GS
448 $from = $guess if $from eq '';
449 }
450 }
37fa004c 451
55d729e4
GS
452 if ($from eq $cc or $me eq $cc) {
453 # Try not to copy ourselves
454 $cc = "yourself";
455 }
37fa004c 456
55d729e4 457 # Prompt for administrator address, unless an override was given
4c62848c 458 if( !$opt{C} and !$opt{c} ) {
54c90be1
J
459 my $description = <<EOF;
460$0 can send a copy of this report to your local perl
461administrator. If the address below is wrong, please correct it,
462or enter 'none' or 'yourself' to not send a copy.
37fa004c 463EOF
54c90be1 464 my $entry = _prompt($description, "Local perl administrator", $cc);
37fa004c 465
55d729e4
GS
466 if ($entry ne "") {
467 $cc = $entry;
468 $cc = '' if $me eq $cc;
37fa004c 469 }
55d729e4 470 }
37fa004c 471
55d729e4 472 $cc = '' if $cc =~ /^(none|yourself|me|myself|ourselves)$/i;
54c90be1
J
473 if ($cc) {
474 $andcc = " and $cc"
475 } else {
476 $andcc = ''
477 }
37fa004c 478
55d729e4 479 # Prompt for editor, if no override is given
ab3ef367 480editor:
4c62848c 481 unless ($opt{e} || $opt{f} || $opt{b}) {
26ab4e07 482
54c90be1 483 my $description;
26ab4e07 484
54c90be1
J
485 chomp (my $common_end = <<"EOF");
486You will probably want to use a text editor to enter the body of
487your report. If "$ed" is the editor you want to use, then just press
488Enter, otherwise type in the name of the editor you would like to
489use.
490
491If you have already composed the body of your report, you may enter
492"file", and $0 will prompt you to enter the name of the file
493containing your report.
721e2275
NC
494EOF
495
496 if ($thanks) {
54c90be1
J
497 $description = <<"EOF";
498It's now time to compose your thank-you message.
721e2275 499
54c90be1
J
500Some information about your local perl configuration will automatically
501be included at the end of your message, because we're curious about
502the different ways that people build and use perl. If you'd rather
503not share this information, you're welcome to delete it.
721e2275
NC
504
505$common_end
506EOF
507 } else {
54c90be1
J
508 $description = <<"EOF";
509It's now time to compose your bug report. Try to make the report
510concise but descriptive. Please include any detail which you think
511might be relevant or might help the volunteers working to improve
512perl. If you are reporting something that does not work as you think
513it should, please try to include examples of the actual result and of
514what you expected.
515
516Some information about your local perl configuration will automatically
517be included at the end of your report. If you are using an unusual
518version of perl, it would be useful if you could confirm that you
519can replicate the problem on a standard build of perl as well.
37fa004c 520
721e2275 521$common_end
37fa004c 522EOF
721e2275
NC
523 }
524
54c90be1 525 my $entry = _prompt($description, "Editor", $ed);
55d729e4
GS
526 $usefile = 0;
527 if ($entry eq "file") {
528 $usefile = 1;
529 } elsif ($entry ne "") {
530 $ed = $entry;
37fa004c 531 }
55d729e4 532 }
721e2275 533 if ($::HaveCoreList && !$ok && !$thanks) {
54c90be1
J
534 my $description = <<EOF;
535If your bug is about a Perl module rather than a core language
536feature, please enter its name here. If it's not, just hit Enter
537to skip this question.
13f4c5e4 538EOF
54c90be1
J
539
540 my $entry = '';
541 while ($entry eq '') {
542 $entry = _prompt($description, 'Module');
13f4c5e4 543 my $first_release = Module::CoreList->first_release($entry);
54c90be1 544 if ($entry and not $first_release) {
13f4c5e4 545 paraprint <<EOF;
54c90be1
J
546$entry is not a "core" Perl module. Please check that you entered
547its name correctly. If it is correct, quit this program, try searching
548for $entry on http://rt.cpan.org, and report your issue there.
13f4c5e4 549EOF
54c90be1
J
550
551 $entry = '';
0accdd48
NC
552 } elsif (my $bug_tracker = $Module::CoreList::bug_tracker{$entry}) {
553 paraprint <<"EOF";
554$entry included with core Perl is copied directly from the CPAN distribution.
555Please report bugs in $entry directly to its maintainers using $bug_tracker
556EOF
557 $entry = '';
54c90be1
J
558 } elsif ($entry) {
559 $category ||= 'library';
560 $report_about_module = $entry;
561 last;
562 } else {
563 last;
564 }
13f4c5e4
AC
565 }
566 }
37fa004c 567
50d3c28b 568 # Prompt for category of bug
975b416b 569 $category ||= ask_for_alternatives('category');
50d3c28b
GS
570
571 # Prompt for severity of bug
975b416b 572 $severity ||= ask_for_alternatives('severity');
50d3c28b 573
55d729e4
GS
574 # Generate scratch file to edit report in
575 $filename = filename();
37fa004c 576
55d729e4
GS
577 # Prompt for file to read report from, if needed
578 if ($usefile and !$file) {
ab3ef367 579filename:
54c90be1 580 my $description = <<EOF;
37fa004c 581What is the name of the file that contains your report?
37fa004c 582EOF
54c90be1 583 my $entry = _prompt($description, "Filename");
37fa004c 584
55d729e4
GS
585 if ($entry eq "") {
586 paraprint <<EOF;
54c90be1
J
587It seems you didn't enter a filename. Please choose to use a text
588editor or enter a filename.
ab3ef367 589EOF
55d729e4
GS
590 goto editor;
591 }
592
593 unless (-f $entry and -r $entry) {
594 paraprint <<EOF;
54c90be1
J
595'$entry' doesn't seem to be a readable file. You may have mistyped
596its name or may not have permission to read it.
597
598If you don't want to use a file as the content of your report, just
599hit Enter and you'll be able to select a text editor instead.
ab3ef367 600EOF
55d729e4 601 goto filename;
37fa004c 602 }
55d729e4
GS
603 $file = $entry;
604 }
37fa004c 605
55d729e4 606 # Generate report
092c3aff 607 open(REP, '>:raw', $filename) or die "Unable to create report file '$filename': $!\n";
7e6b9e3a
CB
608 binmode(REP, ':raw :crlf') if $Is_MSWin32;
609
721e2275 610 my $reptype = !$ok ? ($thanks ? 'thank-you' : 'bug')
4c62848c 611 : $opt{n} ? "build failure" : "success";
37fa004c 612
55d729e4 613 print REP <<EOF;
84902520 614This is a $reptype report for perl from $from,
1ec03f31 615generated with the help of perlbug $Version running under perl $perl_version.
37fa004c 616
617EOF
618
55d729e4
GS
619 if ($body) {
620 print REP $body;
621 } elsif ($usefile) {
fc6f6f37 622 open(F, '<:raw', $file)
c9967ac8 623 or die "Unable to read report file from '$file': $!\n";
7e6b9e3a 624 binmode(F, ':raw :crlf') if $Is_MSWin32;
55d729e4
GS
625 while (<F>) {
626 print REP $_
627 }
c9967ac8 628 close(F) or die "Error closing '$file': $!";
55d729e4 629 } else {
721e2275
NC
630 if ($thanks) {
631 print REP <<'EOF';
632
633-----------------------------------------------------------------
54c90be1 634[Please enter your thank-you message here]
721e2275
NC
635
636
637
54c90be1 638[You're welcome to delete anything below this line]
721e2275
NC
639-----------------------------------------------------------------
640EOF
641 } else {
642 print REP <<'EOF';
774d564b 643
644-----------------------------------------------------------------
54c90be1 645[Please describe your issue here]
774d564b 646
647
648
649[Please do not change anything below this line]
650-----------------------------------------------------------------
651EOF
721e2275 652 }
55d729e4
GS
653 }
654 Dump(*REP);
c0a6bf09 655 close(REP) or die "Error closing report file: $!";
55d729e4 656
54c90be1
J
657 # Set up an initial report fingerprint so we can compare it later
658 _fingerprint_lines_in_report();
659
55d729e4 660} # sub Query
c07a80fd 661
662sub Dump {
55d729e4 663 local(*OUT) = @_;
37fa004c 664
4ea8010a
DM
665 # these won't have been set if run with -d
666 $category ||= 'core';
667 $severity ||= 'low';
668
50d3c28b
GS
669 print OUT <<EFF;
670---
671Flags:
672 category=$category
673 severity=$severity
890b8eb0 674EFF
54c90be1 675
2bb62a09
CB
676 if ($has_patch) {
677 print OUT <<EFF;
678 Type=Patch
679 PatchStatus=HasPatch
680EFF
681 }
682
54c90be1
J
683 if ($report_about_module ) {
684 print OUT <<EFF;
685 module=$report_about_module
686EFF
687 }
4c62848c 688 if ($opt{A}) {
890b8eb0
NC
689 print OUT <<EFF;
690 ack=no
691EFF
692 }
693 print OUT <<EFF;
50d3c28b
GS
694---
695EFF
696 print OUT "This perlbug was built using Perl $config_tag1\n",
1ec03f31 697 "It is being executed now by Perl $config_tag2.\n\n"
55d729e4 698 if $config_tag2 ne $config_tag1;
fb73857a 699
55d729e4 700 print OUT <<EOF;
1ec03f31 701Site configuration information for perl $perl_version:
37fa004c 702
703EOF
55d729e4
GS
704 if ($::Config{cf_by} and $::Config{cf_time}) {
705 print OUT "Configured by $::Config{cf_by} at $::Config{cf_time}.\n\n";
706 }
707 print OUT Config::myconfig;
37fa004c 708
55d729e4
GS
709 if (@patches) {
710 print OUT join "\n ", "Locally applied patches:", @patches;
711 print OUT "\n";
712 };
84902520 713
55d729e4 714 print OUT <<EOF;
8ecf1a0c 715
774d564b 716---
1ec03f31 717\@INC for perl $perl_version:
774d564b 718EOF
55d729e4
GS
719 for my $i (@INC) {
720 print OUT " $i\n";
721 }
774d564b 722
55d729e4 723 print OUT <<EOF;
8ecf1a0c 724
774d564b 725---
1ec03f31 726Environment for perl $perl_version:
8ecf1a0c 727EOF
5cf1d1f1
JH
728 my @env =
729 qw(PATH LD_LIBRARY_PATH LANG PERL_BADLANG SHELL HOME LOGDIR LANGUAGE);
730 push @env, $Config{ldlibpthname} if $Config{ldlibpthname} ne '';
27414c22 731 push @env, grep /^(?:PERL|LC_|LANG|CYGWIN)/, keys %ENV;
8876aa85
JH
732 my %env;
733 @env{@env} = @env;
734 for my $env (sort keys %env) {
55d729e4
GS
735 print OUT " $env",
736 exists $ENV{$env} ? "=$ENV{$env}" : ' (unset)',
737 "\n";
738 }
739 if ($verbose) {
1ec03f31 740 print OUT "\nComplete configuration data for perl $perl_version:\n\n";
55d729e4
GS
741 my $value;
742 foreach (sort keys %::Config) {
743 $value = $::Config{$_};
4ea8010a 744 $value = '' unless defined $value;
55d729e4
GS
745 $value =~ s/'/\\'/g;
746 print OUT "$_='$value'\n";
84902520 747 }
55d729e4
GS
748 }
749} # sub Dump
37fa004c 750
751sub Edit {
55d729e4
GS
752 # Edit the report
753 if ($usefile || $body) {
54c90be1
J
754 my $description = "Please make sure that the name of the editor you want to use is correct.";
755 my $entry = _prompt($description, 'Editor', $ed);
55d729e4
GS
756 $ed = $entry unless $entry eq '';
757 }
a5f75d66 758
24963b0a 759 _edit_file($ed) unless $running_noninteractively;
54c90be1
J
760}
761
762sub _edit_file {
763 my $editor = shift;
764
765 my $report_written = 0;
766
767 while ( !$report_written ) {
8ced8222
NC
768 my $exit_status = system("$editor $filename");
769 if ($exit_status) {
770 my $desc = <<EOF;
54c90be1
J
771The editor you chose ('$editor') could not be run!
772
773If you mistyped its name, please enter it now, otherwise just press Enter.
1948c06a 774EOF
8ced8222
NC
775 my $entry = _prompt( $desc, 'Editor', $editor );
776 if ( $entry ne "" ) {
777 $editor = $entry;
778 next;
779 } else {
780 paraprint <<EOF;
54c90be1
J
781You may want to save your report to a file, so you can edit and
782mail it later.
a5f75d66 783EOF
8ced8222 784 return;
54c90be1
J
785 }
786 }
4c62848c 787 return if ( $ok and not $opt{n} ) || $body;
a5f75d66 788
54c90be1 789 # Check that we have a report that has some, eh, report in it.
774d564b 790
54c90be1
J
791 unless ( _fingerprint_lines_in_report() ) {
792 my $description = <<EOF;
793It looks like you didn't enter a report. You may [r]etry your edit
794or [c]ancel this report.
795EOF
796 my $action = _prompt( $description, "Action (Retry/Cancel) " );
797 if ( $action =~ /^[re]/i ) { # <R>etry <E>dit
798 next;
799 } elsif ( $action =~ /^[cq]/i ) { # <C>ancel, <Q>uit
800 Cancel(); # cancel exits
801 }
802 }
803 # Ok. the user did what they needed to;
804 return;
55d729e4 805
55d729e4 806 }
54c90be1 807}
774d564b 808
774d564b 809
810sub Cancel {
811 1 while unlink($filename); # remove all versions under VMS
54c90be1 812 print "\nQuitting without sending your message.\n";
774d564b 813 exit(0);
37fa004c 814}
815
816sub NowWhat {
55d729e4 817 # Report is done, prompt for further action
4c62848c 818 if( !$opt{S} ) {
55d729e4 819 while(1) {
54c90be1
J
820 my $menu = <<EOF;
821
822
823You have finished composing your message. At this point, you have
824a few options. You can:
825
6821e383 826 * [Se]nd the message to $address$andcc,
54c90be1
J
827 * [D]isplay the message on the screen,
828 * [R]e-edit the message
829 * Display or change the message's [su]bject
830 * Save the message to a [f]ile to mail at another time
831 * [Q]uit without sending a message
832
37fa004c 833EOF
8b49bb9a 834 retry:
54c90be1 835 print $menu;
9cea1b14
NT
836 my $action = _prompt('', "Action (Send/Display/Edit/Subject/Save to File)",
837 $opt{t} ? 'q' : '');
54c90be1 838 print "\n";
55d729e4 839 if ($action =~ /^(f|sa)/i) { # <F>ile/<Sa>ve
54c90be1 840 if ( SaveMessage() ) { exit }
55d729e4
GS
841 } elsif ($action =~ /^(d|l|sh)/i ) { # <D>isplay, <L>ist, <Sh>ow
842 # Display the message
bd18aea6 843 print _read_report($filename);
2bb62a09
CB
844 if ($have_attachment) {
845 print "\n\n---\nAttachment(s):\n";
846 for my $att (split /\s*,\s*/, $attachments) { print " $att\n"; }
847 }
2e7f46bf 848 } elsif ($action =~ /^su/i) { # <Su>bject
54c90be1 849 my $reply = _prompt( "Subject: $subject", "If the above subject is fine, press Enter. Otherwise, type a replacement now\nSubject");
2e7f46bf
JH
850 if ($reply ne '') {
851 unless (TrivialSubject($reply)) {
852 $subject = $reply;
853 print "Subject: $subject\n";
854 }
855 }
55d729e4
GS
856 } elsif ($action =~ /^se/i) { # <S>end
857 # Send the message
54c90be1
J
858 my $reply = _prompt( "Are you certain you want to send this message?", 'Please type "yes" if you are','no');
859 if ($reply =~ /^yes$/) {
55d729e4
GS
860 last;
861 } else {
862 paraprint <<EOF;
54c90be1 863You didn't type "yes", so your message has not yet been sent.
ab3ef367 864EOF
55d729e4
GS
865 }
866 } elsif ($action =~ /^[er]/i) { # <E>dit, <R>e-edit
867 # edit the message
868 Edit();
869 } elsif ($action =~ /^[qc]/i) { # <C>ancel, <Q>uit
870 Cancel();
01544859 871 } elsif ($action =~ /^s/i) {
55d729e4 872 paraprint <<EOF;
54c90be1 873The command you entered was ambiguous. Please type "send", "save" or "subject".
84478119 874EOF
55d729e4 875 }
37fa004c 876 }
55d729e4
GS
877 }
878} # sub NowWhat
37fa004c 879
2e7f46bf
JH
880sub TrivialSubject {
881 my $subject = shift;
882 if ($subject =~
883 /^(y(es)?|no?|help|perl( (bug|problem))?|bug|problem)$/i ||
884 length($subject) < 4 ||
a2b4240a 885 ($subject !~ /\s/ && ! $opt{t})) { # non-whitespace is accepted in test mode
54c90be1 886 print "\nThe subject you entered wasn't very descriptive. Please try again.\n\n";
2e7f46bf
JH
887 return 1;
888 } else {
889 return 0;
890 }
891}
892
54c90be1
J
893sub SaveMessage {
894 my $file_save = $outfile || "$progname.rep";
895 my $file = _prompt( '', "Name of file to save message in", $file_save );
896 save_message_to_disk($file) || return undef;
897 print "\n";
898 paraprint <<EOF;
899A copy of your message has been saved in '$file' for you to
900send to '$address' with your normal mail client.
901EOF
902}
903
37fa004c 904sub Send {
54c90be1 905
55d729e4 906 # Message has been accepted for transmission -- Send the message
afc5e478 907
54c90be1 908 # on linux certain "mail" implementations won't accept the subject
afc5e478
SB
909 # as "~s subject" and thus the Subject header will be corrupted
910 # so don't use Mail::Send to be safe
54c90be1
J
911 eval {
912 if ( $::HaveSend && !$Is_Linux && !$Is_OpenBSD ) {
913 _send_message_mailsend();
914 } elsif ($Is_VMS) {
915 _send_message_vms();
916 } else {
917 _send_message_sendmail();
918 }
919 };
37fa004c 920
54c90be1
J
921 if ( my $error = $@ ) {
922 paraprint <<EOF;
923$0 has detected an error while trying to send your message: $error.
c07a80fd 924
54c90be1 925Your message may not have been sent. You will now have a chance to save a copy to disk.
c07a80fd 926EOF
54c90be1
J
927 SaveMessage();
928 return;
55d729e4 929 }
54c90be1
J
930
931 1 while unlink($filename); # remove all versions under VMS
932} # sub Send
37fa004c 933
934sub Help {
55d729e4 935 print <<EOF;
37fa004c 936
54c90be1
J
937This program is designed to help you generate and send bug reports
938(and thank-you notes) about perl5 and the modules which ship with it.
939
940In most cases, you can just run "$0" interactively from a command
941line without any special arguments and follow the prompts.
942
943Advanced usage:
55d729e4 944
105f9295 945$0 [-v] [-a address] [-s subject] [-b body | -f inpufile ] [ -F outputfile ]
d121ca8c 946 [-r returnaddress] [-e editor] [-c adminaddress | -C] [-S] [-t] [-h]
2bb62a09 947 [-p patchfile ]
890b8eb0 948$0 [-v] [-r returnaddress] [-A] [-ok | -okay | -nok | -nokay]
55d729e4 949
37fa004c 950
951Options:
952
953 -v Include Verbose configuration data in the report
55d729e4 954 -f File containing the body of the report. Use this to
37fa004c 955 quickly send a prepared message.
2bb62a09
CB
956 -p File containing a patch or other text attachment. Separate
957 multiple files with commas.
1948c06a 958 -F File to output the resulting mail message to, instead of mailing.
37fa004c 959 -S Send without asking for confirmation.
c9967ac8
NC
960 -a Address to send the report to. Defaults to '$address'.
961 -c Address to send copy of report to. Defaults to '$cc'.
37fa004c 962 -C Don't send copy to administrator.
55d729e4 963 -s Subject to include with the message. You will be prompted
37fa004c 964 if you don't supply one on the command line.
965 -b Body of the report. If not included on the command line, or
966 in a file with -f, you will get a chance to edit the message.
967 -r Your return address. The program will ask you to confirm
968 this if you don't give it here.
55d729e4 969 -e Editor to use.
c9967ac8
NC
970 -t Test mode. The target address defaults to '$testaddress'.
971 -T Thank-you mode. The target address defaults to '$thanksaddress'.
489b74f8 972 -d Data mode. This prints out your configuration data, without mailing
c07a80fd 973 anything. You can use this with -v to get more complete data.
890b8eb0 974 -A Don't send a bug received acknowledgement to the return address.
84902520 975 -ok Report successful build on this system to perl porters
55d729e4
GS
976 (use alone or with -v). Only use -ok if *everything* was ok:
977 if there were *any* problems at all, use -nok.
fb73857a 978 -okay As -ok but allow report from old builds.
55d729e4
GS
979 -nok Report unsuccessful build on this system to perl porters
980 (use alone or with -v). You must describe what went wrong
981 in the body of the report which you will be asked to edit.
982 -nokay As -nok but allow report from old builds.
983 -h Print this help message.
984
37fa004c 985EOF
986}
987
55d729e4 988sub filename {
003a92ef
NC
989 if ($::HaveTemp) {
990 # Good. Use a secure temp file
991 my ($fh, $filename) = File::Temp::tempfile(UNLINK => 1);
992 close($fh);
993 return $filename;
994 } else {
995 # Bah. Fall back to doing things less securely.
996 my $dir = File::Spec->tmpdir();
997 $filename = "bugrep0$$";
998 $filename++ while -e File::Spec->catfile($dir, $filename);
999 $filename = File::Spec->catfile($dir, $filename);
1000 }
55d729e4
GS
1001}
1002
37fa004c 1003sub paraprint {
1004 my @paragraphs = split /\n{2,}/, "@_";
37fa004c 1005 for (@paragraphs) { # implicit local $_
55d729e4
GS
1006 s/(\S)\s*\n/$1 /g;
1007 write;
1008 print "\n";
37fa004c 1009 }
37fa004c 1010}
37fa004c 1011
54c90be1
J
1012sub _prompt {
1013 my ($explanation, $prompt, $default) = (@_);
1014 if ($explanation) {
1015 print "\n\n";
1016 paraprint $explanation;
1017 }
1018 print $prompt. ($default ? " [$default]" :''). ": ";
1019 my $result = scalar(<>);
9cea1b14 1020 return $default if !defined $result; # got eof
54c90be1
J
1021 chomp($result);
1022 $result =~ s/^\s*(.*?)\s*$/$1/s;
1023 if ($default && $result eq '') {
1024 return $default;
1025 } else {
1026 return $result;
1027 }
1028}
1029
1030sub _build_header {
1031 my %attr = (@_);
1032
1033 my $head = '';
1034 for my $header (keys %attr) {
1035 $head .= "$header: ".$attr{$header}."\n";
1036 }
1037 return $head;
1038}
1039
1040sub _message_headers {
1041 my %headers = ( To => $address, Subject => $subject );
1042 $headers{'Cc'} = $cc if ($cc);
1043 $headers{'Message-Id'} = $messageid if ($messageid);
1044 $headers{'Reply-To'} = $from if ($from);
e4ef3332 1045 $headers{'From'} = $from if ($from);
2bb62a09
CB
1046 if ($have_attachment) {
1047 $headers{'MIME-Version'} = '1.0';
1048 $headers{'Content-Type'} = qq{multipart/mixed; boundary=\"$mime_boundary\"};
1049 }
54c90be1
J
1050 return \%headers;
1051}
1052
2bb62a09
CB
1053sub _add_body_start {
1054 my $body_start = <<"BODY_START";
1055This is a multi-part message in MIME format.
1056--$mime_boundary
fc6f6f37 1057Content-Type: text/plain; format=fixed
2bb62a09
CB
1058Content-Transfer-Encoding: 8bit
1059
1060BODY_START
1061 return $body_start;
1062}
1063
1064sub _add_attachments {
1065 my $attach = '';
1066 for my $attachment (split /\s*,\s*/, $attachments) {
1067 my $attach_file = basename($attachment);
1068 $attach .= <<"ATTACHMENT";
1069
1070--$mime_boundary
1071Content-Type: text/x-patch; name="$attach_file"
1072Content-Transfer-Encoding: 8bit
1073Content-Disposition: attachment; filename="$attach_file"
1074
1075ATTACHMENT
1076
092c3aff 1077 open my $attach_fh, '<:raw', $attachment
2bb62a09
CB
1078 or die "Couldn't open attachment '$attachment': $!\n";
1079 while (<$attach_fh>) { $attach .= $_; }
1080 close($attach_fh) or die "Error closing attachment '$attachment': $!";
1081 }
1082
1083 $attach .= "\n--$mime_boundary--\n";
1084 return $attach;
1085}
1086
bd18aea6
NT
1087sub _read_report {
1088 my $fname = shift;
1089 my $content;
1090 open( REP, "<:raw", $fname ) or die "Couldn't open file '$fname': $!\n";
1091 binmode(REP, ':raw :crlf') if $Is_MSWin32;
c04bead1
NT
1092 # wrap long lines to make sure the report gets delivered
1093 local $Text::Wrap::columns = 900;
1094 local $Text::Wrap::huge = 'overflow';
1095 while (<REP>) {
1096 if ($::HaveWrap && /\S/) { # wrap() would remove empty lines
1097 $content .= Text::Wrap::wrap(undef, undef, $_);
1098 } else {
1099 $content .= $_;
1100 }
1101 }
bd18aea6
NT
1102 close(REP) or die "Error closing report file '$fname': $!";
1103 return $content;
1104}
1105
54c90be1
J
1106sub build_complete_message {
1107 my $content = _build_header(%{_message_headers()}) . "\n\n";
2bb62a09 1108 $content .= _add_body_start() if $have_attachment;
bd18aea6 1109 $content .= _read_report($filename);
2bb62a09 1110 $content .= _add_attachments() if $have_attachment;
54c90be1
J
1111 return $content;
1112}
1113
1114sub save_message_to_disk {
1115 my $file = shift;
1116
092c3aff 1117 open OUTFILE, '>:raw', $file or do { warn "Couldn't open '$file': $!\n"; return undef};
7e6b9e3a
CB
1118 binmode(OUTFILE, ':raw :crlf') if $Is_MSWin32;
1119
54c90be1
J
1120 print OUTFILE build_complete_message();
1121 close(OUTFILE) or do { warn "Error closing $file: $!"; return undef };
1122 print "\nMessage saved.\n";
1123 return 1;
1124}
1125
1126sub _send_message_vms {
90e95a22
CB
1127
1128 my $mail_from = $from;
1129 my $rcpt_to_to = $address;
1130 my $rcpt_to_cc = $cc;
1131
1132 map { $_ =~ s/^[^<]*<//;
1133 $_ =~ s/>[^>]*//; } ($mail_from, $rcpt_to_to, $rcpt_to_cc);
1134
092c3aff 1135 if ( open my $sff_fh, '|-:raw', 'MCR TCPIP$SYSTEM:TCPIP$SMTP_SFF.EXE SYS$INPUT:' ) {
90e95a22
CB
1136 print $sff_fh "MAIL FROM:<$mail_from>\n";
1137 print $sff_fh "RCPT TO:<$rcpt_to_to>\n";
1138 print $sff_fh "RCPT TO:<$rcpt_to_cc>\n" if $rcpt_to_cc;
1139 print $sff_fh "DATA\n";
1140 print $sff_fh build_complete_message();
1141 my $success = close $sff_fh;
1142 if ($success ) {
1143 print "\nMessage sent\n";
1144 return;
54c90be1 1145 }
54c90be1 1146 }
90e95a22 1147 die "Mail transport failed (leaving bug report in $filename): $^E\n";
54c90be1
J
1148}
1149
1150sub _send_message_mailsend {
1151 my $msg = Mail::Send->new();
1152 my %headers = %{_message_headers()};
1153 for my $key ( keys %headers) {
1154 $msg->add($key => $headers{$key});
1155 }
1156
1157 $fh = $msg->open;
092c3aff 1158 binmode($fh, ':raw');
2bb62a09 1159 print $fh _add_body_start() if $have_attachment;
bd18aea6 1160 print $fh _read_report($filename);
2bb62a09 1161 print $fh _add_attachments() if $have_attachment;
e90b02b9 1162 $fh->close or die "Error sending mail: $!";
54c90be1
J
1163
1164 print "\nMessage sent.\n";
1165}
1166
1167sub _probe_for_sendmail {
1168 my $sendmail = "";
1169 for (qw(/usr/lib/sendmail /usr/sbin/sendmail /usr/ucblib/sendmail)) {
1170 $sendmail = $_, last if -e $_;
1171 }
1172 if ( $^O eq 'os2' and $sendmail eq "" ) {
1173 my $path = $ENV{PATH};
1174 $path =~ s:\\:/:;
1175 my @path = split /$Config{'path_sep'}/, $path;
1176 for (@path) {
1177 $sendmail = "$_/sendmail", last if -e "$_/sendmail";
1178 $sendmail = "$_/sendmail.exe", last if -e "$_/sendmail.exe";
1179 }
1180 }
1181 return $sendmail;
1182}
1183
1184sub _send_message_sendmail {
1185 my $sendmail = _probe_for_sendmail();
1186 unless ($sendmail) {
e90d6148 1187 my $message_start = !$Is_Linux && !$Is_OpenBSD ? <<'EOT' : <<'EOT';
54c90be1
J
1188It appears that there is no program which looks like "sendmail" on
1189your system and that the Mail::Send library from CPAN isn't available.
e90d6148
A
1190EOT
1191It appears that there is no program which looks like "sendmail" on
1192your system.
1193EOT
1194 paraprint(<<"EOF"), die "\n";
1195$message_start
54c90be1
J
1196Because of this, there's no easy way to automatically send your
1197message.
1198
1199A copy of your message has been saved in '$filename' for you to
1200send to '$address' with your normal mail client.
1201EOF
1202 }
1203
092c3aff 1204 open( SENDMAIL, "|-:raw", $sendmail, "-t", "-oi", "-f", $from )
019cfd23 1205 || die "'|$sendmail -t -oi -f $from' failed: $!";
54c90be1
J
1206 print SENDMAIL build_complete_message();
1207 if ( close(SENDMAIL) ) {
1208 print "\nMessage sent\n";
1209 } else {
1210 warn "\nSendmail returned status '", $? >> 8, "'\n";
1211 }
1212}
1213
1214
1215
1216# a strange way to check whether any significant editing
1217# has been done: check whether any new non-empty lines
1218# have been added.
1219
1220sub _fingerprint_lines_in_report {
1221 my $new_lines = 0;
1222 # read in the report template once so that
1223 # we can track whether the user does any editing.
1224 # yes, *all* whitespace is ignored.
1225
092c3aff 1226 open(REP, '<:raw', $filename) or die "Unable to open report file '$filename': $!\n";
7e6b9e3a 1227 binmode(REP, ':raw :crlf') if $Is_MSWin32;
54c90be1
J
1228 while (my $line = <REP>) {
1229 $line =~ s/\s+//g;
1230 $new_lines++ if (!$REP{$line});
1231
1232 }
1233 close(REP) or die "Error closing report file '$filename': $!";
1234 # returns the number of lines with content that wasn't there when last we looked
1235 return $new_lines;
1236}
1237
1238
1239
37fa004c 1240format STDOUT =
1241^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ~~
1242$_
1243.
d121ca8c
CS
1244
1245__END__
1246
1247=head1 NAME
1248
1249perlbug - how to submit bug reports on Perl
1250
1251=head1 SYNOPSIS
1252
54c90be1
J
1253B<perlbug>
1254
d121ca8c 1255B<perlbug> S<[ B<-v> ]> S<[ B<-a> I<address> ]> S<[ B<-s> I<subject> ]>
105f9295
HS
1256S<[ B<-b> I<body> | B<-f> I<inputfile> ]> S<[ B<-F> I<outputfile> ]>
1257S<[ B<-r> I<returnaddress> ]>
d121ca8c 1258S<[ B<-e> I<editor> ]> S<[ B<-c> I<adminaddress> | B<-C> ]>
985dc10a 1259S<[ B<-S> ]> S<[ B<-t> ]> S<[ B<-d> ]> S<[ B<-A> ]> S<[ B<-h> ]> S<[ B<-T> ]>
d121ca8c 1260
55d729e4 1261B<perlbug> S<[ B<-v> ]> S<[ B<-r> I<returnaddress> ]>
890b8eb0 1262 S<[ B<-A> ]> S<[ B<-ok> | B<-okay> | B<-nok> | B<-nokay> ]>
1b0e3b9e 1263
985dc10a
SP
1264B<perlthanks>
1265
d121ca8c
CS
1266=head1 DESCRIPTION
1267
d121ca8c 1268
54c90be1
J
1269This program is designed to help you generate and send bug reports
1270(and thank-you notes) about perl5 and the modules which ship with it.
1271
1272In most cases, you can just run it interactively from a command
1273line without any special arguments and follow the prompts.
1274
1275If you have found a bug with a non-standard port (one that was not
1276part of the I<standard distribution>), a binary distribution, or a
1277non-core module (such as Tk, DBI, etc), then please see the
1278documentation that came with that distribution to determine the
1279correct place to report bugs.
d121ca8c 1280
54c90be1
J
1281If you are unable to send your report using B<perlbug> (most likely
1282because your system doesn't have a way to send mail that perlbug
1283recognizes), you may be able to use this tool to compose your report
1284and save it to a file which you can then send to B<perlbug@perl.org>
1285using your regular mail client.
d121ca8c 1286
54c90be1
J
1287In extreme cases, B<perlbug> may not work well enough on your system
1288to guide you through composing a bug report. In those cases, you
1289may be able to use B<perlbug -d> to get system configuration
1290information to include in a manually composed bug report to
1291B<perlbug@perl.org>.
d121ca8c 1292
54c90be1
J
1293
1294When reporting a bug, please run through this checklist:
d121ca8c
CS
1295
1296=over 4
1297
884baa66 1298=item What version of Perl you are running?
d121ca8c
CS
1299
1300Type C<perl -v> at the command line to find out.
1301
1302=item Are you running the latest released version of perl?
1303
54c90be1
J
1304Look at http://www.perl.org/ to find out. If you are not using the
1305latest released version, please try to replicate your bug on the
1306latest stable release.
1307
1308Note that reports about bugs in old versions of Perl, especially
1309those which indicate you haven't also tested the current stable
1310release of Perl, are likely to receive less attention from the
1311volunteers who build and maintain Perl than reports about bugs in
1312the current release.
1313
5538372e 1314This tool isn't appropriate for reporting bugs in any version
54c90be1 1315prior to Perl 5.0.
d121ca8c
CS
1316
1317=item Are you sure what you have is a bug?
1318
54c90be1
J
1319A significant number of the bug reports we get turn out to be
1320documented features in Perl. Make sure the issue you've run into
1321isn't intentional by glancing through the documentation that comes
1322with the Perl distribution.
d121ca8c 1323
54c90be1
J
1324Given the sheer volume of Perl documentation, this isn't a trivial
1325undertaking, but if you can point to documentation that suggests
1326the behaviour you're seeing is I<wrong>, your issue is likely to
1327receive more attention. You may want to start with B<perldoc>
1328L<perltrap> for pointers to common traps that new (and experienced)
1329Perl programmers run into.
d121ca8c 1330
54c90be1
J
1331If you're unsure of the meaning of an error message you've run
1332across, B<perldoc> L<perldiag> for an explanation. If the message
1333isn't in perldiag, it probably isn't generated by Perl. You may
1334have luck consulting your operating system documentation instead.
bdcdfa19 1335
54c90be1 1336If you are on a non-UNIX platform B<perldoc> L<perlport>, as some
1948c06a 1337features may be unimplemented or work differently.
bdcdfa19 1338
54c90be1
J
1339You may be able to figure out what's going wrong using the Perl
1340debugger. For information about how to use the debugger B<perldoc>
1341L<perldebug>.
d121ca8c
CS
1342
1343=item Do you have a proper test case?
1344
1345The easier it is to reproduce your bug, the more likely it will be
985dc10a 1346fixed -- if nobody can duplicate your problem, it probably won't be
54c90be1
J
1347addressed.
1348
1349A good test case has most of these attributes: short, simple code;
1350few dependencies on external commands, modules, or libraries; no
1351platform-dependent code (unless it's a platform-specific bug);
1352clear, simple documentation.
1353
1354A good test case is almost always a good candidate to be included in
1355Perl's test suite. If you have the time, consider writing your test case so
1356that it can be easily included into the standard test suite.
d121ca8c 1357
54c90be1 1358=item Have you included all relevant information?
d121ca8c 1359
54c90be1
J
1360Be sure to include the B<exact> error messages, if any.
1361"Perl gave an error" is not an exact error message.
bdcdfa19
JH
1362
1363If you get a core dump (or equivalent), you may use a debugger
1364(B<dbx>, B<gdb>, etc) to produce a stack trace to include in the bug
54c90be1
J
1365report.
1366
1367NOTE: unless your Perl has been compiled with debug info
bdcdfa19 1368(often B<-g>), the stack trace is likely to be somewhat hard to use
884baa66 1369because it will most probably contain only the function names and not
bdcdfa19 1370their arguments. If possible, recompile your Perl with debug info and
54c90be1 1371reproduce the crash and the stack trace.
bdcdfa19 1372
d121ca8c
CS
1373=item Can you describe the bug in plain English?
1374
54c90be1
J
1375The easier it is to understand a reproducible bug, the more likely
1376it will be fixed. Any insight you can provide into the problem
1377will help a great deal. In other words, try to analyze the problem
1378(to the extent you can) and report your discoveries.
d121ca8c
CS
1379
1380=item Can you fix the bug yourself?
1381
2bb62a09
CB
1382If so, that's great news; bug reports with patches are likely to
1383receive significantly more attention and interest than those without
1384patches. Please attach your patch to the report using the C<-p> option.
1385When sending a patch, create it using C<git format-patch> if possible,
1386though a unified diff created with C<diff -pu> will do nearly as well.
54c90be1
J
1387
1388Your patch may be returned with requests for changes, or requests for more
d121ca8c
CS
1389detailed explanations about your fix.
1390
54c90be1
J
1391Here are a few hints for creating high-quality patches:
1392
1393Make sure the patch is not reversed (the first argument to diff is
1394typically the original file, the second argument your changed file).
2bb62a09
CB
1395Make sure you test your patch by applying it with C<git am> or the
1396C<patch> program before you send it on its way. Try to follow the
1397same style as the code you are trying to patch. Make sure your patch
1398really does work (C<make test>, if the thing you're patching is covered
54c90be1 1399by Perl's test suite).
d121ca8c
CS
1400
1401=item Can you use C<perlbug> to submit the report?
1402
1403B<perlbug> will, amongst other things, ensure your report includes
54c90be1
J
1404crucial information about your version of perl. If C<perlbug> is
1405unable to mail your report after you have typed it in, you may have
1406to compose the message yourself, add the output produced by C<perlbug
1407-d> and email it to B<perlbug@perl.org>. If, for some reason, you
1408cannot run C<perlbug> at all on your system, be sure to include the
1409entire output produced by running C<perl -V> (note the uppercase V).
d121ca8c 1410
bdcdfa19 1411Whether you use C<perlbug> or send the email manually, please make
54c90be1
J
1412your Subject line informative. "a bug" is not informative. Neither
1413is "perl crashes" nor is "HELP!!!". These don't help. A compact
1414description of what's wrong is fine.
bdcdfa19 1415
985dc10a
SP
1416=item Can you use C<perlbug> to submit a thank-you note?
1417
1418Yes, you can do this by either using the C<-T> option, or by invoking
1419the program as C<perlthanks>. Thank-you notes are good. It makes people
1420smile.
1421
d121ca8c
CS
1422=back
1423
54c90be1
J
1424Having done your bit, please be prepared to wait, to be told the
1425bug is in your code, or possibly to get no reply at all. The
1426volunteers who maintain Perl are busy folks, so if your problem is
1427an obvious bug in your own code, is difficult to understand or is
1428a duplicate of an existing report, you may not receive a personal
1429reply.
1430
26ab4e07 1431If it is important to you that your bug be fixed, do monitor the
a9d7774b
MM
1432perl5-porters@perl.org mailing list (mailing lists are moderated, your
1433message may take a while to show up) and the commit logs to development
54c90be1
J
1434versions of Perl, and encourage the maintainers with kind words or
1435offers of frosty beverages. (Please do be kind to the maintainers.
a9d7774b
MM
1436Harassing or flaming them is likely to have the opposite effect of the
1437one you want.)
54c90be1
J
1438
1439Feel free to update the ticket about your bug on http://rt.perl.org
1440if a new version of Perl is released and your bug is still present.
d121ca8c
CS
1441
1442=head1 OPTIONS
1443
1444=over 8
1445
1446=item B<-a>
1447
3e79b69b 1448Address to send the report to. Defaults to B<perlbug@perl.org>.
d121ca8c 1449
890b8eb0
NC
1450=item B<-A>
1451
1452Don't send a bug received acknowledgement to the reply address.
1453Generally it is only a sensible to use this option if you are a
1454perl maintainer actively watching perl porters for your message to
1455arrive.
1456
d121ca8c
CS
1457=item B<-b>
1458
1459Body of the report. If not included on the command line, or
1460in a file with B<-f>, you will get a chance to edit the message.
1461
1462=item B<-C>
1463
1464Don't send copy to administrator.
1465
1466=item B<-c>
1467
1468Address to send copy of report to. Defaults to the address of the
1469local perl administrator (recorded when perl was built).
1470
1471=item B<-d>
1472
1473Data mode (the default if you redirect or pipe output). This prints out
1474your configuration data, without mailing anything. You can use this
1475with B<-v> to get more complete data.
1476
1477=item B<-e>
1478
55d729e4 1479Editor to use.
d121ca8c
CS
1480
1481=item B<-f>
1482
1483File containing the body of the report. Use this to quickly send a
1484prepared message.
1485
105f9295
HS
1486=item B<-F>
1487
1488File to output the results to instead of sending as an email. Useful
1489particularly when running perlbug on a machine with no direct internet
1490connection.
1491
d121ca8c
CS
1492=item B<-h>
1493
1494Prints a brief summary of the options.
1495
1b0e3b9e
CR
1496=item B<-ok>
1497
84902520
TB
1498Report successful build on this system to perl porters. Forces B<-S>
1499and B<-C>. Forces and supplies values for B<-s> and B<-b>. Only
1b0e3b9e 1500prompts for a return address if it cannot guess it (for use with
84902520
TB
1501B<make>). Honors return address specified with B<-r>. You can use this
1502with B<-v> to get more complete data. Only makes a report if this
1503system is less than 60 days old.
1504
1505=item B<-okay>
1506
1507As B<-ok> except it will report on older systems.
1b0e3b9e 1508
55d729e4
GS
1509=item B<-nok>
1510
1511Report unsuccessful build on this system. Forces B<-C>. Forces and
1512supplies a value for B<-s>, then requires you to edit the report
1513and say what went wrong. Alternatively, a prepared report may be
1514supplied using B<-f>. Only prompts for a return address if it
1515cannot guess it (for use with B<make>). Honors return address
1516specified with B<-r>. You can use this with B<-v> to get more
1517complete data. Only makes a report if this system is less than 60
1518days old.
1519
1520=item B<-nokay>
1521
1522As B<-nok> except it will report on older systems.
1523
2bb62a09
CB
1524=item B<-p>
1525
1526The names of one or more patch files or other text attachments to be
1527included with the report. Multiple files must be separated with commas.
1528
d121ca8c
CS
1529=item B<-r>
1530
1531Your return address. The program will ask you to confirm its default
1532if you don't use this option.
1533
1534=item B<-S>
1535
1536Send without asking for confirmation.
1537
1538=item B<-s>
1539
1540Subject to include with the message. You will be prompted if you don't
1541supply one on the command line.
1542
1543=item B<-t>
1544
3e79b69b 1545Test mode. The target address defaults to B<perlbug-test@perl.org>.
fdfa3307
NT
1546Also makes it possible to command perlbug from a pipe or file, for
1547testing purposes.
d121ca8c 1548
985dc10a
SP
1549=item B<-T>
1550
1551Send a thank-you note instead of a bug report.
1552
d121ca8c
CS
1553=item B<-v>
1554
1555Include verbose configuration data in the report.
1556
1557=back
1558
1559=head1 AUTHORS
1560
54c90be1
J
1561Kenneth Albanowski (E<lt>kjahds@kjahds.comE<gt>), subsequently
1562I<doc>tored by Gurusamy Sarathy (E<lt>gsar@activestate.comE<gt>),
1563Tom Christiansen (E<lt>tchrist@perl.comE<gt>), Nathan Torkington
1564(E<lt>gnat@frii.comE<gt>), Charles F. Randall (E<lt>cfr@pobox.comE<gt>),
9e533305
DH
1565Mike Guy (E<lt>mjtg@cam.ac.ukE<gt>), Dominic Dunlop
1566(E<lt>domo@computer.orgE<gt>), Hugo van der Sanden (E<lt>hv@crypt.orgE<gt>),
50d3c28b
GS
1567Jarkko Hietaniemi (E<lt>jhi@iki.fiE<gt>), Chris Nandor
1568(E<lt>pudge@pobox.comE<gt>), Jon Orwant (E<lt>orwant@media.mit.eduE<gt>,
2bb62a09
CB
1569Richard Foley (E<lt>richard.foley@rfi.netE<gt>), Jesse Vincent
1570(E<lt>jesse@bestpractical.comE<gt>), and Craig A. Berry (E<lt>craigberry@mac.comE<gt>).
d121ca8c
CS
1571
1572=head1 SEE ALSO
1573
bdcdfa19
JH
1574perl(1), perldebug(1), perldiag(1), perlport(1), perltrap(1),
1575diff(1), patch(1), dbx(1), gdb(1)
d121ca8c
CS
1576
1577=head1 BUGS
1578
1579None known (guess what must have been used to report them?)
1580
1581=cut
1582
37fa004c 1583!NO!SUBS!
1584
1585close OUT or die "Can't close $file: $!";
1586chmod 0755, $file or die "Can't reset permissions for $file: $!\n";
1587exec("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':';
8a5546a1 1588chdir $origdir;