perl 5.003_06: utils/h2xs.PL
[p5sagit/p5-mst-13.2.git] / utils / perlbug.PL
index 375bb78..f136372 100644 (file)
@@ -15,8 +15,7 @@ use File::Basename qw(&basename &dirname);
 chdir(dirname($0));
 ($file = basename($0)) =~ s/\.PL$//;
 $file =~ s/\.pl$//
-       if ($Config{'osname'} eq 'VMS' or
-           $Config{'osname'} eq 'OS2');  # "case-forgiving"
+       if ($^O eq 'VMS' or $^O eq 'os2');  # "case-forgiving"
 
 open OUT,">$file" or die "Can't create $file: $!";
 
@@ -51,22 +50,28 @@ use strict;
 sub paraprint;
 
 
-my($Version) = "1.11";
+my($Version) = "1.14";
 
 # Changed in 1.06 to skip Mail::Send and Mail::Util if not available.
-# Changed in 1.07 to see more sendmail execs, and added pipe output
-# Changed in 1.08 to use correct address for sendmail
+# Changed in 1.07 to see more sendmail execs, and added pipe output.
+# Changed in 1.08 to use correct address for sendmail.
 # Changed in 1.09 to close the REP file before calling it up in the editor.
 #                 Also removed some old comments duplicated elsewhere.
 # Changed in 1.10 to run under VMS without Mail::Send; also fixed
-#                 temp filename generation
+#                 temp filename generation.
 # Changed in 1.11 to clean up some text and removed Mail::Send deactivator.
+# Changed in 1.12 to check for editor errors, make save/send distinction
+#                 clearer and add $ENV{REPLYTO}.
+# Changed in 1.13 to hopefully make it more difficult to accidentally
+#                 send mail
+# Changed in 1.14 to make the prompts a little more clear on providing
+#                 helpful information. Also let file read fail gracefully.
 
 # TODO: Allow the user to re-name the file on mail failure, and
 #       make sure failure (transmission-wise) of Mail::Send is 
 #       accounted for.
 
-my( $file, $cc, $address, $perlbug, $testaddress, $filename,
+my( $file, $usefile, $cc, $address, $perlbug, $testaddress, $filename,
     $subject, $from, $verbose, $ed, 
     $fh, $me, $Is_VMS, $msg, $body, $andcc );
 
@@ -74,10 +79,18 @@ Init();
 
 if($::opt_h) { Help(); exit; }
 
+if(!-t STDIN) {
+       paraprint <<EOF;
+Please use perlbug interactively. If you want to 
+include a file, you can use the -f switch.
+EOF
+       die "\n";
+}
+
 if($::opt_d or !-t STDOUT) { Dump(*STDOUT); exit; }
 
 Query();
-Edit();
+Edit() unless $usefile;
 NowWhat();
 Send();
 
@@ -87,7 +100,7 @@ sub Init {
  
        # -------- Setup --------
 
-       $Is_VMS = $::Config{'osname'} eq 'VMS';
+       $Is_VMS = $^O eq 'VMS';
 
        getopts("dhva:s:b:f:r:e:SCc:t");
        
@@ -123,6 +136,9 @@ sub Init {
        # Subject of bug-report message
        $subject = $::opt_s || "";
 
+       # Send a file
+       $usefile = ($::opt_f || 0);
+       
        # File to send as report
        $file = $::opt_f || "";
 
@@ -130,10 +146,10 @@ sub Init {
        $body = $::opt_b || "";
 
        # Editor
-       $ed = ($::opt_f ? "file" : (
-                       $::opt_e || $ENV{VISUAL} || $ENV{EDITOR} || $ENV{EDIT} || 
+       $ed = ( $::opt_e || $ENV{VISUAL} || $ENV{EDITOR} || $ENV{EDIT} || 
                      ($Is_VMS ? "edit/tpu" : "vi")
-             ));
+             );
+             
       
        # My username
        $me = getpwuid($<);
@@ -146,9 +162,8 @@ sub Query {
        # Explain what perlbug is
        
        paraprint <<EOF;
-This program allows you to create a bug report,
-which will be sent as an e-mail message to $address
-once you have filled in the report.
+This program provides an easy way to create a message reporting a bug in
+perl, and e-mail it to $address.
 
 EOF
 
@@ -157,8 +172,8 @@ EOF
        if(! $subject) {
                paraprint <<EOF;
 First of all, please provide a subject for the 
-message. It should be as a concise description of 
-the bug as is possible.
+message. It should be a concise description of 
+the bug or problem.
 
 EOF
                print "Subject: ";
@@ -198,26 +213,29 @@ EOF
                             
                if( !$domain) {
                        $guess = "";
-               } elsif ($Is_VMS && !$::Config{'d_has_sockets'}) { 
+               } elsif ($Is_VMS && !$::Config{'d_socket'}) { 
                        $guess = "$domain\:\:$me";
                } else {
                        $guess = "$me\@$domain" if $domain;
                        $guess = "$me\@unknown.addresss" unless $domain;
                        }
+                       
+               $guess = $ENV{'REPLYTO'} if defined($ENV{'REPLYTO'});
+               $guess = $ENV{"REPLY-TO"} if defined($ENV{'REPLY-TO'});
        
                if( $guess ) {
                        paraprint <<EOF;
 
 
-Your e-mail address will be useful if you need to be contacted.
-If the default shown is not your proper address, please correct it.
+Your e-mail address will be useful if you need to be contacted. If the
+default shown is not your full internet e-mail address, please correct it.
 
 EOF
                } else {
                        paraprint <<EOF;
 
 So that you may be contacted if necessary, please enter 
-your e-mail address here.
+your full internet e-mail address here.
 
 EOF
                }
@@ -265,11 +283,12 @@ EOF
        
        }
 
-       if($cc =~ /^(none|yourself|myself|ourselves)$/i) { $cc = "" }
+       if($cc =~ /^(none|yourself|me|myself|ourselves)$/i) { $cc = "" }
 
        $andcc = " and $cc" if $cc;
 
-
+editor:
+       
        # Prompt for editor, if no override is given
        if(! $::opt_e and ! $::opt_f and ! $::opt_b) {
                paraprint <<EOF;
@@ -277,9 +296,16 @@ EOF
 
 Now you need to supply the bug report. Try to make
 the report concise but descriptive. Include any 
-relevant detail. Some information about your local
+relevant detail. If you are reporting something
+that does not work as you think it should, please
+try to include example of both the actual 
+result, and what you expected.
+
+Some information about your local
 perl configuration will automatically be included 
-at the end of the report. 
+at the end of the report. If you are using any
+unusual version of perl, please try and confirm
+exactly which versions are relevant.
 
 You will probably want to use an editor to enter
 the report. If "$ed" is the editor you want
@@ -295,8 +321,11 @@ EOF
        
                my($entry) =scalar(<>);
                chop $entry;
-       
-               if($entry ne "") {
+               
+               $usefile = 0;
+               if($entry eq "file") {
+                       $usefile = 1;
+               } elsif($entry ne "") {
                        $ed = $entry;
                } 
        }
@@ -314,10 +343,10 @@ EOF
        
        # Prompt for file to read report from, if needed
        
-       if( $ed eq "file" and ! $file) {
+       if( $usefile and ! $file) {
+filename:
                paraprint <<EOF;
 
-
 What is the name of the file that contains your report?
 
 EOF
@@ -327,9 +356,24 @@ EOF
                my($entry) = scalar(<>);
                chop($entry);
 
+               if($entry eq "") {
+                       paraprint <<EOF;
+                       
+No filename? I'll let you go back and choose an editor again.                  
+
+EOF
+                       goto editor;
+               }
+               
                if(!-f $entry or !-r $entry) {
-                       print "\n\nUnable to read from `$entry'.\nExiting.\n";
-                       exit;
+                       paraprint <<EOF;
+                       
+I'm sorry, but I can't read from `$entry'. Maybe you mistyped the name of
+the file? If you don't want to send a file, just enter a blank line and you
+can get back to the editor selection.
+
+EOF
+                       goto filename;
                }
                $file = $entry;
 
@@ -348,8 +392,8 @@ EOF
 
        if($body) {
                print REP $body;
-       } elsif($file) {
-               open(F,"<$file") or die "Unable to read report file: $!\n";
+       } elsif($usefile) {
+               open(F,"<$file") or die "Unable to read report file from `$file': $!\n";
                while(<F>) {
                print REP $_
                }
@@ -393,11 +437,52 @@ EOF
 
 sub Edit {
        # Edit the report
+
+       if($usefile) {
+               $usefile = 0;
+               paraprint <<EOF;
+
+Please make sure that the name of the editor you want to use is correct.
+
+EOF
+               print "Editor [$ed]: ";
+               
+               my($entry) =scalar(<>);
+               chop $entry;
+       
+               if($entry ne "") {
+                       $ed = $entry;
+               } 
+       }
        
-       if(!$file and !$body) {
+tryagain:
+       if(!$usefile and !$body) {
                my($sts) = system("$ed $filename");
                if( $Is_VMS ? !($sts & 1) : $sts ) {
-                       print "\nUnable to run editor!\n";
+                       #print "\nUnable to run editor!\n";
+                       paraprint <<EOF;
+
+The editor you chose (`$ed') could apparently not be run!
+Did you mistype the name of your editor? If so, please
+correct it here, otherwise just press Enter. 
+
+EOF
+                       print "Editor [$ed]: ";
+               
+                       my($entry) =scalar(<>);
+                       chop $entry;
+       
+                       if($entry ne "") {
+                               $ed = $entry;
+                               goto tryagain;
+                       } else {
+                       
+                       paraprint <<EOF;
+
+You may want to save your report to a file, so you can edit and mail it
+yourself.
+EOF
+                       }
                } 
        }
 }
@@ -418,14 +503,11 @@ You may also save the message as a file to mail at another time.
 
 EOF
 
-                       print "Action (Send/Display/Edit/Cancel/File): ";
+                       print "Action (Send/Display/Edit/Cancel/Save to File): ";
                        my($action) = scalar(<>);
                        chop $action;
 
-                       if($action =~ /^s/i) { # Send
-                               # Send the message
-                               last;
-                       } elsif($action =~ /^f/i) { # File
+                       if( $action =~ /^(f|sa)/i ) { # <F>ile/<Sa>ve
                                print "\n\nName of file to save message in [perlbug.rep]: ";
                                my($file) = scalar(<>);
                                chop $file;
@@ -444,18 +526,43 @@ EOF
                                print "\nMessage saved in `$file'.\n";
                                exit;
 
-                       } elsif($action =~ /^[drl]/i) { # Display, Redisplay, List
+                       } elsif( $action =~ /^(d|l|sh)/i ) { # <D>isplay, <L>ist, <Sh>ow
                                # Display the message
                                open(REP,"<$filename");
                                while(<REP>) { print $_ }
                                close(REP);
-                       } elsif($action =~ /^e/i) { # Edit
+                       } elsif( $action =~ /^se/i ) { # <S>end
+                               # Send the message
+                               print "\
+Are you certain you want to send this message?
+Please type \"yes\" if you are: ";
+                               my($reply) = scalar(<STDIN>);
+                               chop($reply);
+                               if( $reply eq "yes" ) {
+                                       last;
+                               } else {
+                                       paraprint <<EOF;
+
+That wasn't a clear "yes", so I won't send your message. If you are sure
+your message should be sent, type in "yes" (without the quotes) at the
+confirmation prompt.
+
+EOF
+                                       
+                               }
+                       } elsif( $action =~ /^[er]/i ) { # <E>dit, <R>e-edit
                                # edit the message
-                               system("$ed $filename");
-                       } elsif($action =~ /^[qc]/i) { # Cancel, Quit
+                               Edit();
+                               #system("$ed $filename");
+                       } elsif( $action =~ /^[qc]/i ) { # <C>ancel, <Q>uit
                                1 while unlink($filename);  # remove all versions under VMS
                                print "\nCancelling.\n";
                                exit(0);
+                       } elsif( $action =~ /^s/ ) {
+                               paraprint <<EOF;
+
+I'm sorry, but I didn't understand that. Please type "send" or "save".
+EOF
                        }
                
                }