WinGit: Move create-shortcut.exe to bin/
[msysgit.git] / bin / perlbug
blobe9a22a3024af41ccdacfe8cef502ae33f3faa801
1 #!/usr/bin/perl
2 eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
3 if $running_under_some_shell;
5 my $config_tag1 = 'v5.6.1 - Sat May 18 14:14:54 EDT 2002';
7 my $patchlevel_date = 986778897;
8 my $patch_tags = '';
9 my @patches = (
13 use Config;
14 use File::Spec; # keep perlbug Perl 5.005 compatible
15 use Getopt::Std;
16 use strict;
18 sub paraprint;
20 BEGIN {
21 eval "use Mail::Send;";
22 $::HaveSend = ($@ eq "");
23 eval "use Mail::Util;";
24 $::HaveUtil = ($@ eq "");
27 my $Version = "1.33";
29 # Changed in 1.06 to skip Mail::Send and Mail::Util if not available.
30 # Changed in 1.07 to see more sendmail execs, and added pipe output.
31 # Changed in 1.08 to use correct address for sendmail.
32 # Changed in 1.09 to close the REP file before calling it up in the editor.
33 # Also removed some old comments duplicated elsewhere.
34 # Changed in 1.10 to run under VMS without Mail::Send; also fixed
35 # temp filename generation.
36 # Changed in 1.11 to clean up some text and removed Mail::Send deactivator.
37 # Changed in 1.12 to check for editor errors, make save/send distinction
38 # clearer and add $ENV{REPLYTO}.
39 # Changed in 1.13 to hopefully make it more difficult to accidentally
40 # send mail
41 # Changed in 1.14 to make the prompts a little more clear on providing
42 # helpful information. Also let file read fail gracefully.
43 # Changed in 1.15 to add warnings to stop people using perlbug for non-bugs.
44 # Also report selected environment variables.
45 # Changed in 1.16 to include @INC, and allow user to re-edit if no changes.
46 # Changed in 1.17 Win32 support added. GSAR 97-04-12
47 # Changed in 1.18 add '-ok' option for reporting build success. CFR 97-06-18
48 # Changed in 1.19 '-ok' default not '-v'
49 # add local patch information
50 # warn on '-ok' if this is an old system; add '-okay'
51 # Changed in 1.20 Added patchlevel.h reading and version/config checks
52 # Changed in 1.21 Added '-nok' for reporting build failure DFD 98-05-05
53 # Changed in 1.22 Heavy reformatting & minor bugfixes HVDS 98-05-10
54 # Changed in 1.23 Restore -ok(ay): say 'success'; don't prompt
55 # Changed in 1.24 Added '-F<file>' to save report HVDS 98-07-01
56 # Changed in 1.25 Warn on failure to open save file. HVDS 98-07-12
57 # Changed in 1.26 Don't require -t STDIN for -ok. HVDS 98-07-15
58 # Changed in 1.27 Added Mac OS and File::Spec support CNANDOR 99-07-27
59 # Changed in 1.28 Additional questions for Perlbugtron RFOLEY 20.03.2000
60 # Changed in 1.29 Perlbug(tron): auto(-ok), short prompts RFOLEY 05-05-2000
61 # Changed in 1.30 Added warnings on failure to open files MSTEVENS 13-07-2000
62 # Changed in 1.31 Add checks on close().Fix my $var unless. TJENNESS 26-07-2000
63 # Changed in 1.32 Use File::Spec->tmpdir TJENNESS 20-08-2000
64 # Changed in 1.33 Don't require -t STDOUT for -ok.
66 # TODO: - Allow the user to re-name the file on mail failure, and
67 # make sure failure (transmission-wise) of Mail::Send is
68 # accounted for.
69 # - Test -b option
71 my( $file, $usefile, $cc, $address, $perlbug, $testaddress, $filename,
72 $subject, $from, $verbose, $ed, $outfile, $Is_MacOS, $category, $severity,
73 $fh, $me, $Is_MSWin32, $Is_VMS, $msg, $body, $andcc, %REP, $ok);
75 my $perl_version = $^V ? sprintf("v%vd", $^V) : $];
77 my $config_tag2 = "$perl_version - $Config{cf_time}";
79 Init();
81 if ($::opt_h) { Help(); exit; }
82 if ($::opt_d) { Dump(*STDOUT); exit; }
83 if (!-t STDIN && !($ok and not $::opt_n)) {
84 paraprint <<EOF;
85 Please use perlbug interactively. If you want to
86 include a file, you can use the -f switch.
87 EOF
88 die "\n";
91 Query();
92 Edit() unless $usefile || ($ok and not $::opt_n);
93 NowWhat();
94 Send();
96 exit;
98 sub ask_for_alternatives { # (category|severity)
99 my $name = shift;
100 my %alts = (
101 'category' => {
102 'default' => 'core',
103 'ok' => 'install',
104 'opts' => [qw(core docs install library utilities)], # patch, notabug
106 'severity' => {
107 'default' => 'low',
108 'ok' => 'none',
109 'opts' => [qw(critical high medium low wishlist none)], # zero
112 die "Invalid alternative($name) requested\n" unless grep(/^$name$/, keys %alts);
113 my $alt = "";
114 if ($ok) {
115 $alt = $alts{$name}{'ok'};
116 } else {
117 my @alts = @{$alts{$name}{'opts'}};
118 paraprint <<EOF;
119 Please pick a \u$name from the following:
121 @alts
124 my $err = 0;
125 do {
126 if ($err++ > 5) {
127 die "Invalid $name: aborting.\n";
129 print "Please enter a \u$name [$alts{$name}{'default'}]: ";
130 $alt = <>;
131 chomp $alt;
132 if ($alt =~ /^\s*$/) {
133 $alt = $alts{$name}{'default'};
135 } while !((($alt) = grep(/^$alt/i, @alts)));
137 lc $alt;
140 sub Init {
141 # -------- Setup --------
143 $Is_MSWin32 = $^O eq 'MSWin32';
144 $Is_VMS = $^O eq 'VMS';
145 $Is_MacOS = $^O eq 'MacOS';
147 @ARGV = split m/\s+/,
148 MacPerl::Ask('Provide command-line args here (-h for help):')
149 if $Is_MacOS && $MacPerl::Version =~ /App/;
151 if (!getopts("Adhva:s:b:f:F:r:e:SCc:to:n:")) { Help(); exit; };
153 # This comment is needed to notify metaconfig that we are
154 # using the $perladmin, $cf_by, and $cf_time definitions.
156 # -------- Configuration ---------
158 # perlbug address
159 $perlbug = 'perlbug@perl.org';
161 # Test address
162 $testaddress = 'perlbug-test@perl.com';
164 # Target address
165 $address = $::opt_a || ($::opt_t ? $testaddress : $perlbug);
167 # Users address, used in message and in Reply-To header
168 $from = $::opt_r || "";
170 # Include verbose configuration information
171 $verbose = $::opt_v || 0;
173 # Subject of bug-report message
174 $subject = $::opt_s || "";
176 # Send a file
177 $usefile = ($::opt_f || 0);
179 # File to send as report
180 $file = $::opt_f || "";
182 # File to output to
183 $outfile = $::opt_F || "";
185 # Body of report
186 $body = $::opt_b || "";
188 # Editor
189 $ed = $::opt_e || $ENV{VISUAL} || $ENV{EDITOR} || $ENV{EDIT}
190 || ($Is_VMS && "edit/tpu")
191 || ($Is_MSWin32 && "notepad")
192 || ($Is_MacOS && '')
193 || "vi";
195 # Not OK - provide build failure template by finessing OK report
196 if ($::opt_n) {
197 if (substr($::opt_n, 0, 2) eq 'ok' ) {
198 $::opt_o = substr($::opt_n, 1);
199 } else {
200 Help();
201 exit();
205 # OK - send "OK" report for build on this system
206 $ok = 0;
207 if ($::opt_o) {
208 if ($::opt_o eq 'k' or $::opt_o eq 'kay') {
209 my $age = time - $patchlevel_date;
210 if ($::opt_o eq 'k' and $age > 60 * 24 * 60 * 60 ) {
211 my $date = localtime $patchlevel_date;
212 print <<"EOF";
213 "perlbug -ok" and "perlbug -nok" do not report on Perl versions which
214 are more than 60 days old. This Perl version was constructed on
215 $date. If you really want to report this, use
216 "perlbug -okay" or "perlbug -nokay".
218 exit();
220 # force these options
221 unless ($::opt_n) {
222 $::opt_S = 1; # don't prompt for send
223 $::opt_b = 1; # we have a body
224 $body = "Perl reported to build OK on this system.\n";
226 $::opt_C = 1; # don't send a copy to the local admin
227 $::opt_s = 1; # we have a subject line
228 $subject = ($::opt_n ? 'Not ' : '')
229 . "OK: perl $perl_version ${patch_tags}on"
230 ." $::Config{'archname'} $::Config{'osvers'} $subject";
231 $ok = 1;
232 } else {
233 Help();
234 exit();
238 # Possible administrator addresses, in order of confidence
239 # (Note that cf_email is not mentioned to metaconfig, since
240 # we don't really want it. We'll just take it if we have to.)
242 # This has to be after the $ok stuff above because of the way
243 # that $::opt_C is forced.
244 $cc = $::opt_C ? "" : (
245 $::opt_c || $::Config{'perladmin'}
246 || $::Config{'cf_email'} || $::Config{'cf_by'}
249 # My username
250 $me = $Is_MSWin32 ? $ENV{'USERNAME'}
251 : $^O eq 'os2' ? $ENV{'USER'} || $ENV{'LOGNAME'}
252 : $Is_MacOS ? $ENV{'USER'}
253 : eval { getpwuid($<) }; # May be missing
255 $from = $::Config{'cf_email'}
256 if !$from && $::Config{'cf_email'} && $::Config{'cf_by'} && $me &&
257 ($me eq $::Config{'cf_by'});
258 } # sub Init
260 sub Query {
261 # Explain what perlbug is
262 unless ($ok) {
263 paraprint <<EOF;
264 This program provides an easy way to create a message reporting a bug
265 in perl, and e-mail it to $address. It is *NOT* intended for
266 sending test messages or simply verifying that perl works, *NOR* is it
267 intended for reporting bugs in third-party perl modules. It is *ONLY*
268 a means of reporting verifiable problems with the core perl distribution,
269 and any solutions to such problems, to the people who maintain perl.
271 If you're just looking for help with perl, try posting to the Usenet
272 newsgroup comp.lang.perl.misc. If you're looking for help with using
273 perl with CGI, try posting to comp.infosystems.www.programming.cgi.
277 # Prompt for subject of message, if needed
278 unless ($subject) {
279 paraprint <<EOF;
280 First of all, please provide a subject for the
281 message. It should be a concise description of
282 the bug or problem. "perl bug" or "perl problem"
283 is not a concise description.
285 print "Subject: ";
286 $subject = <>;
288 my $err = 0;
289 while ($subject !~ /\S/) {
290 print "\nPlease enter a subject: ";
291 $subject = <>;
292 if ($err++ > 5) {
293 die "Aborting.\n";
296 chop $subject;
299 # Prompt for return address, if needed
300 unless ($from) {
301 # Try and guess return address
302 my $guess;
304 $guess = $ENV{'REPLY-TO'} || $ENV{'REPLYTO'} || '';
305 if ($Is_MacOS) {
306 require Mac::InternetConfig;
307 $guess = $Mac::InternetConfig::InternetConfig{
308 Mac::InternetConfig::kICEmail()
312 unless ($guess) {
313 my $domain;
314 if ($::HaveUtil) {
315 $domain = Mail::Util::maildomain();
316 } elsif ($Is_MSWin32) {
317 $domain = $ENV{'USERDOMAIN'};
318 } else {
319 require Sys::Hostname;
320 $domain = Sys::Hostname::hostname();
322 if ($domain) {
323 if ($Is_VMS && !$::Config{'d_socket'}) {
324 $guess = "$domain\:\:$me";
325 } else {
326 $guess = "$me\@$domain" if $domain;
331 if ($guess) {
332 unless ($ok) {
333 paraprint <<EOF;
334 Your e-mail address will be useful if you need to be contacted. If the
335 default shown is not your full internet e-mail address, please correct it.
338 } else {
339 paraprint <<EOF;
340 So that you may be contacted if necessary, please enter
341 your full internet e-mail address here.
345 if ($ok && $guess) {
346 # use it
347 $from = $guess;
348 } else {
349 # verify it
350 print "Your address [$guess]: ";
351 $from = <>;
352 chop $from;
353 $from = $guess if $from eq '';
357 if ($from eq $cc or $me eq $cc) {
358 # Try not to copy ourselves
359 $cc = "yourself";
362 # Prompt for administrator address, unless an override was given
363 if( !$::opt_C and !$::opt_c ) {
364 paraprint <<EOF;
365 A copy of this report can be sent to your local
366 perl administrator. If the address is wrong, please
367 correct it, or enter 'none' or 'yourself' to not send
368 a copy.
370 print "Local perl administrator [$cc]: ";
371 my $entry = scalar <>;
372 chop $entry;
374 if ($entry ne "") {
375 $cc = $entry;
376 $cc = '' if $me eq $cc;
380 $cc = '' if $cc =~ /^(none|yourself|me|myself|ourselves)$/i;
381 $andcc = " and $cc" if $cc;
383 # Prompt for editor, if no override is given
384 editor:
385 unless ($::opt_e || $::opt_f || $::opt_b) {
386 paraprint <<EOF;
387 Now you need to supply the bug report. Try to make
388 the report concise but descriptive. Include any
389 relevant detail. If you are reporting something
390 that does not work as you think it should, please
391 try to include example of both the actual
392 result, and what you expected.
394 Some information about your local
395 perl configuration will automatically be included
396 at the end of the report. If you are using any
397 unusual version of perl, please try and confirm
398 exactly which versions are relevant.
400 You will probably want to use an editor to enter
401 the report. If "$ed" is the editor you want
402 to use, then just press Enter, otherwise type in
403 the name of the editor you would like to use.
405 If you would like to use a prepared file, type
406 "file", and you will be asked for the filename.
408 print "Editor [$ed]: ";
409 my $entry =scalar <>;
410 chop $entry;
412 $usefile = 0;
413 if ($entry eq "file") {
414 $usefile = 1;
415 } elsif ($entry ne "") {
416 $ed = $entry;
420 # Prompt for category of bug
421 $category ||= ask_for_alternatives('category');
423 # Prompt for severity of bug
424 $severity ||= ask_for_alternatives('severity');
426 # Generate scratch file to edit report in
427 $filename = filename();
429 # Prompt for file to read report from, if needed
430 if ($usefile and !$file) {
431 filename:
432 paraprint <<EOF;
433 What is the name of the file that contains your report?
435 print "Filename: ";
436 my $entry = scalar <>;
437 chop $entry;
439 if ($entry eq "") {
440 paraprint <<EOF;
441 No filename? I'll let you go back and choose an editor again.
443 goto editor;
446 unless (-f $entry and -r $entry) {
447 paraprint <<EOF;
448 I'm sorry, but I can't read from `$entry'. Maybe you mistyped the name of
449 the file? If you don't want to send a file, just enter a blank line and you
450 can get back to the editor selection.
452 goto filename;
454 $file = $entry;
457 # Generate report
458 open(REP,">$filename") or die "Unable to create report file `$filename': $!\n";
459 my $reptype = !$ok ? "bug" : $::opt_n ? "build failure" : "success";
461 print REP <<EOF;
462 This is a $reptype report for perl from $from,
463 generated with the help of perlbug $Version running under perl $perl_version.
467 if ($body) {
468 print REP $body;
469 } elsif ($usefile) {
470 open(F, "<$file")
471 or die "Unable to read report file from `$file': $!\n";
472 while (<F>) {
473 print REP $_
475 close(F) or die "Error closing `$file': $!";
476 } else {
477 print REP <<EOF;
479 -----------------------------------------------------------------
480 [Please enter your report here]
484 [Please do not change anything below this line]
485 -----------------------------------------------------------------
488 Dump(*REP);
489 close(REP) or die "Error closing report file: $!";
491 # read in the report template once so that
492 # we can track whether the user does any editing.
493 # yes, *all* whitespace is ignored.
494 open(REP, "<$filename") or die "Unable to open report file `$filename': $!\n";
495 while (<REP>) {
496 s/\s+//g;
497 $REP{$_}++;
499 close(REP) or die "Error closing report file `$filename': $!";
500 } # sub Query
502 sub Dump {
503 local(*OUT) = @_;
505 print OUT <<EFF;
507 Flags:
508 category=$category
509 severity=$severity
511 if ($::opt_A) {
512 print OUT <<EFF;
513 ack=no
516 print OUT <<EFF;
519 print OUT "This perlbug was built using Perl $config_tag1\n",
520 "It is being executed now by Perl $config_tag2.\n\n"
521 if $config_tag2 ne $config_tag1;
523 print OUT <<EOF;
524 Site configuration information for perl $perl_version:
527 if ($::Config{cf_by} and $::Config{cf_time}) {
528 print OUT "Configured by $::Config{cf_by} at $::Config{cf_time}.\n\n";
530 print OUT Config::myconfig;
532 if (@patches) {
533 print OUT join "\n ", "Locally applied patches:", @patches;
534 print OUT "\n";
537 print OUT <<EOF;
540 \@INC for perl $perl_version:
542 for my $i (@INC) {
543 print OUT " $i\n";
546 print OUT <<EOF;
549 Environment for perl $perl_version:
551 my @env =
552 qw(PATH LD_LIBRARY_PATH LANG PERL_BADLANG SHELL HOME LOGDIR LANGUAGE);
553 push @env, $Config{ldlibpthname} if $Config{ldlibpthname} ne '';
554 push @env, grep /^(?:PERL|LC_|LANG)/, keys %ENV;
555 my %env;
556 @env{@env} = @env;
557 for my $env (sort keys %env) {
558 print OUT " $env",
559 exists $ENV{$env} ? "=$ENV{$env}" : ' (unset)',
560 "\n";
562 if ($verbose) {
563 print OUT "\nComplete configuration data for perl $perl_version:\n\n";
564 my $value;
565 foreach (sort keys %::Config) {
566 $value = $::Config{$_};
567 $value =~ s/'/\\'/g;
568 print OUT "$_='$value'\n";
571 } # sub Dump
573 sub Edit {
574 # Edit the report
575 if ($usefile || $body) {
576 paraprint <<EOF;
577 Please make sure that the name of the editor you want to use is correct.
579 print "Editor [$ed]: ";
580 my $entry =scalar <>;
581 chop $entry;
582 $ed = $entry unless $entry eq '';
585 tryagain:
586 my $sts;
587 $sts = system("$ed $filename") unless $Is_MacOS;
588 if ($Is_MacOS) {
589 require ExtUtils::MakeMaker;
590 ExtUtils::MM_MacOS::launch_file($filename);
591 paraprint <<EOF;
592 Press Enter when done.
594 scalar <>;
596 if ($sts) {
597 paraprint <<EOF;
598 The editor you chose (`$ed') could apparently not be run!
599 Did you mistype the name of your editor? If so, please
600 correct it here, otherwise just press Enter.
602 print "Editor [$ed]: ";
603 my $entry =scalar <>;
604 chop $entry;
606 if ($entry ne "") {
607 $ed = $entry;
608 goto tryagain;
609 } else {
610 paraprint <<EOF;
611 You may want to save your report to a file, so you can edit and mail it
612 yourself.
617 return if ($ok and not $::opt_n) || $body;
618 # Check that we have a report that has some, eh, report in it.
619 my $unseen = 0;
621 open(REP, "<$filename") or die "Couldn't open `$filename': $!\n";
622 # a strange way to check whether any significant editing
623 # have been done: check whether any new non-empty lines
624 # have been added. Yes, the below code ignores *any* space
625 # in *any* line.
626 while (<REP>) {
627 s/\s+//g;
628 $unseen++ if $_ ne '' and not exists $REP{$_};
631 while ($unseen == 0) {
632 paraprint <<EOF;
633 I am sorry but it looks like you did not report anything.
635 print "Action (Retry Edit/Cancel) ";
636 my ($action) = scalar(<>);
637 if ($action =~ /^[re]/i) { # <R>etry <E>dit
638 goto tryagain;
639 } elsif ($action =~ /^[cq]/i) { # <C>ancel, <Q>uit
640 Cancel();
643 } # sub Edit
645 sub Cancel {
646 1 while unlink($filename); # remove all versions under VMS
647 print "\nCancelling.\n";
648 exit(0);
651 sub NowWhat {
652 # Report is done, prompt for further action
653 if( !$::opt_S ) {
654 while(1) {
655 paraprint <<EOF;
656 Now that you have completed your report, would you like to send
657 the message to $address$andcc, display the message on
658 the screen, re-edit it, or cancel without sending anything?
659 You may also save the message as a file to mail at another time.
661 retry:
662 print "Action (Send/Display/Edit/Cancel/Save to File): ";
663 my $action = scalar <>;
664 chop $action;
666 if ($action =~ /^(f|sa)/i) { # <F>ile/<Sa>ve
667 print "\n\nName of file to save message in [perlbug.rep]: ";
668 my $file = scalar <>;
669 chop $file;
670 $file = "perlbug.rep" if $file eq "";
672 unless (open(FILE, ">$file")) {
673 print "\nError opening $file: $!\n\n";
674 goto retry;
676 open(REP, "<$filename") or die "Couldn't open file `$filename': $!\n";
677 print FILE "To: $address\nSubject: $subject\n";
678 print FILE "Cc: $cc\n" if $cc;
679 print FILE "Reply-To: $from\n" if $from;
680 print FILE "\n";
681 while (<REP>) { print FILE }
682 close(REP) or die "Error closing report file `$filename': $!";
683 close(FILE) or die "Error closing $file: $!";
685 print "\nMessage saved in `$file'.\n";
686 exit;
687 } elsif ($action =~ /^(d|l|sh)/i ) { # <D>isplay, <L>ist, <Sh>ow
688 # Display the message
689 open(REP, "<$filename") or die "Couldn't open file `$filename': $!\n";
690 while (<REP>) { print $_ }
691 close(REP) or die "Error closing report file `$filename': $!";
692 } elsif ($action =~ /^se/i) { # <S>end
693 # Send the message
694 print "Are you certain you want to send this message?\n"
695 . 'Please type "yes" if you are: ';
696 my $reply = scalar <STDIN>;
697 chop $reply;
698 if ($reply eq "yes") {
699 last;
700 } else {
701 paraprint <<EOF;
702 That wasn't a clear "yes", so I won't send your message. If you are sure
703 your message should be sent, type in "yes" (without the quotes) at the
704 confirmation prompt.
707 } elsif ($action =~ /^[er]/i) { # <E>dit, <R>e-edit
708 # edit the message
709 Edit();
710 } elsif ($action =~ /^[qc]/i) { # <C>ancel, <Q>uit
711 Cancel();
712 } elsif ($action =~ /^s/i) {
713 paraprint <<EOF;
714 I'm sorry, but I didn't understand that. Please type "send" or "save".
719 } # sub NowWhat
721 sub Send {
722 # Message has been accepted for transmission -- Send the message
723 if ($outfile) {
724 open SENDMAIL, ">$outfile" or die "Couldn't open '$outfile': $!\n";
725 goto sendout;
727 if ($::HaveSend) {
728 $msg = new Mail::Send Subject => $subject, To => $address;
729 $msg->cc($cc) if $cc;
730 $msg->add("Reply-To",$from) if $from;
732 $fh = $msg->open;
733 open(REP, "<$filename") or die "Couldn't open `$filename': $!\n";
734 while (<REP>) { print $fh $_ }
735 close(REP) or die "Error closing $filename: $!";
736 $fh->close;
738 print "\nMessage sent.\n";
739 } elsif ($Is_VMS) {
740 if ( ($address =~ /@/ and $address !~ /^\w+%"/) or
741 ($cc =~ /@/ and $cc !~ /^\w+%"/) ) {
742 my $prefix;
743 foreach (qw[ IN MX SMTP UCX PONY WINS ], '') {
744 $prefix = "$_%", last if $ENV{"MAIL\$PROTOCOL_$_"};
746 $address = qq[${prefix}"$address"] unless $address =~ /^\w+%"/;
747 $cc = qq[${prefix}"$cc"] unless !$cc || $cc =~ /^\w+%"/;
749 $subject =~ s/"/""/g; $address =~ s/"/""/g; $cc =~ s/"/""/g;
750 my $sts = system(qq[mail/Subject="$subject" $filename. "$address","$cc"]);
751 if ($sts) {
752 die <<EOF;
753 Can't spawn off mail
754 (leaving bug report in $filename): $sts
757 } else {
758 my $sendmail = "";
759 for (qw(/usr/lib/sendmail /usr/sbin/sendmail /usr/ucblib/sendmail)) {
760 $sendmail = $_, last if -e $_;
762 if ($^O eq 'os2' and $sendmail eq "") {
763 my $path = $ENV{PATH};
764 $path =~ s:\\:/: ;
765 my @path = split /$Config{'path_sep'}/, $path;
766 for (@path) {
767 $sendmail = "$_/sendmail", last if -e "$_/sendmail";
768 $sendmail = "$_/sendmail.exe", last if -e "$_/sendmail.exe";
772 paraprint(<<"EOF"), die "\n" if $sendmail eq "";
773 I am terribly sorry, but I cannot find sendmail, or a close equivalent, and
774 the perl package Mail::Send has not been installed, so I can't send your bug
775 report. We apologize for the inconvenience.
777 So you may attempt to find some way of sending your message, it has
778 been left in the file `$filename'.
780 open(SENDMAIL, "|$sendmail -t -oi") || die "'|$sendmail -t -oi' failed: $!";
781 sendout:
782 print SENDMAIL "To: $address\n";
783 print SENDMAIL "Subject: $subject\n";
784 print SENDMAIL "Cc: $cc\n" if $cc;
785 print SENDMAIL "Reply-To: $from\n" if $from;
786 print SENDMAIL "\n\n";
787 open(REP, "<$filename") or die "Couldn't open `$filename': $!\n";
788 while (<REP>) { print SENDMAIL $_ }
789 close(REP) or die "Error closing $filename: $!";
791 if (close(SENDMAIL)) {
792 printf "\nMessage %s.\n", $outfile ? "saved" : "sent";
793 } else {
794 warn "\nSendmail returned status '", $? >> 8, "'\n";
797 1 while unlink($filename); # remove all versions under VMS
798 } # sub Send
800 sub Help {
801 print <<EOF;
803 A program to help generate bug reports about perl5, and mail them.
804 It is designed to be used interactively. Normally no arguments will
805 be needed.
807 Usage:
808 $0 [-v] [-a address] [-s subject] [-b body | -f inpufile ] [ -F outputfile ]
809 [-r returnaddress] [-e editor] [-c adminaddress | -C] [-S] [-t] [-h]
810 $0 [-v] [-r returnaddress] [-A] [-ok | -okay | -nok | -nokay]
812 Simplest usage: run "$0", and follow the prompts.
814 Options:
816 -v Include Verbose configuration data in the report
817 -f File containing the body of the report. Use this to
818 quickly send a prepared message.
819 -F File to output the resulting mail message to, instead of mailing.
820 -S Send without asking for confirmation.
821 -a Address to send the report to. Defaults to `$address'.
822 -c Address to send copy of report to. Defaults to `$cc'.
823 -C Don't send copy to administrator.
824 -s Subject to include with the message. You will be prompted
825 if you don't supply one on the command line.
826 -b Body of the report. If not included on the command line, or
827 in a file with -f, you will get a chance to edit the message.
828 -r Your return address. The program will ask you to confirm
829 this if you don't give it here.
830 -e Editor to use.
831 -t Test mode. The target address defaults to `$testaddress'.
832 -d Data mode. This prints out your configuration data, without mailing
833 anything. You can use this with -v to get more complete data.
834 -A Don't send a bug received acknowledgement to the return address.
835 -ok Report successful build on this system to perl porters
836 (use alone or with -v). Only use -ok if *everything* was ok:
837 if there were *any* problems at all, use -nok.
838 -okay As -ok but allow report from old builds.
839 -nok Report unsuccessful build on this system to perl porters
840 (use alone or with -v). You must describe what went wrong
841 in the body of the report which you will be asked to edit.
842 -nokay As -nok but allow report from old builds.
843 -h Print this help message.
848 sub filename {
849 my $dir = File::Spec->tmpdir();
850 $filename = "bugrep0$$";
851 $filename++ while -e File::Spec->catfile($dir, $filename);
852 $filename = File::Spec->catfile($dir, $filename);
855 sub paraprint {
856 my @paragraphs = split /\n{2,}/, "@_";
857 print "\n\n";
858 for (@paragraphs) { # implicit local $_
859 s/(\S)\s*\n/$1 /g;
860 write;
861 print "\n";
865 format STDOUT =
866 ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ~~
870 __END__
872 =head1 NAME
874 perlbug - how to submit bug reports on Perl
876 =head1 SYNOPSIS
878 B<perlbug> S<[ B<-v> ]> S<[ B<-a> I<address> ]> S<[ B<-s> I<subject> ]>
879 S<[ B<-b> I<body> | B<-f> I<inputfile> ]> S<[ B<-F> I<outputfile> ]>
880 S<[ B<-r> I<returnaddress> ]>
881 S<[ B<-e> I<editor> ]> S<[ B<-c> I<adminaddress> | B<-C> ]>
882 S<[ B<-S> ]> S<[ B<-t> ]> S<[ B<-d> ]> S<[ B<-A> ]> S<[ B<-h> ]>
884 B<perlbug> S<[ B<-v> ]> S<[ B<-r> I<returnaddress> ]>
885 S<[ B<-A> ]> S<[ B<-ok> | B<-okay> | B<-nok> | B<-nokay> ]>
887 =head1 DESCRIPTION
889 A program to help generate bug reports about perl or the modules that
890 come with it, and mail them.
892 If you have found a bug with a non-standard port (one that was not part
893 of the I<standard distribution>), a binary distribution, or a
894 non-standard module (such as Tk, CGI, etc), then please see the
895 documentation that came with that distribution to determine the correct
896 place to report bugs.
898 C<perlbug> is designed to be used interactively. Normally no arguments
899 will be needed. Simply run it, and follow the prompts.
901 If you are unable to run B<perlbug> (most likely because you don't have
902 a working setup to send mail that perlbug recognizes), you may have to
903 compose your own report, and email it to B<perlbug@perl.org>. You might
904 find the B<-d> option useful to get summary information in that case.
906 In any case, when reporting a bug, please make sure you have run through
907 this checklist:
909 =over 4
911 =item What version of Perl you are running?
913 Type C<perl -v> at the command line to find out.
915 =item Are you running the latest released version of perl?
917 Look at http://www.perl.com/ to find out. If it is not the latest
918 released version, get that one and see whether your bug has been
919 fixed. Note that bug reports about old versions of Perl, especially
920 those prior to the 5.0 release, are likely to fall upon deaf ears.
921 You are on your own if you continue to use perl1 .. perl4.
923 =item Are you sure what you have is a bug?
925 A significant number of the bug reports we get turn out to be documented
926 features in Perl. Make sure the behavior you are witnessing doesn't fall
927 under that category, by glancing through the documentation that comes
928 with Perl (we'll admit this is no mean task, given the sheer volume of
929 it all, but at least have a look at the sections that I<seem> relevant).
931 Be aware of the familiar traps that perl programmers of various hues
932 fall into. See L<perltrap>.
934 Check in L<perldiag> to see what any Perl error message(s) mean.
935 If message isn't in perldiag, it probably isn't generated by Perl.
936 Consult your operating system documentation instead.
938 If you are on a non-UNIX platform check also L<perlport>, as some
939 features may be unimplemented or work differently.
941 Try to study the problem under the Perl debugger, if necessary.
942 See L<perldebug>.
944 =item Do you have a proper test case?
946 The easier it is to reproduce your bug, the more likely it will be
947 fixed, because if no one can duplicate the problem, no one can fix it.
948 A good test case has most of these attributes: fewest possible number
949 of lines; few dependencies on external commands, modules, or
950 libraries; runs on most platforms unimpeded; and is self-documenting.
952 A good test case is almost always a good candidate to be on the perl
953 test suite. If you have the time, consider making your test case so
954 that it will readily fit into the standard test suite.
956 Remember also to include the B<exact> error messages, if any.
957 "Perl complained something" is not an exact error message.
959 If you get a core dump (or equivalent), you may use a debugger
960 (B<dbx>, B<gdb>, etc) to produce a stack trace to include in the bug
961 report. NOTE: unless your Perl has been compiled with debug info
962 (often B<-g>), the stack trace is likely to be somewhat hard to use
963 because it will most probably contain only the function names and not
964 their arguments. If possible, recompile your Perl with debug info and
965 reproduce the dump and the stack trace.
967 =item Can you describe the bug in plain English?
969 The easier it is to understand a reproducible bug, the more likely it
970 will be fixed. Anything you can provide by way of insight into the
971 problem helps a great deal. In other words, try to analyze the
972 problem (to the extent you can) and report your discoveries.
974 =item Can you fix the bug yourself?
976 A bug report which I<includes a patch to fix it> will almost
977 definitely be fixed. Use the C<diff> program to generate your patches
978 (C<diff> is being maintained by the GNU folks as part of the B<diffutils>
979 package, so you should be able to get it from any of the GNU software
980 repositories). If you do submit a patch, the cool-dude counter at
981 perlbug@perl.org will register you as a savior of the world. Your
982 patch may be returned with requests for changes, or requests for more
983 detailed explanations about your fix.
985 Here are some clues for creating quality patches: Use the B<-c> or
986 B<-u> switches to the diff program (to create a so-called context or
987 unified diff). Make sure the patch is not reversed (the first
988 argument to diff is typically the original file, the second argument
989 your changed file). Make sure you test your patch by applying it with
990 the C<patch> program before you send it on its way. Try to follow the
991 same style as the code you are trying to patch. Make sure your patch
992 really does work (C<make test>, if the thing you're patching supports
993 it).
995 =item Can you use C<perlbug> to submit the report?
997 B<perlbug> will, amongst other things, ensure your report includes
998 crucial information about your version of perl. If C<perlbug> is unable
999 to mail your report after you have typed it in, you may have to compose
1000 the message yourself, add the output produced by C<perlbug -d> and email
1001 it to B<perlbug@perl.org>. If, for some reason, you cannot run
1002 C<perlbug> at all on your system, be sure to include the entire output
1003 produced by running C<perl -V> (note the uppercase V).
1005 Whether you use C<perlbug> or send the email manually, please make
1006 your Subject line informative. "a bug" not informative. Neither is
1007 "perl crashes" nor "HELP!!!". These don't help.
1008 A compact description of what's wrong is fine.
1010 =back
1012 Having done your bit, please be prepared to wait, to be told the bug
1013 is in your code, or even to get no reply at all. The Perl maintainers
1014 are busy folks, so if your problem is a small one or if it is difficult
1015 to understand or already known, they may not respond with a personal reply.
1016 If it is important to you that your bug be fixed, do monitor the
1017 C<Changes> file in any development releases since the time you submitted
1018 the bug, and encourage the maintainers with kind words (but never any
1019 flames!). Feel free to resend your bug report if the next released
1020 version of perl comes out and your bug is still present.
1022 =head1 OPTIONS
1024 =over 8
1026 =item B<-a>
1028 Address to send the report to. Defaults to `perlbug@perl.org'.
1030 =item B<-A>
1032 Don't send a bug received acknowledgement to the reply address.
1033 Generally it is only a sensible to use this option if you are a
1034 perl maintainer actively watching perl porters for your message to
1035 arrive.
1037 =item B<-b>
1039 Body of the report. If not included on the command line, or
1040 in a file with B<-f>, you will get a chance to edit the message.
1042 =item B<-C>
1044 Don't send copy to administrator.
1046 =item B<-c>
1048 Address to send copy of report to. Defaults to the address of the
1049 local perl administrator (recorded when perl was built).
1051 =item B<-d>
1053 Data mode (the default if you redirect or pipe output). This prints out
1054 your configuration data, without mailing anything. You can use this
1055 with B<-v> to get more complete data.
1057 =item B<-e>
1059 Editor to use.
1061 =item B<-f>
1063 File containing the body of the report. Use this to quickly send a
1064 prepared message.
1066 =item B<-F>
1068 File to output the results to instead of sending as an email. Useful
1069 particularly when running perlbug on a machine with no direct internet
1070 connection.
1072 =item B<-h>
1074 Prints a brief summary of the options.
1076 =item B<-ok>
1078 Report successful build on this system to perl porters. Forces B<-S>
1079 and B<-C>. Forces and supplies values for B<-s> and B<-b>. Only
1080 prompts for a return address if it cannot guess it (for use with
1081 B<make>). Honors return address specified with B<-r>. You can use this
1082 with B<-v> to get more complete data. Only makes a report if this
1083 system is less than 60 days old.
1085 =item B<-okay>
1087 As B<-ok> except it will report on older systems.
1089 =item B<-nok>
1091 Report unsuccessful build on this system. Forces B<-C>. Forces and
1092 supplies a value for B<-s>, then requires you to edit the report
1093 and say what went wrong. Alternatively, a prepared report may be
1094 supplied using B<-f>. Only prompts for a return address if it
1095 cannot guess it (for use with B<make>). Honors return address
1096 specified with B<-r>. You can use this with B<-v> to get more
1097 complete data. Only makes a report if this system is less than 60
1098 days old.
1100 =item B<-nokay>
1102 As B<-nok> except it will report on older systems.
1104 =item B<-r>
1106 Your return address. The program will ask you to confirm its default
1107 if you don't use this option.
1109 =item B<-S>
1111 Send without asking for confirmation.
1113 =item B<-s>
1115 Subject to include with the message. You will be prompted if you don't
1116 supply one on the command line.
1118 =item B<-t>
1120 Test mode. The target address defaults to `perlbug-test@perl.com'.
1122 =item B<-v>
1124 Include verbose configuration data in the report.
1126 =back
1128 =head1 AUTHORS
1130 Kenneth Albanowski (E<lt>kjahds@kjahds.comE<gt>), subsequently I<doc>tored
1131 by Gurusamy Sarathy (E<lt>gsar@activestate.comE<gt>), Tom Christiansen
1132 (E<lt>tchrist@perl.comE<gt>), Nathan Torkington (E<lt>gnat@frii.comE<gt>),
1133 Charles F. Randall (E<lt>cfr@pobox.comE<gt>), Mike Guy
1134 (E<lt>mjtg@cam.a.ukE<gt>), Dominic Dunlop (E<lt>domo@computer.orgE<gt>),
1135 Hugo van der Sanden (E<lt>hv@crypt0.demon.co.ukE<gt>),
1136 Jarkko Hietaniemi (E<lt>jhi@iki.fiE<gt>), Chris Nandor
1137 (E<lt>pudge@pobox.comE<gt>), Jon Orwant (E<lt>orwant@media.mit.eduE<gt>,
1138 and Richard Foley (E<lt>richard@rfi.netE<gt>).
1140 =head1 SEE ALSO
1142 perl(1), perldebug(1), perldiag(1), perlport(1), perltrap(1),
1143 diff(1), patch(1), dbx(1), gdb(1)
1145 =head1 BUGS
1147 None known (guess what must have been used to report them?)
1149 =cut