develooper Front page | perl.perl5.porters | Postings from December 2000

UPDATE: Carp/Heavy now passes all tests

From:
Ben Tilly
Date:
December 5, 2000 05:00
Subject:
UPDATE: Carp/Heavy now passes all tests
Message ID:
LAW2-F58V1qdiixjnzi00005523@hotmail.com
I just have to admit to being stupid sometimes.

I had an incorrectly formatted message. :-(

With this patch to my new Carp/Heavy.pm I now pass all
of the tests in pragma/warnings.t.  Areas of future
improvement, give more flexibility over the trust
relationship, internal documentation on %Carp::Internal
and %Carp::CarpInternal, better messages for the case
where you have references (hook it up to Data::Dumper?),
rewrite warnings.pm to use the internal hooks, find out
*WHY* the messages just return immediately if the first
argument is an object...

This fixes several things including improved behaviour
on truncating strings (the old max length wasn't really),
correctly handles arguments like "5\n" (the old thought
that was a number), less obfuscated code, a more
straightforward algorithm for carp and croak to figure
out where the message comes from, and circular inheritance
no longer causes deep recursion.

Cheers,
Ben

--- Carp/Heavy.pm.00.12.02      Mon Dec  4 19:48:04 2000
+++ Carp/Heavy.pm       Mon Dec  4 20:27:16 2000
@@ -58,7 +58,7 @@
sub get_status {
     my $cache = shift;
     my $pkg = shift;
-    $cache->{$pkg} ||= [{}, [trusts_directly($pkg)]];
+    $cache->{$pkg} ||= [{$pkg => $pkg}, [trusts_directly($pkg)]];
     return @{$cache->{$pkg}};
}

@@ -131,13 +131,12 @@
     $mess = $err;
   }
   else {
-    my %info = caller_info($i);
-    $mess = "$err at $info{file} line $info{line}$tid_msg\n";
+    my %i = caller_info($i);
+    $mess = "$err at $i{file} line $i{line}$tid_msg\n";
   }

-  while (my %call_info = caller_info(++$i)) {
-    my %info = caller_info($i);
-    $mess .= "\t$info{sub_name} called at $info{file} line 
$line$tid_msg\n";
+  while (my %i = caller_info(++$i)) {
+    $mess .= "\t$i{sub_name} called at $i{file} line $i{line}$tid_msg\n";
   }

   return $mess || $err;
@@ -155,8 +154,8 @@
     $tid_msg = " thread $tid" if $tid;
   }

-  my %info = caller_info($i);
-  return "$err at $info{file} line $info{line}$tid_msg\n";
+  my %i = caller_info($i);
+  return "$err at $i{file} line $i{line}$tid_msg\n";
}

_____________________________________________________________________________________
Get more from the Web.  FREE MSN Explorer download : http://explorer.msn.com




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About