4 use File::Basename qw(&basename &dirname);
6 # List explicitly here the variables you want Configure to
7 # generate. Metaconfig only looks for shell variables, so you
8 # have to mention them as if they were shell variables, not
9 # %Config entries. Thus you write
11 # to ensure Configure will look for $Config{startperl}.
13 # This forces PL files to create target in same directory as PL file.
14 # This is so that make depend always knows where to find PL derivatives.
16 $file = basename($0, '.PL');
18 open OUT,">$file" or die "Can't create $file: $!";
20 print "Extracting $file (with variable substitutions)\n";
22 # In this section, perl variables will be expanded during extraction.
23 # You can use $Config{...} to use Configure variables.
25 print OUT <<"!GROK!THIS!";
27 eval 'exec $Config{perlpath} -S \$0 \${1+"\$@"}'
28 if \$running_under_some_shell;
31 # In the following, perl variables are not expanded during extraction.
33 print OUT <<'!NO!SUBS!';
39 eval "use Mail::Send;";
40 $::HaveSend = ($@ eq "");
41 eval "use Mail::Util;";
42 $::HaveUtil = ($@ eq "");
51 my($Version) = "1.15";
53 # Changed in 1.06 to skip Mail::Send and Mail::Util if not available.
54 # Changed in 1.07 to see more sendmail execs, and added pipe output.
55 # Changed in 1.08 to use correct address for sendmail.
56 # Changed in 1.09 to close the REP file before calling it up in the editor.
57 # Also removed some old comments duplicated elsewhere.
58 # Changed in 1.10 to run under VMS without Mail::Send; also fixed
59 # temp filename generation.
60 # Changed in 1.11 to clean up some text and removed Mail::Send deactivator.
61 # Changed in 1.12 to check for editor errors, make save/send distinction
62 # clearer and add $ENV{REPLYTO}.
63 # Changed in 1.13 to hopefully make it more difficult to accidentally
65 # Changed in 1.14 to make the prompts a little more clear on providing
66 # helpful information. Also let file read fail gracefully.
67 # Changed in 1.15 to add warnings to stop people using perlbug for non-bugs.
68 # Also report selected environment variables.
70 # TODO: Allow the user to re-name the file on mail failure, and
71 # make sure failure (transmission-wise) of Mail::Send is
74 my( $file, $usefile, $cc, $address, $perlbug, $testaddress, $filename,
75 $subject, $from, $verbose, $ed,
76 $fh, $me, $Is_VMS, $msg, $body, $andcc );
80 if($::opt_h) { Help(); exit; }
84 Please use perlbug interactively. If you want to
85 include a file, you can use the -f switch.
90 if($::opt_d or !-t STDOUT) { Dump(*STDOUT); exit; }
93 Edit() unless $usefile;
101 # -------- Setup --------
103 $Is_VMS = $^O eq 'VMS';
105 getopts("dhva:s:b:f:r:e:SCc:t");
108 # This comment is needed to notify metaconfig that we are
109 # using the $perladmin, $cf_by, and $cf_time definitions.
112 # -------- Configuration ---------
115 $perlbug = 'perlbug@perl.com';
118 $testaddress = 'perlbug-test@perl.com';
121 $address = $::opt_a || ($::opt_t ? $testaddress : $perlbug);
123 # Possible administrator addresses, in order of confidence
124 # (Note that cf_email is not mentioned to metaconfig, since
125 # we don't really want it. We'll just take it if we have to.)
126 $cc = ($::opt_C ? "" : (
127 $::opt_c || $::Config{perladmin} || $::Config{cf_email} || $::Config{cf_by}
130 # Users address, used in message and in Reply-To header
131 $from = $::opt_r || "";
133 # Include verbose configuration information
134 $verbose = $::opt_v || 0;
136 # Subject of bug-report message
137 $subject = $::opt_s || "";
140 $usefile = ($::opt_f || 0);
142 # File to send as report
143 $file = $::opt_f || "";
146 $body = $::opt_b || "";
149 $ed = ( $::opt_e || $ENV{VISUAL} || $ENV{EDITOR} || $ENV{EDIT} ||
150 ($Is_VMS ? "edit/tpu" : "vi")
162 # Explain what perlbug is
165 This program provides an easy way to create a message reporting a bug
166 in perl, and e-mail it to $address. It is *NOT* intended for
167 sending test messages or simply verifying that perl works. It is *ONLY*
168 a means of reporting verifiable problems with perl, and any solutions to
169 such problems, to the people who maintain perl.
174 # Prompt for subject of message, if needed
177 First of all, please provide a subject for the
178 message. It should be a concise description of
188 while( $subject =~ /^\s*$/ ) {
189 print "\nPlease enter a subject: ";
199 # Prompt for return address, if needed
202 # Try and guess return address
206 $domain = Mail::Util::maildomain();
208 require Sys::Hostname;
209 $domain = Sys::Hostname::hostname();
211 $domain = `hostname`.".".`domainname`;
212 $domain =~ s/[\r\n]+//g;
219 } elsif ($Is_VMS && !$::Config{'d_socket'}) {
220 $guess = "$domain\:\:$me";
222 $guess = "$me\@$domain" if $domain;
223 $guess = "$me\@unknown.addresss" unless $domain;
226 $guess = $ENV{'REPLYTO'} if defined($ENV{'REPLYTO'});
227 $guess = $ENV{"REPLY-TO"} if defined($ENV{'REPLY-TO'});
233 Your e-mail address will be useful if you need to be contacted. If the
234 default shown is not your full internet e-mail address, please correct it.
240 So that you may be contacted if necessary, please enter
241 your full internet e-mail address here.
245 print "Your address [$guess]: ";
250 if($from eq "") { $from = $guess }
254 #if( $from =~ /^(.*)\@(.*)$/ ) {
259 if( $from eq $cc or $me eq $cc ) {
260 # Try not to copy ourselves
265 # Prompt for administrator address, unless an override was given
266 if( !$::opt_C and !$::opt_c ) {
270 A copy of this report can be sent to your local
271 perl administrator. If the address is wrong, please
272 correct it, or enter 'none' or 'yourself' to not send
277 print "Local perl administrator [$cc]: ";
279 my($entry) = scalar(<>);
284 if($me eq $cc) { $cc = "" }
289 if($cc =~ /^(none|yourself|me|myself|ourselves)$/i) { $cc = "" }
291 $andcc = " and $cc" if $cc;
295 # Prompt for editor, if no override is given
296 if(! $::opt_e and ! $::opt_f and ! $::opt_b) {
300 Now you need to supply the bug report. Try to make
301 the report concise but descriptive. Include any
302 relevant detail. If you are reporting something
303 that does not work as you think it should, please
304 try to include example of both the actual
305 result, and what you expected.
307 Some information about your local
308 perl configuration will automatically be included
309 at the end of the report. If you are using any
310 unusual version of perl, please try and confirm
311 exactly which versions are relevant.
313 You will probably want to use an editor to enter
314 the report. If "$ed" is the editor you want
315 to use, then just press Enter, otherwise type in
316 the name of the editor you would like to use.
318 If you would like to use a prepared file, type
319 "file", and you will be asked for the filename.
323 print "Editor [$ed]: ";
325 my($entry) =scalar(<>);
329 if($entry eq "file") {
331 } elsif($entry ne "") {
337 # Generate scratch file to edit report in
340 my($dir) = $Is_VMS ? 'sys$scratch:' : '/tmp/';
341 $filename = "bugrep0$$";
342 $filename++ while -e "$dir$filename";
343 $filename = "$dir$filename";
347 # Prompt for file to read report from, if needed
349 if( $usefile and ! $file) {
353 What is the name of the file that contains your report?
359 my($entry) = scalar(<>);
365 No filename? I'll let you go back and choose an editor again.
371 if(!-f $entry or !-r $entry) {
374 I'm sorry, but I can't read from `$entry'. Maybe you mistyped the name of
375 the file? If you don't want to send a file, just enter a blank line and you
376 can get back to the editor selection.
388 open(REP,">$filename");
391 This is a bug report for perl from $from,
392 generated with the help of perlbug $Version running under perl $].
399 open(F,"<$file") or die "Unable to read report file from `$file': $!\n";
405 print REP "[Please enter your report here]\n";
420 Site configuration information for perl $]:
424 if( $::Config{cf_by} and $::Config{cf_time}) {
425 print OUT "Configured by $::Config{cf_by} at $::Config{cf_time}.\n\n";
428 print OUT Config::myconfig;
431 print OUT "\nComplete configuration data for perl $]:\n\n";
433 foreach (sort keys %::Config) {
434 $value = $::Config{$_};
436 print OUT "$_='$value'\n";
442 Environment for perl $]:
444 for my $env (qw(PATH LD_LIBRARY_PATH
445 PERL5LIB PERLLIB PERL5DB
446 LC_ALL LC_COLLATE LC_CTYPE LC_MONETARY LC_NUMERIC LC_TIME
448 SHELL HOME LOGDIR)) {
450 exists $ENV{$env} ? "=$ENV{$env}" : ' (unset)',
462 Please make sure that the name of the editor you want to use is correct.
465 print "Editor [$ed]: ";
467 my($entry) =scalar(<>);
476 if(!$usefile and !$body) {
477 my($sts) = system("$ed $filename");
478 if( $Is_VMS ? !($sts & 1) : $sts ) {
479 #print "\nUnable to run editor!\n";
482 The editor you chose (`$ed') could apparently not be run!
483 Did you mistype the name of your editor? If so, please
484 correct it here, otherwise just press Enter.
487 print "Editor [$ed]: ";
489 my($entry) =scalar(<>);
499 You may want to save your report to a file, so you can edit and mail it
509 # Report is done, prompt for further action
516 Now that you have completed your report, would you like to send
517 the message to $address$andcc, display the message on
518 the screen, re-edit it, or cancel without sending anything?
519 You may also save the message as a file to mail at another time.
523 print "Action (Send/Display/Edit/Cancel/Save to File): ";
524 my($action) = scalar(<>);
527 if( $action =~ /^(f|sa)/i ) { # <F>ile/<Sa>ve
528 print "\n\nName of file to save message in [perlbug.rep]: ";
529 my($file) = scalar(<>);
531 if($file eq "") { $file = "perlbug.rep" }
534 open(REP,"<$filename");
535 print FILE "To: $address\nSubject: $subject\n";
536 print FILE "Cc: $cc\n" if $cc;
537 print FILE "Reply-To: $from\n" if $from;
539 while(<REP>) { print FILE }
543 print "\nMessage saved in `$file'.\n";
546 } elsif( $action =~ /^(d|l|sh)/i ) { # <D>isplay, <L>ist, <Sh>ow
547 # Display the message
548 open(REP,"<$filename");
549 while(<REP>) { print $_ }
551 } elsif( $action =~ /^se/i ) { # <S>end
554 Are you certain you want to send this message?
555 Please type \"yes\" if you are: ";
556 my($reply) = scalar(<STDIN>);
558 if( $reply eq "yes" ) {
563 That wasn't a clear "yes", so I won't send your message. If you are sure
564 your message should be sent, type in "yes" (without the quotes) at the
570 } elsif( $action =~ /^[er]/i ) { # <E>dit, <R>e-edit
573 #system("$ed $filename");
574 } elsif( $action =~ /^[qc]/i ) { # <C>ancel, <Q>uit
575 1 while unlink($filename); # remove all versions under VMS
576 print "\nCancelling.\n";
578 } elsif( $action =~ /^s/ ) {
581 I'm sorry, but I didn't understand that. Please type "send" or "save".
592 # Message has been accepted for transmission -- Send the message
596 $msg = new Mail::Send Subject => $subject, To => $address;
598 $msg->cc($cc) if $cc;
599 $msg->add("Reply-To",$from) if $from;
603 open(REP,"<$filename");
604 while(<REP>) { print $fh $_ }
611 if ( ($address =~ /@/ and $address !~ /^\w+%"/) or
612 ($cc =~ /@/ and $cc !~ /^\w+%"/) ){
614 foreach (qw[ IN MX SMTP UCX PONY WINS ],'') {
615 $prefix = "$_%",last if $ENV{"MAIL\$PROTOCOL_$_"};
617 $address = qq[${prefix}"$address"] unless $address =~ /^\w+%"/;
618 $cc = qq[${prefix}"$cc"] unless !$cc || $cc =~ /^\w+%"/;
620 $subject =~ s/"/""/g; $address =~ s/"/""/g; $cc =~ s/"/""/g;
621 my($sts) = system(qq[mail/Subject="$subject" $filename. "$address","$cc"]);
622 if (!($sts & 1)) { die "Can't spawn off mail\n\t(leaving bug report in $filename): $sts\n;" }
626 foreach (qw(/usr/lib/sendmail /usr/sbin/sendmail /usr/ucblib/sendmail))
628 $sendmail = $_, last if -e $_;
631 paraprint <<"EOF" and die "\n" if $sendmail eq "";
633 I am terribly sorry, but I cannot find sendmail, or a close equivalent, and
634 the perl package Mail::Send has not been installed, so I can't send your bug
635 report. We apologize for the inconveniencence.
637 So you may attempt to find some way of sending your message, it has
638 been left in the file `$filename'.
642 open(SENDMAIL,"|$sendmail -t");
643 print SENDMAIL "To: $address\n";
644 print SENDMAIL "Subject: $subject\n";
645 print SENDMAIL "Cc: $cc\n" if $cc;
646 print SENDMAIL "Reply-To: $from\n" if $from;
647 print SENDMAIL "\n\n";
648 open(REP,"<$filename");
649 while(<REP>) { print SENDMAIL $_ }
657 print "\nMessage sent.\n";
659 1 while unlink($filename); # remove all versions under VMS
666 A program to help generate bug reports about perl5, and mail them.
667 It is designed to be used interactively. Normally no arguments will
671 $0 [-v] [-a address] [-s subject] [-b body | -f file ]
672 [-r returnaddress] [-e editor] [-c adminaddress | -C] [-S] [-t]
674 Simplest usage: run "$0", and follow the prompts.
678 -v Include Verbose configuration data in the report
679 -f File containing the body of the report. Use this to
680 quickly send a prepared message.
681 -S Send without asking for confirmation.
682 -a Address to send the report to. Defaults to `$address'.
683 -c Address to send copy of report to. Defaults to `$cc'.
684 -C Don't send copy to administrator.
685 -s Subject to include with the message. You will be prompted
686 if you don't supply one on the command line.
687 -b Body of the report. If not included on the command line, or
688 in a file with -f, you will get a chance to edit the message.
689 -r Your return address. The program will ask you to confirm
690 this if you don't give it here.
692 -t Test mode. The target address defaults to `$testaddress'.
693 -d Data mode (the default if you redirect or pipe output.)
694 This prints out your configuration data, without mailing
695 anything. You can use this with -v to get more complete data.
701 my @paragraphs = split /\n{2,}/, "@_";
703 for (@paragraphs) { # implicit local $_
713 ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ~~
718 close OUT or die "Can't close $file: $!";
719 chmod 0755, $file or die "Can't reset permissions for $file: $!\n";
720 exec("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':';