--- Error-0.15/Error.pm Tue Feb 10 18:37:07 2004
+++ /tmp/Error.pm Thu Apr 15 12:13:04 2004
@@ -250,6 +250,36 @@
$text;
}
+sub id () {
+ my $self = shift;
+
+ my $id = $self->{id};
+
+ if ( defined( $id )) {
+ return( $id );
+ }
+
+ $self->{id} = Message->id( from => $self->{-text} );
+ return( $self->{ id } );
+}
+
+sub idMatches {
+ my $self = shift;
+
+ my %args;
+ my %targs = @_;
+ foreach my $arg ( keys %targs ) {
+ $args{ lc( $arg ) } = lc( $targs{ $arg } );
+ }
+ my $argID = $args{ id };
+
+ my $id = lc($self->id());
+
+ my $match = ( $id eq $argID );
+
+ return $match;
+}
+
##########################################################################
##########################################################################
@@ -258,10 +288,11 @@
package Error::subs;
+use Data::Dumper;
use Exporter ();
use vars qw(@EXPORT_OK @ISA %EXPORT_TAGS);
-@EXPORT_OK = qw(try with finally except otherwise);
+@EXPORT_OK = qw(try with finally except otherwise catch annotate );
%EXPORT_TAGS = (try => \@EXPORT_OK);
@ISA = qw(Exporter);
@@ -269,9 +300,19 @@
sub run_clauses ($$$\@) {
my($clauses,$err,$wantarray,$result) = @_;
my $code = undef;
+ my $annotate = $clauses->{'annotate'};
$err = new Error::Simple($err) unless ref($err);
+ #-----------------------------------------
+ # Prepend the annotation if there is one.
+ # Keep the message id in front.
+ #-----------------------------------------
+ if(defined($annotate)) {
+ my $annotation = eval{ $annotate->() };
+ $err->{'-stacktrace'} = $annotation . $err if !$@ && $annotation ne '';
+ }
+
CATCH: {
# catch
@@ -282,6 +323,7 @@
CATCHLOOP:
for( ; $i < @$catch ; $i += 2) {
my $pkg = $catch->[$i];
+
unless(defined $pkg) {
#except
splice(@$catch,$i,2,$catch->[$i+1]->());
@@ -324,7 +366,11 @@
# otherwise
my $owise;
- if(defined($owise = $clauses->{'otherwise'})) {
+ if ( (! $err->isa('Termination') ) &&
+ ( defined( $owise = $clauses->{'otherwise'} )))
+ {
+
+# if(defined($owise = $clauses->{'otherwise'})) {
my $code = $clauses->{'otherwise'};
my $more = 0;
my $ok = eval {
@@ -463,6 +509,29 @@
$clauses;
}
+sub catch (&;$) {
+ if ( ref( $_[0] ) eq "CODE" ) {
+ goto &otherwise;
+ }
+ else {
+ Error::catch( @_ );
+ }
+}
+
+sub annotate (&;$) {
+ my $code = shift;
+ my $clauses = shift || {};
+
+ if(exists $clauses->{'annotate'}) {
+ require Carp;
+ Carp::croak("Multiple annotate clauses");
+ }
+
+ $clauses->{'annotate'} = $code;
+
+ $clauses;
+}
+
1;
__END__