WinGit: do not add uninstaller to the start menu
[msysgit/mtrensch.git] / bin / perlbug
blob4174f39cfe8d8d208877437ee3c1f80b38b7f311
1 #!/usr/bin/perl
2 eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
3 if $running_under_some_shell;
5 my $config_tag1 = 'v5.8.8 - Wed Jan 16 13:15:16 GMTST 2008';
7 my $patchlevel_date = 1138723930;
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 "");
25 # use secure tempfiles wherever possible
26 eval "require File::Temp;";
27 $::HaveTemp = ($@ eq "");
30 my $Version = "1.35";
32 # Changed in 1.06 to skip Mail::Send and Mail::Util if not available.
33 # Changed in 1.07 to see more sendmail execs, and added pipe output.
34 # Changed in 1.08 to use correct address for sendmail.
35 # Changed in 1.09 to close the REP file before calling it up in the editor.
36 # Also removed some old comments duplicated elsewhere.
37 # Changed in 1.10 to run under VMS without Mail::Send; also fixed
38 # temp filename generation.
39 # Changed in 1.11 to clean up some text and removed Mail::Send deactivator.
40 # Changed in 1.12 to check for editor errors, make save/send distinction
41 # clearer and add $ENV{REPLYTO}.
42 # Changed in 1.13 to hopefully make it more difficult to accidentally
43 # send mail
44 # Changed in 1.14 to make the prompts a little more clear on providing
45 # helpful information. Also let file read fail gracefully.
46 # Changed in 1.15 to add warnings to stop people using perlbug for non-bugs.
47 # Also report selected environment variables.
48 # Changed in 1.16 to include @INC, and allow user to re-edit if no changes.
49 # Changed in 1.17 Win32 support added. GSAR 97-04-12
50 # Changed in 1.18 add '-ok' option for reporting build success. CFR 97-06-18
51 # Changed in 1.19 '-ok' default not '-v'
52 # add local patch information
53 # warn on '-ok' if this is an old system; add '-okay'
54 # Changed in 1.20 Added patchlevel.h reading and version/config checks
55 # Changed in 1.21 Added '-nok' for reporting build failure DFD 98-05-05
56 # Changed in 1.22 Heavy reformatting & minor bugfixes HVDS 98-05-10
57 # Changed in 1.23 Restore -ok(ay): say 'success'; don't prompt
58 # Changed in 1.24 Added '-F<file>' to save report HVDS 98-07-01
59 # Changed in 1.25 Warn on failure to open save file. HVDS 98-07-12
60 # Changed in 1.26 Don't require -t STDIN for -ok. HVDS 98-07-15
61 # Changed in 1.27 Added Mac OS and File::Spec support CNANDOR 99-07-27
62 # Changed in 1.28 Additional questions for Perlbugtron RFOLEY 20.03.2000
63 # Changed in 1.29 Perlbug(tron): auto(-ok), short prompts RFOLEY 05-05-2000
64 # Changed in 1.30 Added warnings on failure to open files MSTEVENS 13-07-2000
65 # Changed in 1.31 Add checks on close().Fix my $var unless. TJENNESS 26-07-2000
66 # Changed in 1.32 Use File::Spec->tmpdir TJENNESS 20-08-2000
67 # Changed in 1.33 Don't require -t STDOUT for -ok.
68 # Changed in 1.34 Added Message-Id RFOLEY 18-06-2002
69 # Changed in 1.35 Use File::Temp (patch from Solar Designer) NWCLARK 28-02-2004
71 # TODO: - Allow the user to re-name the file on mail failure, and
72 # make sure failure (transmission-wise) of Mail::Send is
73 # accounted for.
74 # - Test -b option
76 my( $file, $usefile, $cc, $address, $perlbug, $testaddress, $filename, $messageid, $domain,
77 $subject, $from, $verbose, $ed, $outfile, $Is_MacOS, $category, $severity,
78 $fh, $me, $Is_MSWin32, $Is_Linux, $Is_VMS, $msg, $body, $andcc, %REP, $ok,
79 $Is_OpenBSD);
81 my $perl_version = $^V ? sprintf("v%vd", $^V) : $];
83 my $config_tag2 = "$perl_version - $Config{cf_time}";
85 Init();
87 if ($::opt_h) { Help(); exit; }
88 if ($::opt_d) { Dump(*STDOUT); exit; }
89 if (!-t STDIN && !($ok and not $::opt_n)) {
90 paraprint <<EOF;
91 Please use perlbug interactively. If you want to
92 include a file, you can use the -f switch.
93 EOF
94 die "\n";
97 Query();
98 Edit() unless $usefile || ($ok and not $::opt_n);
99 NowWhat();
100 Send();
102 exit;
104 sub ask_for_alternatives { # (category|severity)
105 my $name = shift;
106 my %alts = (
107 'category' => {
108 'default' => 'core',
109 'ok' => 'install',
110 'opts' => [qw(core docs install library utilities)], # patch, notabug
112 'severity' => {
113 'default' => 'low',
114 'ok' => 'none',
115 'opts' => [qw(critical high medium low wishlist none)], # zero
118 die "Invalid alternative($name) requested\n" unless grep(/^$name$/, keys %alts);
119 my $alt = "";
120 if ($ok) {
121 $alt = $alts{$name}{'ok'};
122 } else {
123 my @alts = @{$alts{$name}{'opts'}};
124 paraprint <<EOF;
125 Please pick a \u$name from the following:
127 @alts
130 my $err = 0;
131 do {
132 if ($err++ > 5) {
133 die "Invalid $name: aborting.\n";
135 print "Please enter a \u$name [$alts{$name}{'default'}]: ";
136 $alt = <>;
137 chomp $alt;
138 if ($alt =~ /^\s*$/) {
139 $alt = $alts{$name}{'default'};
141 } while !((($alt) = grep(/^$alt/i, @alts)));
143 lc $alt;
146 sub Init {
147 # -------- Setup --------
149 $Is_MSWin32 = $^O eq 'MSWin32';
150 $Is_VMS = $^O eq 'VMS';
151 $Is_Linux = lc($^O) eq 'linux';
152 $Is_OpenBSD = lc($^O) eq 'openbsd';
153 $Is_MacOS = $^O eq 'MacOS';
155 @ARGV = split m/\s+/,
156 MacPerl::Ask('Provide command-line args here (-h for help):')
157 if $Is_MacOS && $MacPerl::Version =~ /App/;
159 if (!getopts("Adhva:s:b:f:F:r:e:SCc:to:n:")) { Help(); exit; };
161 # This comment is needed to notify metaconfig that we are
162 # using the $perladmin, $cf_by, and $cf_time definitions.
164 # -------- Configuration ---------
166 # perlbug address
167 $perlbug = 'perlbug@perl.org';
169 # Test address
170 $testaddress = 'perlbug-test@perl.org';
172 # Target address
173 $address = $::opt_a || ($::opt_t ? $testaddress : $perlbug);
175 # Users address, used in message and in Reply-To header
176 $from = $::opt_r || "";
178 # Include verbose configuration information
179 $verbose = $::opt_v || 0;
181 # Subject of bug-report message
182 $subject = $::opt_s || "";
184 # Send a file
185 $usefile = ($::opt_f || 0);
187 # File to send as report
188 $file = $::opt_f || "";
190 # File to output to
191 $outfile = $::opt_F || "";
193 # Body of report
194 $body = $::opt_b || "";
196 # Editor
197 $ed = $::opt_e || $ENV{VISUAL} || $ENV{EDITOR} || $ENV{EDIT}
198 || ($Is_VMS && "edit/tpu")
199 || ($Is_MSWin32 && "notepad")
200 || ($Is_MacOS && '')
201 || "vi";
203 # Not OK - provide build failure template by finessing OK report
204 if ($::opt_n) {
205 if (substr($::opt_n, 0, 2) eq 'ok' ) {
206 $::opt_o = substr($::opt_n, 1);
207 } else {
208 Help();
209 exit();
213 # OK - send "OK" report for build on this system
214 $ok = 0;
215 if ($::opt_o) {
216 if ($::opt_o eq 'k' or $::opt_o eq 'kay') {
217 my $age = time - $patchlevel_date;
218 if ($::opt_o eq 'k' and $age > 60 * 24 * 60 * 60 ) {
219 my $date = localtime $patchlevel_date;
220 print <<"EOF";
221 "perlbug -ok" and "perlbug -nok" do not report on Perl versions which
222 are more than 60 days old. This Perl version was constructed on
223 $date. If you really want to report this, use
224 "perlbug -okay" or "perlbug -nokay".
226 exit();
228 # force these options
229 unless ($::opt_n) {
230 $::opt_S = 1; # don't prompt for send
231 $::opt_b = 1; # we have a body
232 $body = "Perl reported to build OK on this system.\n";
234 $::opt_C = 1; # don't send a copy to the local admin
235 $::opt_s = 1; # we have a subject line
236 $subject = ($::opt_n ? 'Not ' : '')
237 . "OK: perl $perl_version ${patch_tags}on"
238 ." $::Config{'archname'} $::Config{'osvers'} $subject";
239 $ok = 1;
240 } else {
241 Help();
242 exit();
246 # Possible administrator addresses, in order of confidence
247 # (Note that cf_email is not mentioned to metaconfig, since
248 # we don't really want it. We'll just take it if we have to.)
250 # This has to be after the $ok stuff above because of the way
251 # that $::opt_C is forced.
252 $cc = $::opt_C ? "" : (
253 $::opt_c || $::Config{'perladmin'}
254 || $::Config{'cf_email'} || $::Config{'cf_by'}
257 if ($::HaveUtil) {
258 $domain = Mail::Util::maildomain();
259 } elsif ($Is_MSWin32) {
260 $domain = $ENV{'USERDOMAIN'};
261 } else {
262 require Sys::Hostname;
263 $domain = Sys::Hostname::hostname();
266 # Message-Id - rjsf
267 $messageid = "<$::Config{'version'}_${$}_".time."\@$domain>";
269 # My username
270 $me = $Is_MSWin32 ? $ENV{'USERNAME'}
271 : $^O eq 'os2' ? $ENV{'USER'} || $ENV{'LOGNAME'}
272 : $Is_MacOS ? $ENV{'USER'}
273 : eval { getpwuid($<) }; # May be missing
275 $from = $::Config{'cf_email'}
276 if !$from && $::Config{'cf_email'} && $::Config{'cf_by'} && $me &&
277 ($me eq $::Config{'cf_by'});
278 } # sub Init
280 sub Query {
281 # Explain what perlbug is
282 unless ($ok) {
283 paraprint <<EOF;
284 This program provides an easy way to create a message reporting a bug
285 in perl, and e-mail it to $address. It is *NOT* intended for
286 sending test messages or simply verifying that perl works, *NOR* is it
287 intended for reporting bugs in third-party perl modules. It is *ONLY*
288 a means of reporting verifiable problems with the core perl distribution,
289 and any solutions to such problems, to the people who maintain perl.
291 If you're just looking for help with perl, try posting to the Usenet
292 newsgroup comp.lang.perl.misc. If you're looking for help with using
293 perl with CGI, try posting to comp.infosystems.www.programming.cgi.
297 # Prompt for subject of message, if needed
299 if (TrivialSubject($subject)) {
300 $subject = '';
303 unless ($subject) {
304 paraprint <<EOF;
305 First of all, please provide a subject for the
306 message. It should be a concise description of
307 the bug or problem. "perl bug" or "perl problem"
308 is not a concise description.
311 my $err = 0;
312 do {
313 print "Subject: ";
314 $subject = <>;
315 chomp $subject;
316 if ($err++ == 5) {
317 die "Aborting.\n";
319 } while (TrivialSubject($subject));
322 # Prompt for return address, if needed
323 unless ($from) {
324 # Try and guess return address
325 my $guess;
327 $guess = $ENV{'REPLY-TO'} || $ENV{'REPLYTO'} || '';
328 if ($Is_MacOS) {
329 require Mac::InternetConfig;
330 $guess = $Mac::InternetConfig::InternetConfig{
331 Mac::InternetConfig::kICEmail()
335 unless ($guess) {
336 # move $domain to where we can use it elsewhere
337 if ($domain) {
338 if ($Is_VMS && !$::Config{'d_socket'}) {
339 $guess = "$domain\:\:$me";
340 } else {
341 $guess = "$me\@$domain" if $domain;
346 if ($guess) {
347 unless ($ok) {
348 paraprint <<EOF;
349 Your e-mail address will be useful if you need to be contacted. If the
350 default shown is not your full internet e-mail address, please correct it.
353 } else {
354 paraprint <<EOF;
355 So that you may be contacted if necessary, please enter
356 your full internet e-mail address here.
360 if ($ok && $guess) {
361 # use it
362 $from = $guess;
363 } else {
364 # verify it
365 print "Your address [$guess]: ";
366 $from = <>;
367 chomp $from;
368 $from = $guess if $from eq '';
372 if ($from eq $cc or $me eq $cc) {
373 # Try not to copy ourselves
374 $cc = "yourself";
377 # Prompt for administrator address, unless an override was given
378 if( !$::opt_C and !$::opt_c ) {
379 paraprint <<EOF;
380 A copy of this report can be sent to your local
381 perl administrator. If the address is wrong, please
382 correct it, or enter 'none' or 'yourself' to not send
383 a copy.
385 print "Local perl administrator [$cc]: ";
386 my $entry = scalar <>;
387 chomp $entry;
389 if ($entry ne "") {
390 $cc = $entry;
391 $cc = '' if $me eq $cc;
395 $cc = '' if $cc =~ /^(none|yourself|me|myself|ourselves)$/i;
396 $andcc = " and $cc" if $cc;
398 # Prompt for editor, if no override is given
399 editor:
400 unless ($::opt_e || $::opt_f || $::opt_b) {
401 paraprint <<EOF;
402 Now you need to supply the bug report. Try to make
403 the report concise but descriptive. Include any
404 relevant detail. If you are reporting something
405 that does not work as you think it should, please
406 try to include example of both the actual
407 result, and what you expected.
409 Some information about your local
410 perl configuration will automatically be included
411 at the end of the report. If you are using any
412 unusual version of perl, please try and confirm
413 exactly which versions are relevant.
415 You will probably want to use an editor to enter
416 the report. If "$ed" is the editor you want
417 to use, then just press Enter, otherwise type in
418 the name of the editor you would like to use.
420 If you would like to use a prepared file, type
421 "file", and you will be asked for the filename.
423 print "Editor [$ed]: ";
424 my $entry =scalar <>;
425 chomp $entry;
427 $usefile = 0;
428 if ($entry eq "file") {
429 $usefile = 1;
430 } elsif ($entry ne "") {
431 $ed = $entry;
435 # Prompt for category of bug
436 $category ||= ask_for_alternatives('category');
438 # Prompt for severity of bug
439 $severity ||= ask_for_alternatives('severity');
441 # Generate scratch file to edit report in
442 $filename = filename();
444 # Prompt for file to read report from, if needed
445 if ($usefile and !$file) {
446 filename:
447 paraprint <<EOF;
448 What is the name of the file that contains your report?
450 print "Filename: ";
451 my $entry = scalar <>;
452 chomp $entry;
454 if ($entry eq "") {
455 paraprint <<EOF;
456 No filename? I'll let you go back and choose an editor again.
458 goto editor;
461 unless (-f $entry and -r $entry) {
462 paraprint <<EOF;
463 I'm sorry, but I can't read from `$entry'. Maybe you mistyped the name of
464 the file? If you don't want to send a file, just enter a blank line and you
465 can get back to the editor selection.
467 goto filename;
469 $file = $entry;
472 # Generate report
473 open(REP,">$filename") or die "Unable to create report file `$filename': $!\n";
474 my $reptype = !$ok ? "bug" : $::opt_n ? "build failure" : "success";
476 print REP <<EOF;
477 This is a $reptype report for perl from $from,
478 generated with the help of perlbug $Version running under perl $perl_version.
482 if ($body) {
483 print REP $body;
484 } elsif ($usefile) {
485 open(F, "<$file")
486 or die "Unable to read report file from `$file': $!\n";
487 while (<F>) {
488 print REP $_
490 close(F) or die "Error closing `$file': $!";
491 } else {
492 print REP <<EOF;
494 -----------------------------------------------------------------
495 [Please enter your report here]
499 [Please do not change anything below this line]
500 -----------------------------------------------------------------
503 Dump(*REP);
504 close(REP) or die "Error closing report file: $!";
506 # read in the report template once so that
507 # we can track whether the user does any editing.
508 # yes, *all* whitespace is ignored.
509 open(REP, "<$filename") or die "Unable to open report file `$filename': $!\n";
510 while (<REP>) {
511 s/\s+//g;
512 $REP{$_}++;
514 close(REP) or die "Error closing report file `$filename': $!";
515 } # sub Query
517 sub Dump {
518 local(*OUT) = @_;
520 print OUT <<EFF;
522 Flags:
523 category=$category
524 severity=$severity
526 if ($::opt_A) {
527 print OUT <<EFF;
528 ack=no
531 print OUT <<EFF;
534 print OUT "This perlbug was built using Perl $config_tag1\n",
535 "It is being executed now by Perl $config_tag2.\n\n"
536 if $config_tag2 ne $config_tag1;
538 print OUT <<EOF;
539 Site configuration information for perl $perl_version:
542 if ($::Config{cf_by} and $::Config{cf_time}) {
543 print OUT "Configured by $::Config{cf_by} at $::Config{cf_time}.\n\n";
545 print OUT Config::myconfig;
547 if (@patches) {
548 print OUT join "\n ", "Locally applied patches:", @patches;
549 print OUT "\n";
552 print OUT <<EOF;
555 \@INC for perl $perl_version:
557 for my $i (@INC) {
558 print OUT " $i\n";
561 print OUT <<EOF;
564 Environment for perl $perl_version:
566 my @env =
567 qw(PATH LD_LIBRARY_PATH LANG PERL_BADLANG SHELL HOME LOGDIR LANGUAGE);
568 push @env, $Config{ldlibpthname} if $Config{ldlibpthname} ne '';
569 push @env, grep /^(?:PERL|LC_|LANG|CYGWIN)/, keys %ENV;
570 my %env;
571 @env{@env} = @env;
572 for my $env (sort keys %env) {
573 print OUT " $env",
574 exists $ENV{$env} ? "=$ENV{$env}" : ' (unset)',
575 "\n";
577 if ($verbose) {
578 print OUT "\nComplete configuration data for perl $perl_version:\n\n";
579 my $value;
580 foreach (sort keys %::Config) {
581 $value = $::Config{$_};
582 $value =~ s/'/\\'/g;
583 print OUT "$_='$value'\n";
586 } # sub Dump
588 sub Edit {
589 # Edit the report
590 if ($usefile || $body) {
591 paraprint <<EOF;
592 Please make sure that the name of the editor you want to use is correct.
594 print "Editor [$ed]: ";
595 my $entry =scalar <>;
596 chomp $entry;
597 $ed = $entry unless $entry eq '';
600 tryagain:
601 my $sts;
602 $sts = system("$ed $filename") unless $Is_MacOS;
603 if ($Is_MacOS) {
604 require ExtUtils::MakeMaker;
605 ExtUtils::MM_MacOS::launch_file($filename);
606 paraprint <<EOF;
607 Press Enter when done.
609 scalar <>;
611 if ($sts) {
612 paraprint <<EOF;
613 The editor you chose (`$ed') could apparently not be run!
614 Did you mistype the name of your editor? If so, please
615 correct it here, otherwise just press Enter.
617 print "Editor [$ed]: ";
618 my $entry =scalar <>;
619 chomp $entry;
621 if ($entry ne "") {
622 $ed = $entry;
623 goto tryagain;
624 } else {
625 paraprint <<EOF;
626 You may want to save your report to a file, so you can edit and mail it
627 yourself.
632 return if ($ok and not $::opt_n) || $body;
633 # Check that we have a report that has some, eh, report in it.
634 my $unseen = 0;
636 open(REP, "<$filename") or die "Couldn't open `$filename': $!\n";
637 # a strange way to check whether any significant editing
638 # have been done: check whether any new non-empty lines
639 # have been added. Yes, the below code ignores *any* space
640 # in *any* line.
641 while (<REP>) {
642 s/\s+//g;
643 $unseen++ if $_ ne '' and not exists $REP{$_};
646 while ($unseen == 0) {
647 paraprint <<EOF;
648 I am sorry but it looks like you did not report anything.
650 print "Action (Retry Edit/Cancel) ";
651 my ($action) = scalar(<>);
652 if ($action =~ /^[re]/i) { # <R>etry <E>dit
653 goto tryagain;
654 } elsif ($action =~ /^[cq]/i) { # <C>ancel, <Q>uit
655 Cancel();
658 } # sub Edit
660 sub Cancel {
661 1 while unlink($filename); # remove all versions under VMS
662 print "\nCancelling.\n";
663 exit(0);
666 sub NowWhat {
667 # Report is done, prompt for further action
668 if( !$::opt_S ) {
669 while(1) {
670 paraprint <<EOF;
671 Now that you have completed your report, would you like to send
672 the message to $address$andcc, display the message on
673 the screen, re-edit it, display/change the subject,
674 or cancel without sending anything?
675 You may also save the message as a file to mail at another time.
677 retry:
678 print "Action (Send/Display/Edit/Subject/Save to File): ";
679 my $action = scalar <>;
680 chomp $action;
682 if ($action =~ /^(f|sa)/i) { # <F>ile/<Sa>ve
683 my $file_save = $outfile || "perlbug.rep";
684 print "\n\nName of file to save message in [$file_save]: ";
685 my $file = scalar <>;
686 chomp $file;
687 $file = $file_save if $file eq "";
689 unless (open(FILE, ">$file")) {
690 print "\nError opening $file: $!\n\n";
691 goto retry;
693 open(REP, "<$filename") or die "Couldn't open file `$filename': $!\n";
694 print FILE "To: $address\nSubject: $subject\n";
695 print FILE "Cc: $cc\n" if $cc;
696 print FILE "Reply-To: $from\n" if $from;
697 print FILE "Message-Id: $messageid\n" if $messageid;
698 print FILE "\n";
699 while (<REP>) { print FILE }
700 close(REP) or die "Error closing report file `$filename': $!";
701 close(FILE) or die "Error closing $file: $!";
703 print "\nMessage saved in `$file'.\n";
704 exit;
705 } elsif ($action =~ /^(d|l|sh)/i ) { # <D>isplay, <L>ist, <Sh>ow
706 # Display the message
707 open(REP, "<$filename") or die "Couldn't open file `$filename': $!\n";
708 while (<REP>) { print $_ }
709 close(REP) or die "Error closing report file `$filename': $!";
710 } elsif ($action =~ /^su/i) { # <Su>bject
711 print "Subject: $subject\n";
712 print "If the above subject is fine, just press Enter.\n";
713 print "If not, type in the new subject.\n";
714 print "Subject: ";
715 my $reply = scalar <STDIN>;
716 chomp $reply;
717 if ($reply ne '') {
718 unless (TrivialSubject($reply)) {
719 $subject = $reply;
720 print "Subject: $subject\n";
723 } elsif ($action =~ /^se/i) { # <S>end
724 # Send the message
725 print "Are you certain you want to send this message?\n"
726 . 'Please type "yes" if you are: ';
727 my $reply = scalar <STDIN>;
728 chomp $reply;
729 if ($reply eq "yes") {
730 last;
731 } else {
732 paraprint <<EOF;
733 That wasn't a clear "yes", so I won't send your message. If you are sure
734 your message should be sent, type in "yes" (without the quotes) at the
735 confirmation prompt.
738 } elsif ($action =~ /^[er]/i) { # <E>dit, <R>e-edit
739 # edit the message
740 Edit();
741 } elsif ($action =~ /^[qc]/i) { # <C>ancel, <Q>uit
742 Cancel();
743 } elsif ($action =~ /^s/i) {
744 paraprint <<EOF;
745 I'm sorry, but I didn't understand that. Please type "send" or "save".
750 } # sub NowWhat
752 sub TrivialSubject {
753 my $subject = shift;
754 if ($subject =~
755 /^(y(es)?|no?|help|perl( (bug|problem))?|bug|problem)$/i ||
756 length($subject) < 4 ||
757 $subject !~ /\s/) {
758 print "\nThat doesn't look like a good subject. Please be more verbose.\n\n";
759 return 1;
760 } else {
761 return 0;
765 sub Send {
766 # Message has been accepted for transmission -- Send the message
767 if ($outfile) {
768 open SENDMAIL, ">$outfile" or die "Couldn't open '$outfile': $!\n";
769 goto sendout;
772 # on linux certain mail implementations won't accept the subject
773 # as "~s subject" and thus the Subject header will be corrupted
774 # so don't use Mail::Send to be safe
775 if ($::HaveSend && !$Is_Linux && !$Is_OpenBSD) {
776 $msg = new Mail::Send Subject => $subject, To => $address;
777 $msg->cc($cc) if $cc;
778 $msg->add("Reply-To",$from) if $from;
780 $fh = $msg->open;
781 open(REP, "<$filename") or die "Couldn't open `$filename': $!\n";
782 while (<REP>) { print $fh $_ }
783 close(REP) or die "Error closing $filename: $!";
784 $fh->close;
786 print "\nMessage sent.\n";
787 } elsif ($Is_VMS) {
788 if ( ($address =~ /@/ and $address !~ /^\w+%"/) or
789 ($cc =~ /@/ and $cc !~ /^\w+%"/) ) {
790 my $prefix;
791 foreach (qw[ IN MX SMTP UCX PONY WINS ], '') {
792 $prefix = "$_%", last if $ENV{"MAIL\$PROTOCOL_$_"};
794 $address = qq[${prefix}"$address"] unless $address =~ /^\w+%"/;
795 $cc = qq[${prefix}"$cc"] unless !$cc || $cc =~ /^\w+%"/;
797 $subject =~ s/"/""/g; $address =~ s/"/""/g; $cc =~ s/"/""/g;
798 my $sts = system(qq[mail/Subject="$subject" $filename. "$address","$cc"]);
799 if ($sts) {
800 die <<EOF;
801 Can't spawn off mail
802 (leaving bug report in $filename): $sts
805 } else {
806 my $sendmail = "";
807 for (qw(/usr/lib/sendmail /usr/sbin/sendmail /usr/ucblib/sendmail)) {
808 $sendmail = $_, last if -e $_;
810 if ($^O eq 'os2' and $sendmail eq "") {
811 my $path = $ENV{PATH};
812 $path =~ s:\\:/: ;
813 my @path = split /$Config{'path_sep'}/, $path;
814 for (@path) {
815 $sendmail = "$_/sendmail", last if -e "$_/sendmail";
816 $sendmail = "$_/sendmail.exe", last if -e "$_/sendmail.exe";
820 paraprint(<<"EOF"), die "\n" if $sendmail eq "";
821 I am terribly sorry, but I cannot find sendmail, or a close equivalent, and
822 the perl package Mail::Send has not been installed, so I can't send your bug
823 report. We apologize for the inconvenience.
825 So you may attempt to find some way of sending your message, it has
826 been left in the file `$filename'.
828 open(SENDMAIL, "|$sendmail -t -oi") || die "'|$sendmail -t -oi' failed: $!";
829 sendout:
830 print SENDMAIL "To: $address\n";
831 print SENDMAIL "Subject: $subject\n";
832 print SENDMAIL "Cc: $cc\n" if $cc;
833 print SENDMAIL "Reply-To: $from\n" if $from;
834 print SENDMAIL "Message-Id: $messageid\n" if $messageid;
835 print SENDMAIL "\n\n";
836 open(REP, "<$filename") or die "Couldn't open `$filename': $!\n";
837 while (<REP>) { print SENDMAIL $_ }
838 close(REP) or die "Error closing $filename: $!";
840 if (close(SENDMAIL)) {
841 printf "\nMessage %s.\n", $outfile ? "saved" : "sent";
842 } else {
843 warn "\nSendmail returned status '", $? >> 8, "'\n";
846 1 while unlink($filename); # remove all versions under VMS
847 } # sub Send
849 sub Help {
850 print <<EOF;
852 A program to help generate bug reports about perl5, and mail them.
853 It is designed to be used interactively. Normally no arguments will
854 be needed.
856 Usage:
857 $0 [-v] [-a address] [-s subject] [-b body | -f inpufile ] [ -F outputfile ]
858 [-r returnaddress] [-e editor] [-c adminaddress | -C] [-S] [-t] [-h]
859 $0 [-v] [-r returnaddress] [-A] [-ok | -okay | -nok | -nokay]
861 Simplest usage: run "$0", and follow the prompts.
863 Options:
865 -v Include Verbose configuration data in the report
866 -f File containing the body of the report. Use this to
867 quickly send a prepared message.
868 -F File to output the resulting mail message to, instead of mailing.
869 -S Send without asking for confirmation.
870 -a Address to send the report to. Defaults to `$address'.
871 -c Address to send copy of report to. Defaults to `$cc'.
872 -C Don't send copy to administrator.
873 -s Subject to include with the message. You will be prompted
874 if you don't supply one on the command line.
875 -b Body of the report. If not included on the command line, or
876 in a file with -f, you will get a chance to edit the message.
877 -r Your return address. The program will ask you to confirm
878 this if you don't give it here.
879 -e Editor to use.
880 -t Test mode. The target address defaults to `$testaddress'.
881 -d Data mode. This prints out your configuration data, without mailing
882 anything. You can use this with -v to get more complete data.
883 -A Don't send a bug received acknowledgement to the return address.
884 -ok Report successful build on this system to perl porters
885 (use alone or with -v). Only use -ok if *everything* was ok:
886 if there were *any* problems at all, use -nok.
887 -okay As -ok but allow report from old builds.
888 -nok Report unsuccessful build on this system to perl porters
889 (use alone or with -v). You must describe what went wrong
890 in the body of the report which you will be asked to edit.
891 -nokay As -nok but allow report from old builds.
892 -h Print this help message.
897 sub filename {
898 if ($::HaveTemp) {
899 # Good. Use a secure temp file
900 my ($fh, $filename) = File::Temp::tempfile(UNLINK => 1);
901 close($fh);
902 return $filename;
903 } else {
904 # Bah. Fall back to doing things less securely.
905 my $dir = File::Spec->tmpdir();
906 $filename = "bugrep0$$";
907 $filename++ while -e File::Spec->catfile($dir, $filename);
908 $filename = File::Spec->catfile($dir, $filename);
912 sub paraprint {
913 my @paragraphs = split /\n{2,}/, "@_";
914 print "\n\n";
915 for (@paragraphs) { # implicit local $_
916 s/(\S)\s*\n/$1 /g;
917 write;
918 print "\n";
922 format STDOUT =
923 ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ~~
927 __END__
929 =head1 NAME
931 perlbug - how to submit bug reports on Perl
933 =head1 SYNOPSIS
935 B<perlbug> S<[ B<-v> ]> S<[ B<-a> I<address> ]> S<[ B<-s> I<subject> ]>
936 S<[ B<-b> I<body> | B<-f> I<inputfile> ]> S<[ B<-F> I<outputfile> ]>
937 S<[ B<-r> I<returnaddress> ]>
938 S<[ B<-e> I<editor> ]> S<[ B<-c> I<adminaddress> | B<-C> ]>
939 S<[ B<-S> ]> S<[ B<-t> ]> S<[ B<-d> ]> S<[ B<-A> ]> S<[ B<-h> ]>
941 B<perlbug> S<[ B<-v> ]> S<[ B<-r> I<returnaddress> ]>
942 S<[ B<-A> ]> S<[ B<-ok> | B<-okay> | B<-nok> | B<-nokay> ]>
944 =head1 DESCRIPTION
946 A program to help generate bug reports about perl or the modules that
947 come with it, and mail them.
949 If you have found a bug with a non-standard port (one that was not part
950 of the I<standard distribution>), a binary distribution, or a
951 non-standard module (such as Tk, CGI, etc), then please see the
952 documentation that came with that distribution to determine the correct
953 place to report bugs.
955 C<perlbug> is designed to be used interactively. Normally no arguments
956 will be needed. Simply run it, and follow the prompts.
958 If you are unable to run B<perlbug> (most likely because you don't have
959 a working setup to send mail that perlbug recognizes), you may have to
960 compose your own report, and email it to B<perlbug@perl.org>. You might
961 find the B<-d> option useful to get summary information in that case.
963 In any case, when reporting a bug, please make sure you have run through
964 this checklist:
966 =over 4
968 =item What version of Perl you are running?
970 Type C<perl -v> at the command line to find out.
972 =item Are you running the latest released version of perl?
974 Look at http://www.perl.com/ to find out. If it is not the latest
975 released version, get that one and see whether your bug has been
976 fixed. Note that bug reports about old versions of Perl, especially
977 those prior to the 5.0 release, are likely to fall upon deaf ears.
978 You are on your own if you continue to use perl1 .. perl4.
980 =item Are you sure what you have is a bug?
982 A significant number of the bug reports we get turn out to be documented
983 features in Perl. Make sure the behavior you are witnessing doesn't fall
984 under that category, by glancing through the documentation that comes
985 with Perl (we'll admit this is no mean task, given the sheer volume of
986 it all, but at least have a look at the sections that I<seem> relevant).
988 Be aware of the familiar traps that perl programmers of various hues
989 fall into. See L<perltrap>.
991 Check in L<perldiag> to see what any Perl error message(s) mean.
992 If message isn't in perldiag, it probably isn't generated by Perl.
993 Consult your operating system documentation instead.
995 If you are on a non-UNIX platform check also L<perlport>, as some
996 features may be unimplemented or work differently.
998 Try to study the problem under the Perl debugger, if necessary.
999 See L<perldebug>.
1001 =item Do you have a proper test case?
1003 The easier it is to reproduce your bug, the more likely it will be
1004 fixed, because if no one can duplicate the problem, no one can fix it.
1005 A good test case has most of these attributes: fewest possible number
1006 of lines; few dependencies on external commands, modules, or
1007 libraries; runs on most platforms unimpeded; and is self-documenting.
1009 A good test case is almost always a good candidate to be on the perl
1010 test suite. If you have the time, consider making your test case so
1011 that it will readily fit into the standard test suite.
1013 Remember also to include the B<exact> error messages, if any.
1014 "Perl complained something" is not an exact error message.
1016 If you get a core dump (or equivalent), you may use a debugger
1017 (B<dbx>, B<gdb>, etc) to produce a stack trace to include in the bug
1018 report. NOTE: unless your Perl has been compiled with debug info
1019 (often B<-g>), the stack trace is likely to be somewhat hard to use
1020 because it will most probably contain only the function names and not
1021 their arguments. If possible, recompile your Perl with debug info and
1022 reproduce the dump and the stack trace.
1024 =item Can you describe the bug in plain English?
1026 The easier it is to understand a reproducible bug, the more likely it
1027 will be fixed. Anything you can provide by way of insight into the
1028 problem helps a great deal. In other words, try to analyze the
1029 problem (to the extent you can) and report your discoveries.
1031 =item Can you fix the bug yourself?
1033 A bug report which I<includes a patch to fix it> will almost
1034 definitely be fixed. Use the C<diff> program to generate your patches
1035 (C<diff> is being maintained by the GNU folks as part of the B<diffutils>
1036 package, so you should be able to get it from any of the GNU software
1037 repositories). If you do submit a patch, the cool-dude counter at
1038 perlbug@perl.org will register you as a savior of the world. Your
1039 patch may be returned with requests for changes, or requests for more
1040 detailed explanations about your fix.
1042 Here are some clues for creating quality patches: Use the B<-c> or
1043 B<-u> switches to the diff program (to create a so-called context or
1044 unified diff). Make sure the patch is not reversed (the first
1045 argument to diff is typically the original file, the second argument
1046 your changed file). Make sure you test your patch by applying it with
1047 the C<patch> program before you send it on its way. Try to follow the
1048 same style as the code you are trying to patch. Make sure your patch
1049 really does work (C<make test>, if the thing you're patching supports
1050 it).
1052 =item Can you use C<perlbug> to submit the report?
1054 B<perlbug> will, amongst other things, ensure your report includes
1055 crucial information about your version of perl. If C<perlbug> is unable
1056 to mail your report after you have typed it in, you may have to compose
1057 the message yourself, add the output produced by C<perlbug -d> and email
1058 it to B<perlbug@perl.org>. If, for some reason, you cannot run
1059 C<perlbug> at all on your system, be sure to include the entire output
1060 produced by running C<perl -V> (note the uppercase V).
1062 Whether you use C<perlbug> or send the email manually, please make
1063 your Subject line informative. "a bug" not informative. Neither is
1064 "perl crashes" nor "HELP!!!". These don't help.
1065 A compact description of what's wrong is fine.
1067 =back
1069 Having done your bit, please be prepared to wait, to be told the bug
1070 is in your code, or even to get no reply at all. The Perl maintainers
1071 are busy folks, so if your problem is a small one or if it is difficult
1072 to understand or already known, they may not respond with a personal reply.
1073 If it is important to you that your bug be fixed, do monitor the
1074 C<Changes> file in any development releases since the time you submitted
1075 the bug, and encourage the maintainers with kind words (but never any
1076 flames!). Feel free to resend your bug report if the next released
1077 version of perl comes out and your bug is still present.
1079 =head1 OPTIONS
1081 =over 8
1083 =item B<-a>
1085 Address to send the report to. Defaults to B<perlbug@perl.org>.
1087 =item B<-A>
1089 Don't send a bug received acknowledgement to the reply address.
1090 Generally it is only a sensible to use this option if you are a
1091 perl maintainer actively watching perl porters for your message to
1092 arrive.
1094 =item B<-b>
1096 Body of the report. If not included on the command line, or
1097 in a file with B<-f>, you will get a chance to edit the message.
1099 =item B<-C>
1101 Don't send copy to administrator.
1103 =item B<-c>
1105 Address to send copy of report to. Defaults to the address of the
1106 local perl administrator (recorded when perl was built).
1108 =item B<-d>
1110 Data mode (the default if you redirect or pipe output). This prints out
1111 your configuration data, without mailing anything. You can use this
1112 with B<-v> to get more complete data.
1114 =item B<-e>
1116 Editor to use.
1118 =item B<-f>
1120 File containing the body of the report. Use this to quickly send a
1121 prepared message.
1123 =item B<-F>
1125 File to output the results to instead of sending as an email. Useful
1126 particularly when running perlbug on a machine with no direct internet
1127 connection.
1129 =item B<-h>
1131 Prints a brief summary of the options.
1133 =item B<-ok>
1135 Report successful build on this system to perl porters. Forces B<-S>
1136 and B<-C>. Forces and supplies values for B<-s> and B<-b>. Only
1137 prompts for a return address if it cannot guess it (for use with
1138 B<make>). Honors return address specified with B<-r>. You can use this
1139 with B<-v> to get more complete data. Only makes a report if this
1140 system is less than 60 days old.
1142 =item B<-okay>
1144 As B<-ok> except it will report on older systems.
1146 =item B<-nok>
1148 Report unsuccessful build on this system. Forces B<-C>. Forces and
1149 supplies a value for B<-s>, then requires you to edit the report
1150 and say what went wrong. Alternatively, a prepared report may be
1151 supplied using B<-f>. Only prompts for a return address if it
1152 cannot guess it (for use with B<make>). Honors return address
1153 specified with B<-r>. You can use this with B<-v> to get more
1154 complete data. Only makes a report if this system is less than 60
1155 days old.
1157 =item B<-nokay>
1159 As B<-nok> except it will report on older systems.
1161 =item B<-r>
1163 Your return address. The program will ask you to confirm its default
1164 if you don't use this option.
1166 =item B<-S>
1168 Send without asking for confirmation.
1170 =item B<-s>
1172 Subject to include with the message. You will be prompted if you don't
1173 supply one on the command line.
1175 =item B<-t>
1177 Test mode. The target address defaults to B<perlbug-test@perl.org>.
1179 =item B<-v>
1181 Include verbose configuration data in the report.
1183 =back
1185 =head1 AUTHORS
1187 Kenneth Albanowski (E<lt>kjahds@kjahds.comE<gt>), subsequently I<doc>tored
1188 by Gurusamy Sarathy (E<lt>gsar@activestate.comE<gt>), Tom Christiansen
1189 (E<lt>tchrist@perl.comE<gt>), Nathan Torkington (E<lt>gnat@frii.comE<gt>),
1190 Charles F. Randall (E<lt>cfr@pobox.comE<gt>), Mike Guy
1191 (E<lt>mjtg@cam.a.ukE<gt>), Dominic Dunlop (E<lt>domo@computer.orgE<gt>),
1192 Hugo van der Sanden (E<lt>hv@crypt.org<gt>),
1193 Jarkko Hietaniemi (E<lt>jhi@iki.fiE<gt>), Chris Nandor
1194 (E<lt>pudge@pobox.comE<gt>), Jon Orwant (E<lt>orwant@media.mit.eduE<gt>,
1195 and Richard Foley (E<lt>richard@rfi.netE<gt>).
1197 =head1 SEE ALSO
1199 perl(1), perldebug(1), perldiag(1), perlport(1), perltrap(1),
1200 diff(1), patch(1), dbx(1), gdb(1)
1202 =head1 BUGS
1204 None known (guess what must have been used to report them?)
1206 =cut