home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / perl_utl.zip / perlbug.cmd < prev    next >
OS/2 REXX Batch file  |  1997-11-28  |  30KB  |  1,080 lines

  1. extproc perl -S
  2. #!f:/perllib/bin/perl
  3.     eval 'exec f:/perllib/bin/perl -S $0 ${1+"$@"}'
  4.     if $running_under_some_shell;
  5.  
  6. my $config_tag1 = '5.00455 - Wed Nov 26 18:29:32 PST 1997';
  7.  
  8. my $patchlevel_date = 880475336;
  9. my $patch_tags = '';
  10. my @patches = (
  11.     ''
  12. );
  13.  
  14. use Config;
  15. use Getopt::Std;
  16.  
  17. BEGIN {
  18.     eval "use Mail::Send;";
  19.     $::HaveSend = ($@ eq "");
  20.     eval "use Mail::Util;";
  21.     $::HaveUtil = ($@ eq "");
  22. };
  23.  
  24.  
  25. use strict;
  26.  
  27. sub paraprint;
  28.  
  29.  
  30. my($Version) = "1.20";
  31.  
  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.  
  56. # TODO: - Allow the user to re-name the file on mail failure, and
  57. #       make sure failure (transmission-wise) of Mail::Send is 
  58. #       accounted for.
  59. #       - Test -b option
  60.  
  61. my( $file, $usefile, $cc, $address, $perlbug, $testaddress, $filename,
  62.     $subject, $from, $verbose, $ed, 
  63.     $fh, $me, $Is_MSWin32, $Is_VMS, $msg, $body, $andcc, %REP, $ok);
  64.  
  65. my $config_tag2 = "$] - $Config{cf_time}";
  66.  
  67. Init();
  68.  
  69. if($::opt_h) { Help(); exit; }
  70.  
  71. if($::opt_d) { Dump(*STDOUT); exit; }
  72.  
  73. if(!-t STDIN) {
  74.     paraprint <<EOF;
  75. Please use perlbug interactively. If you want to 
  76. include a file, you can use the -f switch.
  77. EOF
  78.     die "\n";
  79. }
  80.  
  81. if(!-t STDOUT) { Dump(*STDOUT); exit; }
  82.  
  83. Query();
  84. Edit() unless $usefile;
  85. NowWhat();
  86. Send();
  87.  
  88. exit;
  89.  
  90. sub Init {
  91.  
  92.     # -------- Setup --------
  93.  
  94.     $Is_MSWin32 = $^O eq 'MSWin32';
  95.     $Is_VMS = $^O eq 'VMS';
  96.  
  97.     getopts("dhva:s:b:f:r:e:SCc:to:");
  98.     
  99.  
  100.     # This comment is needed to notify metaconfig that we are
  101.     # using the $perladmin, $cf_by, and $cf_time definitions.
  102.  
  103.  
  104.     # -------- Configuration ---------
  105.     
  106.     # perlbug address
  107.     $perlbug = 'perlbug@perl.com';
  108.  
  109.     
  110.     # Test address
  111.     $testaddress = 'perlbug-test@perl.com';
  112.     
  113.     # Target address
  114.     $address = $::opt_a || ($::opt_t ? $testaddress : $perlbug);
  115.  
  116.     # Users address, used in message and in Reply-To header
  117.     $from = $::opt_r || "";
  118.  
  119.     # Include verbose configuration information
  120.     $verbose = $::opt_v || 0;
  121.  
  122.     # Subject of bug-report message
  123.     $subject = $::opt_s || "";
  124.  
  125.     # Send a file
  126.     $usefile = ($::opt_f || 0);
  127.     
  128.     # File to send as report
  129.     $file = $::opt_f || "";
  130.  
  131.     # Body of report
  132.     $body = $::opt_b || "";
  133.  
  134.     # Editor
  135.     $ed = (    $::opt_e || $ENV{VISUAL} || $ENV{EDITOR} || $ENV{EDIT} || 
  136.               ($Is_VMS ? "edit/tpu" : $Is_MSWin32 ? "notepad" : "vi")
  137.           );
  138.           
  139.         # OK - send "OK" report for build on this system
  140.         $ok = 0;
  141.     if ( $::opt_o ) {
  142.         if ( $::opt_o eq 'k' or $::opt_o eq 'kay' ) {
  143.                 my $age = time - $patchlevel_date;
  144.                 if ( $::opt_o eq 'k' and $age > 60 * 24 * 60 * 60 ) {
  145.                     my $date = localtime $patchlevel_date;
  146.                     print <<"EOF";
  147. \"perlbug -ok\" does not report on Perl versions which are more than
  148. 60 days old.  This Perl version was constructed on $date.
  149. If you really want to report this, use \"perlbug -okay\".
  150. EOF
  151.                     exit();
  152.                 };
  153.         # force these options
  154.         $::opt_S = 1; # don't prompt for send
  155.         $::opt_C = 1; # don't send a copy to the local admin
  156.         $::opt_s = 1;
  157.         $subject = "OK: perl $] ${patch_tags}on"
  158.               ." $::Config{'archname'} $::Config{'osvers'} $subject";
  159.         $::opt_b = 1;
  160.         $body    = "Perl reported to build OK on this system.\n";
  161.         $ok = 1;
  162.         }
  163.         else {
  164.         Help();
  165.         exit();
  166.         }
  167.     }
  168.       
  169.     # Possible administrator addresses, in order of confidence
  170.     # (Note that cf_email is not mentioned to metaconfig, since
  171.     # we don't really want it. We'll just take it if we have to.)
  172.         #
  173.         # This has to be after the $ok stuff above because of the way
  174.         # that $::opt_C is forced.
  175.     $cc = ($::opt_C ? "" : (
  176.         $::opt_c || $::Config{perladmin} || $::Config{cf_email} || $::Config{cf_by}
  177.         ));
  178.     
  179.     # My username
  180.     $me = ( $Is_MSWin32 
  181.         ? $ENV{'USERNAME'} 
  182.         : ( $^O eq 'os2' 
  183.             ? $ENV{'USER'} || $ENV{'LOGNAME'} 
  184.             : eval { getpwuid($<) }) );    # May be missing
  185.  
  186. }
  187.  
  188.  
  189. sub Query {
  190.  
  191.     # Explain what perlbug is
  192.     if ( ! $ok ) {
  193.     paraprint <<EOF;
  194. This program provides an easy way to create a message reporting a bug
  195. in perl, and e-mail it to $address.  It is *NOT* intended for
  196. sending test messages or simply verifying that perl works, *NOR* is it
  197. intended for reporting bugs in third-party perl modules.  It is *ONLY*
  198. a means of reporting verifiable problems with the core perl distribution,
  199. and any solutions to such problems, to the people who maintain perl.
  200.  
  201. If you're just looking for help with perl, try posting to the Usenet
  202. newsgroup comp.lang.perl.misc.  If you're looking for help with using
  203. perl with CGI, try posting to comp.infosystems.www.programming.cgi.
  204.  
  205. EOF
  206.     }
  207.  
  208.  
  209.     # Prompt for subject of message, if needed
  210.     if(! $subject) {
  211.         paraprint <<EOF;
  212. First of all, please provide a subject for the 
  213. message. It should be a concise description of 
  214. the bug or problem. "perl bug" or "perl problem"
  215. is not a concise description.
  216.  
  217. EOF
  218.         print "Subject: ";
  219.     
  220.         $subject = <>;
  221.         chop $subject;
  222.     
  223.         my($err)=0;
  224.         while( $subject =~ /^\s*$/ ) {
  225.             print "\nPlease enter a subject: ";
  226.             $subject = <>;
  227.             chop $subject;
  228.             if($err++>5) {
  229.                 die "Aborting.\n";
  230.             }
  231.         }
  232.     }
  233.     
  234.  
  235.     # Prompt for return address, if needed
  236.     if( !$from) {
  237.  
  238.         # Try and guess return address
  239.         my($domain);
  240.         
  241.         if($::HaveUtil) {
  242.             $domain = Mail::Util::maildomain();
  243.         } elsif ($Is_MSWin32) {
  244.             $domain = $ENV{'USERDOMAIN'};
  245.         } else {
  246.             require Sys::Hostname;
  247.             $domain = Sys::Hostname::hostname();
  248.         }
  249.         
  250.         my($guess);
  251.                          
  252.             if( !$domain) {
  253.                 $guess = "";
  254.             } elsif ($Is_VMS && !$::Config{'d_socket'}) { 
  255.                 $guess = "$domain\:\:$me";
  256.             } else {
  257.                 $guess = "$me\@$domain" if $domain;
  258.                 $guess = "$me\@unknown.addresss" unless $domain;
  259.             }
  260.             
  261.         $guess = $ENV{'REPLYTO'} if defined($ENV{'REPLYTO'});
  262.         $guess = $ENV{"REPLY-TO"} if defined($ENV{'REPLY-TO'});
  263.     
  264.         if( $guess ) {
  265.             if ( ! $ok ) {
  266.             paraprint <<EOF;
  267.  
  268.  
  269. Your e-mail address will be useful if you need to be contacted. If the
  270. default shown is not your full internet e-mail address, please correct it.
  271.  
  272. EOF
  273.                     }
  274.         } else {
  275.             paraprint <<EOF;
  276.  
  277. So that you may be contacted if necessary, please enter 
  278. your full internet e-mail address here.
  279.  
  280. EOF
  281.         }
  282.  
  283.         if ( $ok && $guess ne '' ) {
  284.             # use it
  285.             $from = $guess;
  286.         }
  287.         else {
  288.             # verify it
  289.             print "Your address [$guess]: ";
  290.             
  291.             $from = <>;
  292.             chop $from;
  293.             
  294.             if($from eq "") { $from = $guess }
  295.         }
  296.     
  297.     }
  298.     
  299.     #if( $from =~ /^(.*)\@(.*)$/ ) {
  300.     #    $mailname = $1;
  301.     #    $maildomain = $2;
  302.     #}
  303.  
  304.     if( $from eq $cc or $me eq $cc ) {
  305.         # Try not to copy ourselves
  306.         $cc = "yourself";
  307.     }
  308.  
  309.  
  310.     # Prompt for administrator address, unless an override was given
  311.     if( !$::opt_C and !$::opt_c ) {
  312.         paraprint <<EOF;
  313.  
  314.  
  315. A copy of this report can be sent to your local
  316. perl administrator. If the address is wrong, please 
  317. correct it, or enter 'none' or 'yourself' to not send
  318. a copy.
  319.  
  320. EOF
  321.  
  322.         print "Local perl administrator [$cc]: ";
  323.     
  324.         my($entry) = scalar(<>);
  325.         chop $entry;
  326.     
  327.         if($entry ne "") {
  328.             $cc = $entry;
  329.             if($me eq $cc) { $cc = "" }
  330.         }
  331.     
  332.     }
  333.  
  334.     if($cc =~ /^(none|yourself|me|myself|ourselves)$/i) { $cc = "" }
  335.  
  336.     $andcc = " and $cc" if $cc;
  337.  
  338. editor:
  339.     
  340.     # Prompt for editor, if no override is given
  341.     if(! $::opt_e and ! $::opt_f and ! $::opt_b) {
  342.         paraprint <<EOF;
  343.  
  344.  
  345. Now you need to supply the bug report. Try to make
  346. the report concise but descriptive. Include any 
  347. relevant detail. If you are reporting something
  348. that does not work as you think it should, please
  349. try to include example of both the actual 
  350. result, and what you expected.
  351.  
  352. Some information about your local
  353. perl configuration will automatically be included 
  354. at the end of the report. If you are using any
  355. unusual version of perl, please try and confirm
  356. exactly which versions are relevant.
  357.  
  358. You will probably want to use an editor to enter
  359. the report. If "$ed" is the editor you want
  360. to use, then just press Enter, otherwise type in
  361. the name of the editor you would like to use.
  362.  
  363. If you would like to use a prepared file, type
  364. "file", and you will be asked for the filename.
  365.  
  366. EOF
  367.  
  368.         print "Editor [$ed]: ";
  369.     
  370.         my($entry) =scalar(<>);
  371.         chop $entry;
  372.         
  373.         $usefile = 0;
  374.         if($entry eq "file") {
  375.             $usefile = 1;
  376.         } elsif($entry ne "") {
  377.             $ed = $entry;
  378.         } 
  379.     }
  380.  
  381.  
  382.     # Generate scratch file to edit report in
  383.     
  384.     {
  385.     my($dir) = ($Is_VMS ? 'sys$scratch:' :
  386.             (($Is_MSWin32 && $ENV{'TEMP'}) ? $ENV{'TEMP'} : '/tmp/'));
  387.     $filename = "bugrep0$$";
  388.     $dir .= "\\" if $Is_MSWin32 and $dir !~ m|[\\/]$|;
  389.     $filename++ while -e "$dir$filename";
  390.     $filename = "$dir$filename";
  391.     }
  392.     
  393.     
  394.     # Prompt for file to read report from, if needed
  395.     
  396.     if( $usefile and ! $file) {
  397. filename:
  398.         paraprint <<EOF;
  399.  
  400. What is the name of the file that contains your report?
  401.  
  402. EOF
  403.  
  404.         print "Filename: ";
  405.     
  406.         my($entry) = scalar(<>);
  407.         chop($entry);
  408.  
  409.         if($entry eq "") {
  410.             paraprint <<EOF;
  411.             
  412. No filename? I'll let you go back and choose an editor again.            
  413.  
  414. EOF
  415.             goto editor;
  416.         }
  417.         
  418.         if(!-f $entry or !-r $entry) {
  419.             paraprint <<EOF;
  420.             
  421. I'm sorry, but I can't read from `$entry'. Maybe you mistyped the name of
  422. the file? If you don't want to send a file, just enter a blank line and you
  423. can get back to the editor selection.
  424.  
  425. EOF
  426.             goto filename;
  427.         }
  428.         $file = $entry;
  429.  
  430.     }
  431.  
  432.  
  433.     # Generate report
  434.  
  435.     open(REP,">$filename");
  436.  
  437.     my $reptype = $ok ? "success" : "bug";
  438.  
  439.     print REP <<EOF;
  440. This is a $reptype report for perl from $from,
  441. generated with the help of perlbug $Version running under perl $].
  442.  
  443. EOF
  444.  
  445.     if($body) {
  446.         print REP $body;
  447.     } elsif($usefile) {
  448.         open(F,"<$file") or die "Unable to read report file from `$file': $!\n";
  449.         while(<F>) {
  450.         print REP $_
  451.         }
  452.         close(F);
  453.     } else {
  454.         print REP <<EOF;
  455.  
  456. -----------------------------------------------------------------
  457. [Please enter your report here]
  458.  
  459.  
  460.  
  461. [Please do not change anything below this line]
  462. -----------------------------------------------------------------
  463. EOF
  464.     }
  465.     
  466.     Dump(*REP);
  467.     close(REP);
  468.  
  469.     # read in the report template once so that
  470.     # we can track whether the user does any editing.
  471.     # yes, *all* whitespace is ignored.
  472.         open(REP, "<$filename");
  473.         while (<REP>) {
  474.         s/\s+//g;
  475.         $REP{$_}++;
  476.     }
  477.     close(REP);
  478.  
  479. }
  480.  
  481. sub Dump {
  482.     local(*OUT) = @_;
  483.     
  484.     print REP "\n---\n";
  485.  
  486.     print REP "This perlbug was built using Perl $config_tag1\n",
  487.           "It is being executed now by  Perl $config_tag2.\n\n"
  488.         if $config_tag2 ne $config_tag1;
  489.  
  490.     print OUT <<EOF;
  491. Site configuration information for perl $]:
  492.  
  493. EOF
  494.  
  495.     if( $::Config{cf_by} and $::Config{cf_time}) {
  496.         print OUT "Configured by $::Config{cf_by} at $::Config{cf_time}.\n\n";
  497.     }
  498.  
  499.     print OUT Config::myconfig;
  500.  
  501.     if (@patches) {
  502.         print OUT join "\n\t", "Locally applied patches:", @patches;
  503.                 print OUT "\n";
  504.         };
  505.  
  506.     print OUT <<EOF;
  507.  
  508. ---
  509. \@INC for perl $]:
  510. EOF
  511.         for my $i (@INC) {
  512.         print OUT "\t$i\n";
  513.         }
  514.  
  515.     print OUT <<EOF;
  516.  
  517. ---
  518. Environment for perl $]:
  519. EOF
  520.         for my $env (sort
  521.              (qw(PATH LD_LIBRARY_PATH
  522.              LANG PERL_BADLANG
  523.              SHELL HOME LOGDIR),
  524.               grep { /^(?:PERL|LC_)/ } keys %ENV)) {
  525.         print OUT "    $env",
  526.                       exists $ENV{$env} ? "=$ENV{$env}" : ' (unset)',
  527.                   "\n";
  528.     }
  529.     if($verbose) {
  530.         print OUT "\nComplete configuration data for perl $]:\n\n";
  531.         my($value);
  532.         foreach (sort keys %::Config) {
  533.             $value = $::Config{$_};
  534.             $value =~ s/'/\\'/g;
  535.             print OUT "$_='$value'\n";
  536.         }
  537.     }
  538. }
  539.  
  540. sub Edit {
  541.     # Edit the report
  542.  
  543.     if($usefile) {
  544.         $usefile = 0;
  545.         paraprint <<EOF;
  546.  
  547. Please make sure that the name of the editor you want to use is correct.
  548.  
  549. EOF
  550.         print "Editor [$ed]: ";
  551.         
  552.         my($entry) =scalar(<>);
  553.         chop $entry;
  554.     
  555.         if($entry ne "") {
  556.             $ed = $entry;
  557.         } 
  558.     }
  559.     
  560. tryagain:
  561.     if(!$usefile and !$body) {
  562.         my $sts = system("$ed $filename");
  563.         if($sts) {
  564.             #print "\nUnable to run editor!\n";
  565.             paraprint <<EOF;
  566.  
  567. The editor you chose (`$ed') could apparently not be run!
  568. Did you mistype the name of your editor? If so, please
  569. correct it here, otherwise just press Enter. 
  570.  
  571. EOF
  572.             print "Editor [$ed]: ";
  573.         
  574.             my($entry) =scalar(<>);
  575.             chop $entry;
  576.     
  577.             if($entry ne "") {
  578.                 $ed = $entry;
  579.                 goto tryagain;
  580.             } else {
  581.             
  582.             paraprint <<EOF;
  583.  
  584. You may want to save your report to a file, so you can edit and mail it
  585. yourself.
  586. EOF
  587.             }
  588.         } 
  589.     }
  590.  
  591.         return if $ok;
  592.         # Check that we have a report that has some, eh, report in it.
  593.  
  594.         my $unseen = 0;
  595.  
  596.         open(REP, "<$filename");
  597.     # a strange way to check whether any significant editing
  598.     # have been done: check whether any new non-empty lines
  599.     # have been added. Yes, the below code ignores *any* space
  600.     # in *any* line.
  601.         while (<REP>) {
  602.         s/\s+//g;
  603.         $unseen++ if ($_ ne '' and not exists $REP{$_});
  604.     }
  605.  
  606.     while ($unseen == 0) {
  607.         paraprint <<EOF;
  608.  
  609. I am sorry but it looks like you did not report anything.
  610.  
  611. EOF
  612.         print "Action (Retry Edit/Cancel) ";
  613.         my ($action) = scalar(<>);
  614.         if ($action =~ /^[re]/i) { # <R>etry <E>dit
  615.             goto tryagain;
  616.         } elsif ($action =~ /^[cq]/i) { # <C>ancel, <Q>uit
  617.                 Cancel();
  618.         }
  619.         }
  620.  
  621. }
  622.  
  623. sub Cancel {
  624.     1 while unlink($filename);  # remove all versions under VMS
  625.     print "\nCancelling.\n";
  626.     exit(0);
  627. }
  628.  
  629. sub NowWhat {
  630.  
  631.     # Report is done, prompt for further action
  632.     if( !$::opt_S ) {
  633.         while(1) {
  634.  
  635.             paraprint <<EOF;
  636.  
  637.  
  638. Now that you have completed your report, would you like to send 
  639. the message to $address$andcc, display the message on 
  640. the screen, re-edit it, or cancel without sending anything?
  641. You may also save the message as a file to mail at another time.
  642.  
  643. EOF
  644.  
  645.             print "Action (Send/Display/Edit/Cancel/Save to File): ";
  646.             my($action) = scalar(<>);
  647.             chop $action;
  648.  
  649.             if( $action =~ /^(f|sa)/i ) { # <F>ile/<Sa>ve
  650.                 print "\n\nName of file to save message in [perlbug.rep]: ";
  651.                 my($file) = scalar(<>);
  652.                 chop $file;
  653.                 if($file eq "") { $file = "perlbug.rep" }
  654.             
  655.                 open(FILE,">$file");
  656.                 open(REP,"<$filename");
  657.                 print FILE "To: $address\nSubject: $subject\n";
  658.                 print FILE "Cc: $cc\n" if $cc;
  659.                 print FILE "Reply-To: $from\n" if $from;
  660.                 print FILE "\n";
  661.                 while(<REP>) { print FILE }
  662.                 close(REP);
  663.                 close(FILE);
  664.     
  665.                 print "\nMessage saved in `$file'.\n";
  666.                 exit;
  667.  
  668.             } elsif( $action =~ /^(d|l|sh)/i ) { # <D>isplay, <L>ist, <Sh>ow
  669.                 # Display the message
  670.                 open(REP,"<$filename");
  671.                 while(<REP>) { print $_ }
  672.                 close(REP);
  673.             } elsif( $action =~ /^se/i ) { # <S>end
  674.                 # Send the message
  675.                 print "\
  676. Are you certain you want to send this message?
  677. Please type \"yes\" if you are: ";
  678.                 my($reply) = scalar(<STDIN>);
  679.                 chop($reply);
  680.                 if( $reply eq "yes" ) {
  681.                     last;
  682.                 } else {
  683.                     paraprint <<EOF;
  684.  
  685. That wasn't a clear "yes", so I won't send your message. If you are sure
  686. your message should be sent, type in "yes" (without the quotes) at the
  687. confirmation prompt.
  688.  
  689. EOF
  690.                     
  691.                 }
  692.             } elsif( $action =~ /^[er]/i ) { # <E>dit, <R>e-edit
  693.                 # edit the message
  694.                 Edit();
  695.                 #system("$ed $filename");
  696.             } elsif( $action =~ /^[qc]/i ) { # <C>ancel, <Q>uit
  697.                     Cancel();
  698.             } elsif( $action =~ /^s/ ) {
  699.                 paraprint <<EOF;
  700.  
  701. I'm sorry, but I didn't understand that. Please type "send" or "save".
  702. EOF
  703.             }
  704.         
  705.         }
  706.     }
  707. }
  708.  
  709.  
  710. sub Send {
  711.  
  712.     # Message has been accepted for transmission -- Send the message
  713.     
  714.     if($::HaveSend) {
  715.  
  716.         $msg = new Mail::Send Subject => $subject, To => $address;
  717.     
  718.         $msg->cc($cc) if $cc;
  719.         $msg->add("Reply-To",$from) if $from;
  720.         
  721.         $fh = $msg->open;
  722.  
  723.         open(REP,"<$filename");
  724.         while(<REP>) { print $fh $_ }
  725.         close(REP);
  726.     
  727.         $fh->close;  
  728.     
  729.         print "\nMessage sent.\n";
  730.     } else {
  731.         if ($Is_VMS) {
  732.             if ( ($address =~ /@/ and $address !~ /^\w+%"/) or
  733.                  ($cc      =~ /@/ and $cc      !~ /^\w+%"/) ){
  734.                 my($prefix);
  735.                 foreach (qw[ IN MX SMTP UCX PONY WINS ],'') {
  736.                     $prefix = "$_%",last if $ENV{"MAIL\$PROTOCOL_$_"};
  737.                 }
  738.                 $address = qq[${prefix}"$address"] unless $address =~ /^\w+%"/;
  739.                 $cc = qq[${prefix}"$cc"] unless !$cc || $cc =~ /^\w+%"/;
  740.             }
  741.             $subject =~ s/"/""/g; $address =~ s/"/""/g; $cc =~ s/"/""/g;
  742.             my($sts) = system(qq[mail/Subject="$subject" $filename. "$address","$cc"]);
  743.             if ($sts) { die "Can't spawn off mail\n\t(leaving bug report in $filename): $sts\n;" }
  744.         } else {
  745.             my($sendmail) = "";
  746.             
  747.             foreach (qw(/usr/lib/sendmail /usr/sbin/sendmail /usr/ucblib/sendmail))
  748.             {
  749.                 $sendmail = $_, last if -e $_;
  750.             }
  751.  
  752.             if ($^O eq 'os2' and $sendmail eq "") {
  753.               my $path = $ENV{PATH};
  754.               $path =~ s:\\:/: ;
  755.               my @path = split /$Config{path_sep}/, $path;
  756.               for (@path) {
  757.                 $sendmail = "$_/sendmail", last 
  758.                   if -e "$_/sendmail";
  759.                 $sendmail = "$_/sendmail.exe", last 
  760.                   if -e "$_/sendmail.exe";
  761.               }
  762.             }
  763.             
  764.             paraprint(<<"EOF"), die "\n" if $sendmail eq "";
  765.             
  766. I am terribly sorry, but I cannot find sendmail, or a close equivalent, and
  767. the perl package Mail::Send has not been installed, so I can't send your bug
  768. report. We apologize for the inconvenience.
  769.  
  770. So you may attempt to find some way of sending your message, it has
  771. been left in the file `$filename'.
  772.  
  773. EOF
  774.             
  775.             open(SENDMAIL,"|$sendmail -t") || die "'|$sendmail -t' failed: $|";
  776.             print SENDMAIL "To: $address\n";
  777.             print SENDMAIL "Subject: $subject\n";
  778.             print SENDMAIL "Cc: $cc\n" if $cc;
  779.             print SENDMAIL "Reply-To: $from\n" if $from;
  780.             print SENDMAIL "\n\n";
  781.             open(REP,"<$filename");
  782.             while(<REP>) { print SENDMAIL $_ }
  783.             close(REP);
  784.             
  785.             if (close(SENDMAIL)) {
  786.               print "\nMessage sent.\n";
  787.             } else {
  788.               warn "\nSendmail returned status '",$?>>8,"'\n";
  789.             }
  790.         }
  791.     
  792.     }
  793.  
  794.     1 while unlink($filename);  # remove all versions under VMS
  795.  
  796. }
  797.  
  798. sub Help {
  799.     print <<EOF; 
  800.  
  801. A program to help generate bug reports about perl5, and mail them. 
  802. It is designed to be used interactively. Normally no arguments will
  803. be needed.
  804.     
  805. Usage:
  806. $0  [-v] [-a address] [-s subject] [-b body | -f file ]
  807.     [-r returnaddress] [-e editor] [-c adminaddress | -C] [-S] [-t] [-h]
  808.     
  809. Simplest usage:  run "$0", and follow the prompts.
  810.  
  811. Options:
  812.  
  813.   -v    Include Verbose configuration data in the report
  814.   -f    File containing the body of the report. Use this to 
  815.         quickly send a prepared message.
  816.   -S    Send without asking for confirmation.
  817.   -a    Address to send the report to. Defaults to `$address'.
  818.   -c    Address to send copy of report to. Defaults to `$cc'.
  819.   -C    Don't send copy to administrator.
  820.   -s    Subject to include with the message. You will be prompted 
  821.         if you don't supply one on the command line.
  822.   -b    Body of the report. If not included on the command line, or
  823.         in a file with -f, you will get a chance to edit the message.
  824.   -r    Your return address. The program will ask you to confirm
  825.         this if you don't give it here.
  826.   -e    Editor to use. 
  827.   -t    Test mode. The target address defaults to `$testaddress'.
  828.   -d    Data mode (the default if you redirect or pipe output.) 
  829.         This prints out your configuration data, without mailing
  830.         anything. You can use this with -v to get more complete data.
  831.   -ok   Report successful build on this system to perl porters
  832.         (use alone or with -v). Only use -ok if *everything* was ok.
  833.         If there were *any* problems at all then don't use -ok.
  834.   -okay As -ok but allow report from old builds.
  835.   -h    Print this help message. 
  836.   
  837. EOF
  838. }
  839.  
  840. sub paraprint {
  841.     my @paragraphs = split /\n{2,}/, "@_";
  842.     print "\n\n";
  843.     for (@paragraphs) {   # implicit local $_
  844.         s/(\S)\s*\n/$1 /g;
  845.         write;
  846.         print "\n";
  847.     }
  848.                        
  849. }
  850.                             
  851.  
  852. format STDOUT =
  853. ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ~~
  854. $_
  855. .
  856.  
  857. __END__
  858.  
  859. =head1 NAME
  860.  
  861. perlbug - how to submit bug reports on Perl
  862.  
  863. =head1 SYNOPSIS
  864.  
  865. B<perlbug> S<[ B<-v> ]> S<[ B<-a> I<address> ]> S<[ B<-s> I<subject> ]>
  866. S<[ B<-b> I<body> | B<-f> I<file> ]> S<[ B<-r> I<returnaddress> ]>
  867. S<[ B<-e> I<editor> ]> S<[ B<-c> I<adminaddress> | B<-C> ]>
  868. S<[ B<-S> ]> S<[ B<-t> ]>  S<[ B<-d> ]>  S<[ B<-h> ]>
  869.  
  870. B<perlbug> S<[ B<-v> ]> S<[ B<-r> I<returnaddress> ]> S<[ B<-ok> | B<okay> ]>
  871.  
  872. =head1 DESCRIPTION
  873.  
  874. A program to help generate bug reports about perl or the modules that
  875. come with it, and mail them. 
  876.  
  877. If you have found a bug with a non-standard port (one that was not part
  878. of the I<standard distribution>), a binary distribution, or a
  879. non-standard module (such as Tk, CGI, etc), then please see the
  880. documentation that came with that distribution to determine the correct
  881. place to report bugs.
  882.  
  883. C<perlbug> is designed to be used interactively. Normally no arguments
  884. will be needed.  Simply run it, and follow the prompts.
  885.  
  886. If you are unable to run B<perlbug> (most likely because you don't have
  887. a working setup to send mail that perlbug recognizes), you may have to
  888. compose your own report, and email it to B<perlbug@perl.com>.  You might
  889. find the B<-d> option useful to get summary information in that case.
  890.  
  891. In any case, when reporting a bug, please make sure you have run through
  892. this checklist:
  893.  
  894. =over 4
  895.  
  896. =item What version of perl you are running?
  897.  
  898. Type C<perl -v> at the command line to find out.
  899.  
  900. =item Are you running the latest released version of perl?
  901.  
  902. Look at http://www.perl.com/ to find out.  If it is not the latest
  903. released version, get that one and see whether your bug has been
  904. fixed.  Note that bug reports about old versions of perl, especially
  905. those prior to the 5.0 release, are likely to fall upon deaf ears.
  906. You are on your own if you continue to use perl1 .. perl4.
  907.  
  908. =item Are you sure what you have is a bug?
  909.  
  910. A significant number of the bug reports we get turn out to be documented
  911. features in perl.  Make sure the behavior you are witnessing doesn't fall
  912. under that category, by glancing through the documentation that comes
  913. with perl (we'll admit this is no mean task, given the sheer volume of
  914. it all, but at least have a look at the sections that I<seem> relevant).
  915.  
  916. Be aware of the familiar traps that perl programmers of various hues
  917. fall into.  See L<perltrap>.
  918.  
  919. Try to study the problem under the perl debugger, if necessary.
  920. See L<perldebug>.
  921.  
  922. =item Do you have a proper test case?
  923.  
  924. The easier it is to reproduce your bug, the more likely it will be
  925. fixed, because if no one can duplicate the problem, no one can fix it.
  926. A good test case has most of these attributes: fewest possible number
  927. of lines; few dependencies on external commands, modules, or
  928. libraries; runs on most platforms unimpeded; and is self-documenting.
  929.  
  930. A good test case is almost always a good candidate to be on the perl
  931. test suite.  If you have the time, consider making your test case so
  932. that it will readily fit into the standard test suite.
  933.  
  934. =item Can you describe the bug in plain English?
  935.  
  936. The easier it is to understand a reproducible bug, the more likely it
  937. will be fixed.  Anything you can provide by way of insight into the
  938. problem helps a great deal.  In other words, try to analyse the
  939. problem to the extent you feel qualified and report your discoveries.
  940.  
  941. =item Can you fix the bug yourself?
  942.  
  943. A bug report which I<includes a patch to fix it> will almost
  944. definitely be fixed.  Use the C<diff> program to generate your patches
  945. (C<diff> is being maintained by the GNU folks as part of the B<diffutils>
  946. package, so you should be able to get it from any of the GNU software
  947. repositories).  If you do submit a patch, the cool-dude counter at
  948. perlbug@perl.com will register you as a savior of the world.  Your
  949. patch may be returned with requests for changes, or requests for more
  950. detailed explanations about your fix.
  951.  
  952. Here are some clues for creating quality patches: Use the B<-c> or
  953. B<-u> switches to the diff program (to create a so-called context or
  954. unified diff).  Make sure the patch is not reversed (the first
  955. argument to diff is typically the original file, the second argument
  956. your changed file).  Make sure you test your patch by applying it with
  957. the C<patch> program before you send it on its way.  Try to follow the
  958. same style as the code you are trying to patch.  Make sure your patch
  959. really does work (C<make test>, if the thing you're patching supports
  960. it).
  961.  
  962. =item Can you use C<perlbug> to submit the report?
  963.  
  964. B<perlbug> will, amongst other things, ensure your report includes
  965. crucial information about your version of perl.  If C<perlbug> is unable
  966. to mail your report after you have typed it in, you may have to compose
  967. the message yourself, add the output produced by C<perlbug -d> and email
  968. it to B<perlbug@perl.com>.  If, for some reason, you cannot run
  969. C<perlbug> at all on your system, be sure to include the entire output
  970. produced by running C<perl -V> (note the uppercase V).
  971.  
  972. =back
  973.  
  974. Having done your bit, please be prepared to wait, to be told the bug
  975. is in your code, or even to get no reply at all.  The perl maintainers
  976. are busy folks, so if your problem is a small one or if it is difficult
  977. to understand or already known, they may not respond with a personal reply.
  978. If it is important to you that your bug be fixed, do monitor the
  979. C<Changes> file in any development releases since the time you submitted
  980. the bug, and encourage the maintainers with kind words (but never any
  981. flames!).  Feel free to resend your bug report if the next released
  982. version of perl comes out and your bug is still present.
  983.  
  984. =head1 OPTIONS
  985.  
  986. =over 8
  987.  
  988. =item B<-a>
  989.  
  990. Address to send the report to.  Defaults to `perlbug@perl.com'.
  991.  
  992. =item B<-b>
  993.  
  994. Body of the report.  If not included on the command line, or
  995. in a file with B<-f>, you will get a chance to edit the message.
  996.  
  997. =item B<-C>
  998.  
  999. Don't send copy to administrator.
  1000.  
  1001. =item B<-c>
  1002.  
  1003. Address to send copy of report to.  Defaults to the address of the
  1004. local perl administrator (recorded when perl was built).
  1005.  
  1006. =item B<-d>
  1007.  
  1008. Data mode (the default if you redirect or pipe output).  This prints out
  1009. your configuration data, without mailing anything.  You can use this
  1010. with B<-v> to get more complete data.
  1011.  
  1012. =item B<-e>
  1013.  
  1014. Editor to use. 
  1015.  
  1016. =item B<-f>
  1017.  
  1018. File containing the body of the report.  Use this to quickly send a
  1019. prepared message.
  1020.  
  1021. =item B<-h>
  1022.  
  1023. Prints a brief summary of the options.
  1024.  
  1025. =item B<-ok>
  1026.  
  1027. Report successful build on this system to perl porters. Forces B<-S>
  1028. and B<-C>. Forces and supplies values for B<-s> and B<-b>. Only
  1029. prompts for a return address if it cannot guess it (for use with
  1030. B<make>). Honors return address specified with B<-r>.  You can use this
  1031. with B<-v> to get more complete data.   Only makes a report if this
  1032. system is less than 60 days old.
  1033.  
  1034. =item B<-okay>
  1035.  
  1036. As B<-ok> except it will report on older systems.
  1037.  
  1038. =item B<-r>
  1039.  
  1040. Your return address.  The program will ask you to confirm its default
  1041. if you don't use this option.
  1042.  
  1043. =item B<-S>
  1044.  
  1045. Send without asking for confirmation.
  1046.  
  1047. =item B<-s>
  1048.  
  1049. Subject to include with the message.  You will be prompted if you don't
  1050. supply one on the command line.
  1051.  
  1052. =item B<-t>
  1053.  
  1054. Test mode.  The target address defaults to `perlbug-test@perl.com'.
  1055.  
  1056. =item B<-v>
  1057.  
  1058. Include verbose configuration data in the report.
  1059.  
  1060. =back
  1061.  
  1062. =head1 AUTHORS
  1063.  
  1064. Kenneth Albanowski (E<lt>kjahds@kjahds.comE<gt>), subsequently I<doc>tored
  1065. by Gurusamy Sarathy (E<lt>gsar@umich.eduE<gt>), Tom Christiansen
  1066. (E<lt>tchrist@perl.comE<gt>), Nathan Torkington (E<lt>gnat@frii.comE<gt>),
  1067. Charles F. Randall (E<lt>cfr@pobox.comE<gt>) and
  1068. Mike Guy (E<lt>mjtg@cam.a.ukE<gt>).
  1069.  
  1070. =head1 SEE ALSO
  1071.  
  1072. perl(1), perldebug(1), perltrap(1), diff(1), patch(1)
  1073.  
  1074. =head1 BUGS
  1075.  
  1076. None known (guess what must have been used to report them?)
  1077.  
  1078. =cut
  1079.  
  1080.