Closed p5pRT closed 20 years ago
when I pass $1 to a subroutine\, the subroutine can access the value of the variable\, but the debugger T command and Carp::carp display the argument as undef.
use Carp; sub t { carp "t(@_)\n"; } t("abc"); $_="1234567"; m/^..(...)..$/; t($1);
t(abc) main::t('abc') called at c line 4 t(345) main::t('undef') called at c line 7
This seems to be a very old bug - perl5.002 has it.
Patch for Carp attached. Also mends another obscure bug - you must never localise @DB::args; it discombobulates caller(). And a small redundancy removed and several questions answered.
The debugger case will take a little longer to fix. Exactly the same issue\, but *much* messier code.
Summary of my perl5 (revision 5.0 version 7 subversion 17) configuration: ^^ Eh? What version of Perl is that?
Mike Guy
Very early version of bleadperl? :-)
That's what perl -V gives you . I once fixed myconfig but apparently not that (though I must check how the thing works with 5.8.0...)
kosh:/tmp/jhi/perl ; ./myconfig Summary of my perl5 (revision 5.0 version 7 subversion 1 patchlevel 10824) configuration: Platform: ...
From: Jarkko Hietaniemi \jhi@​iki\.fi
On Sun\, Jun 24\, 2001 at 03:28:39PM +0100\, Mike Guy wrote:
David Dyck \dcd@​tc\.fluke\.com wrote
Summary of my perl5 (revision 5.0 version 7 subversion 17) configuration: ^^ Eh? What version of Perl is that?
Very early version of bleadperl? :-)
That's what perl -V gives you . I once fixed myconfig but apparently not that (though I must check how the thing works with 5.8.0...)
kosh:/tmp/jhi/perl ; ./myconfig Summary of my perl5 (revision 5.0 version 7 subversion 1 patchlevel 10824) configuration: Platform:
here's what my myconfig prints dd:perl-current$ ./myconfig Summary of my perl5 (revision 5.0 version 7 subversion 1 patchlevel 10742) configuration: ...
Good idea.
Ocassionally I've had a need to use longmess() directly\, but haven't been able to put it in production code as it's undocumented\, and could theoretically disappear.
In fact\, they are already used\, by CGI::Carp\, ExtUtils::MakeMaker and perl5db.pl in the core\, and no doubt in various CPAN modules as well. So they're unlikely to disappear.
I found your suggested patch slightly eccentric\, in documenting them under "BUGS". :-) I attach my suggestion.
Mike Guy
Thanks\, applied. (And the earlier version retracted.)
Can we think of a better name than longmess/shortmess? backtrace/??? Or perhaps something more in line with the whole carp/croak/cluck feel.
Note that whatever we do\, the old names must stay before other modules already use those names.
Or perhaps something more in line with the whole carp/croak/cluck feel.
yodle/yelp? :-)
cry\, cuss\, curse\, caterwaul\, complain(t)
mutter(ed)\, moan(ed)
whimper\, whine
language is such a fun thing. :>
I like it! (Well\, yodel) Patch follows plus a rewrite of Carp.t plus I removed all the uses of longmess and shortmess I could find.
PS The original Carp.t is a perfect example of a Far Too Clever test.
PPS This is a good example of using Test::More
--- lib/CGI/Carp.pm 2001/06/26 05:40:22 1.1
+++ lib/CGI/Carp.pm 2001/06/26 05:42:24
@@ -293\,10 +293\,10 @@
# The mod_perl package Apache::Registry loads CGI programs by calling
# eval. These evals don't count when looking at the stack backtrace.
sub _longmess {
- my $message = Carp::longmess();
+ my $message = Carp::yodel();
my $mod_perl = exists $ENV{MOD_PERL};
$message =~ s\,eval[^\n]+Apache/Registry\.pm.*\,\,s if $mod_perl;
- return $message;
+ return $message;
}
sub die { @@ -321\,10 +321\,10 @@ { local $^W=0; eval \<\<EOF; -sub confess { CGI::Carp::die Carp::longmess \@_; } -sub croak { CGI::Carp::die Carp::shortmess \@_; } -sub carp { CGI::Carp::warn Carp::shortmess \@_; } -sub cluck { CGI::Carp::warn Carp::longmess \@_; } +sub confess { CGI::Carp::die Carp::yodel \@_; } +sub croak { CGI::Carp::die Carp::yelp \@_; } +sub carp { CGI::Carp::warn Carp::yodel \@_; } +sub cluck { CGI::Carp::warn Carp::yelp \@_; } EOF ; } --- lib/ExtUtils/MakeMaker.pm 2001/06/26 05:35:21 1.1 +++ lib/ExtUtils/MakeMaker.pm 2001/06/26 05:36:20 @@ -2\,7 +2\,7 @@
package ExtUtils::MakeMaker;
-$VERSION = "5.45"; +$VERSION = "5.46"; $Version_OK = "5.17"; # Makefiles older than $Version_OK will die # (Will be checked from MakeMaker version 4.13 onwards) ($Revision = substr(q$Revision: 1.1 $\, 10)) =~ s/\s+$//; @@ -381\,7 +381\,7 @@ }
# This is for old Makefiles written pre 5.00\, will go away - if ( Carp::longmess("") =~ /runsubdirpl/s ){ + if ( Carp::yodel("") =~ /runsubdirpl/s ){ Carp::carp("WARNING: Please rerun 'perl Makefile.PL' to regenerate your Makefiles\n"); }
--- lib/Carp.pm 2001/06/25 17:56:19 1.1 +++ lib/Carp.pm 2001/06/26 05:25:56 @@ -21\,8 +21\,10 @@ use Carp qw(cluck); cluck "This is how we got here!";
- print FH Carp::shortmess("This will have caller's details added"); - print FH Carp::longmess("This will have stack backtrace added"); + use Carp qw(yodel yelp); + my $warning = yelp "Its like carp\, but doesn't warn"; + my $trace = yodel "Like cluck\, but returns the stack trace"; +
=head1 DESCRIPTION
@@ -33\,8 +35\,8 @@ will report the error as occurring where Foo() was called\, not where carp() was called.
-The routine shortmess() can be used to generate the string that -carp/croak would have produced. The routine longmess() can be +The routine yelp() can be used to generate the string that +carp/croak would have produced. The routine yodel() can be used to generate the backtrace that cluck/confess would have produced.
@@ -83\,7 +85\,7 @@ require Exporter; @ISA = ('Exporter'); @EXPORT = qw(confess croak carp); -@EXPORT_OK = qw(cluck verbose longmess shortmess); +@EXPORT_OK = qw(cluck verbose yodel yelp); @EXPORT_FAIL = qw(verbose); # hook to enable verbose mode
@@ -121\,6 +123\,12 @@ { local $@; require Carp::Heavy; } # XXX fix require to not clear $@? goto &shortmess_heavy; } + +# long and shortmess must stay around because some things use them. +# Eventually\, yodel/yelp should replace longmess/shortmess and they +# will become the aliases instead of vice-versa. +*yodel = \&longmess; +*yelp = \&shortmess;
# the following four functions call longmess() or shortmess() depending on --- lib/Carp.t 2001/06/26 05:08:28 1.1 +++ lib/Carp.t 2001/06/26 05:33:24 @@ -1\,53 +1\,83 @@ BEGIN { - chdir 't' if -d 't'; - @INC = '../lib'; + chdir 't' if -d 't'; + @INC = '../lib'; }
-use Carp qw(carp cluck croak confess); +use Test::More tests => 13;
-print "1..7\n"; +require_ok("Carp");
-print "ok 1\n"; +{ + # Test that Carp exports the right things by default. + package Testing::Carp;
-$SIG{__WARN__} = sub { - print "ok $1\n" - if $_[0] =~ m!ok (\d+)$! }; + ::ok( !grep(defined &{$_}\, qw(&carp croak confess cluck yodel yelp))\, + 'namespace is clean' );
-carp "ok 2\n";
-
-$SIG{__WARN__} = sub {
- print "ok $1\n"
- if $_[0] =~ m!(\d+) at .+\b(?i:carp\.t) line \d+$! };
+ Carp->import;
-carp 3; + ::ok( !grep(!defined &{$_}\, qw(carp croak confess))\, + 'exported the expected defaults' );
-sub sub_4 { + Carp->import(qw(cluck yodel yelp)); + + ::ok( !grep(!defined &{$_}\, qw(cluck yodel yelp))\, + 'exported the extras' ); +} + + +use Carp qw(:DEFAULT cluck yodel yelp); + +my($warning) = ''; +local $SIG{__WARN__} = sub { $warning = $_[0] }; + +carp("ok 2\n"); +is($warning\, "ok 2\n"\, 'carp with newline'); +
-$SIG{__WARN__} = sub { - print "ok $1\n" - if $_[0] =~ m!^(\d+) at .+\b(?i:carp\.t) line \d+\n\tmain::sub_4\(\) called at .+\b(?i:carp\.t) line \d+$! }; +carp(3); +like($warning\, qr!3 at .+\b(?i:carp\.t) line \d+$!\, 'simple carp');
-cluck 4;
+sub sub_4 { + cluck(4); } +sub_4();
-sub_4; +like($warning\, qr!^(\d+) at .+\b(?i:carp\.t) line \d+\n\tmain::sub_4\(\) called at .+\b(?i:carp\.t) line \d+$!\, 'cluck inside subroutine');
-$SIG{__DIE__} = sub { - print "ok $1\n" - if $_[0] =~ m!^(\d+) at .+\b(?i:carp\.t) line \d+\n\teval \Q{...}\E called at .+\b(?i:carp\.t) line \d+$! };
-eval { croak 5 }; +eval { croak(5) }; +like($@\, qr!^(\d+) at .+\b(?i:carp\.t) line \d+\n\teval \Q{...}\E called at .+\b(?i:carp\.t) line \d+$!\, 'simple croak');
-sub sub_6 { - $SIG{__DIE__} = sub { - print "ok $1\n" - if $_[0] =~ m!^(\d+) at .+\b(?i:carp\.t) line \d+\n\teval \Q{...}\E called at .+\b(?i:carp\.t) line \d+\n\tmain::sub_6\(\) called at .+\b(?i:carp\.t) line \d+$! };
- eval { confess 6 }; + +sub sub_6 { + eval { confess(6) }; }
sub_6;
-print "ok 7\n"; +like($@\, qr!^(\d+) at .+\b(?i:carp\.t) line \d+\n\teval \Q{...}\E called at .+\b(?i:carp\.t) line \d+\n\tmain::sub_6\(\) called at .+\b(?i:carp\.t) line \d+$!\, 'confess inside subroutine' ); + + +my $yodel; +sub sub_7 { + eval { + # These must be on the same line for the message to come out + # the same. + $yodel = yodel("foo"); cluck("foo"); confess("foo"); + }; +} +sub_7(); +is($warning\, $@\, 'cluck/confess output the same thing'); +is($warning\, $yodel\, ' so does yodel'); +
+my $yelp; +eval { + # These must also be on the same line. + $yelp = yelp("bar"); carp("bar"); croak("bar"); +}; +is($warning\, $@\, 'carp/croak output the same thing'); +is($warning\, $yelp\, ' so does yelp'); --- lib/perl5db.pl 2001/06/26 05:36:41 1.1 +++ lib/perl5db.pl 2001/06/26 05:37:44 @@ -2643\,10 +2643\,10 @@ local $doret = -2; $SIG{'ABRT'} = 'DEFAULT'; kill 'ABRT'\, $$ if $panic++; - if (defined &Carp::longmess) { + if (defined &Carp::yodel) { local $SIG{__WARN__} = ''; local $Carp::CarpLevel = 2; # mydie + confess - &warn(Carp::longmess("Signal @_")); + &warn(Carp::yodel("Signal @_")); } else { print $DB::OUT "Got signal @_\n"; @@ -2662\,10 +2662\,10 @@ eval { require Carp } if defined $^S; # If error/warning during compilation\, # require may be broken. CORE::warn(@_\, "\nCannot print stack trace\, load with -MCarp option to see stack")\, - return unless defined &Carp::longmess; + return unless defined &Carp::yodel; my ($mysingle\,$mytrace) = ($single\,$trace); $single = 0; $trace = 0; - my $mess = Carp::longmess(@_); + my $mess = Carp::yodel(@_); ($single\,$trace) = ($mysingle\,$mytrace); &warn($mess); } @@ -2688\,13 +2688\,13 @@ # require may be broken.
die(@_\, "\nCannot print stack trace\, load with -MCarp option to see stack") - unless defined &Carp::longmess; + unless defined &Carp::yodel;
# We do not want to debug this chunk (automatic disabling works # inside DB::DB\, but not in Carp). my ($mysingle\,$mytrace) = ($single\,$trace); $single = 0; $trace = 0; - my $mess = Carp::longmess(@_); + my $mess = Carp::yodel(@_); ($single\,$trace) = ($mysingle\,$mytrace); die $mess; }
I liked it too\, but yodel is equally commonly spelt in one of two ways\, which ain't so cool. A whole lot more fun than shortmess/longmess though!
> On Mon\, Jun 25\, 2001 at 11:09:12PM -0500\, Jarkko Hietaniemi wrote:
Can we think of a better name than longmess/shortmess? backtrace/???
Note that whatever we do\, the old names must stay before other modules already use those names.
Or perhaps something more in line with the whole carp/croak/cluck feel.
yodle/yelp? :-)
> I like it! (Well\, yodel) Patch follows plus a rewrite of Carp.t plus I > removed all the uses of longmess and shortmess I could find.
Your style of naming things is just plain sick:
AnyLoader does anything but interface to any loader. Ima::DBI has something to do with DBI\, but nothing with Ima. D::oh is the only really funny one. But it's from 1999 and getting old. Sex: I still don't know if it is fun or what. Bone::Easy? Same here. Semi::Semicolon? Same here.
And now yodle!
What's the problem you're trying to solve? Is perl not hard and confusing enough?
I'm not convinced about this - the other functions are verbs related to speaking because they write to stderr. shortmess and longmess don't do this.
Hugo
Even though I came up with the y/y pair I tend to agree. Different use\, different names.
Hugo
Thank you. :)
Ima::DBI has something to do with DBI\, but nothing with Ima.
I'm a DBI. GET IT?! Nobody does *grumble*
D::oh is the only really funny one. But it's from 1999 and getting old.
That's D'oh\, and I blame Pudge.
Sex: I still don't know if it is fun or what.
They have a pill for that now\, ya know. ;)
Bone::Easy? Same here.
You know what they say about a fisherman with hot brains.
And now yodle!
I hereby transfer all blame to Jarko Hietaniemi under the Blame Transfer Protocol\, RFC pending.
You forgot uny2k\, loose and UNIVERSAL::exports. :)
What's the problem you're trying to solve? Is perl not hard and confusing enough?
Oh\, you thought this was about solving problems?! No no no\, its about bad puns and wordplay. :)
--
Michael G. Schwern \schwern@​pobox\.com http://www.pobox.com/~schwern/ Perl6 Quality Assurance \perl\-qa@​perl\.org Kwalitee Is Job One Instant Cross-Platform CGI Programming in Visual Perl 5 with Object Oriented Design in 7 Days Unleashed for Dummies Special Edition with Exclusive Java Chapters for Developers. Year 2000 compliant\, Enterprise edition and ISO9000- certified. A Nutshell Handbook Designed For Windows 95/98/NT with a forward by Larry "Bud" Melman. Interactive Multimedia CDROM included. 3rd revised editon\, covers Perl5.6. Of course\, it will be refered to by its simple acronym: ICPCGIPiVP5wOODi7DU4DSEwEJC4DY2KCEedISO9000-cNHD4W9598NTLBMIMCDROM3edP5.6
[snip various defenses and (possibly inappropriate\, due to lack of proxy) BTP use]
You didn't address Andreas' complaint about Semi::Semicolons\, so I'll do that for you.
Schwern can blame me for that\, and I\, in turn can blame Ziggy. And possibly the Egyptians or Mesopatamians or someone for inventing beer. Randal was also a bystander - innocent or not\, I'll leave up to the jury...
:-)
dha
Okay\, then what's a good term for raising objections in a written forum?
I'm the source\, Jarrko is the target\, Andreas (and p5p) the proxy. That's the trouble with relying on these draft protocols.
Flame? :-)
-Rich
I still think more protocols should be bashed out over drinks\, though...
dha
Drinks? Draft protocol? Get it? HA!
Corollary to Godwin's Law: "As a p5p thread grows longer\, the probability of a bad pun approaches one. Once this occurs\, that thread is over\, and whoever inflicted the pun is beaten to within an inch of his life."
Migrated from rt.perl.org#7170 (status was 'resolved')
Searchable as RT7170$