Subject: | have throw and with use record internally |
Recently I subclassed Error to do funny stuff when recording. This lets me subclass only record, and have throw/with work as expected.
--- Error.pm~ 2004-07-29 15:55:15.000000000 +0300
+++ Error.pm 2004-07-29 15:59:53.000000000 +0300
@@ -142,11 +142,11 @@
sub throw {
my $self = shift;
- local $Error::Depth = $Error::Depth + 1;
# if we are not rethrow-ing then create the object to throw
- $self = $self->new(@_) unless ref($self);
-
+ # and always record $self in $Error::Depth
+ $self = $self->record(@_);
+
die $Error::THROWN = $self;
}
@@ -156,9 +156,8 @@
sub with {
my $self = shift;
- local $Error::Depth = $Error::Depth + 1;
- $self->new(@_);
+ $self->record(@_);
}
# syntactic sugar for
@@ -169,7 +168,7 @@
my $self = shift;
local $Error::Depth = $Error::Depth + 1;
- $self->new(@_);
+ ref $self ? $self : $self->new(@_);
}
# catch clause for