doc patch to add documentation about providing rudiments of typed dispatch / extension.
Subject: | safe_isa.diff |
diff --git a/lib/Syntax/Keyword/Try.pm b/lib/Syntax/Keyword/Try.pm
index f9aa4ab..c6ae22e 100644
--- a/lib/Syntax/Keyword/Try.pm
+++ b/lib/Syntax/Keyword/Try.pm
@@ -271,6 +271,53 @@ useful a behaviour to be constrained to exception catching. If the language is
to provide such a facility, it should be more universally applicable as a
stand-alone independent ability.
+For porting away from typed exception library to L<Syntax::Keyword::Try>,
+consider the following code:
+
+ package My::Exceptions
+ use Import::Into;
+ use Scalar::Util;
+ use Syntax::Keyword::Try;
+ use Safe::Isa;
+
+ sub import {
+ my ($class) = @_;
+ my $who = scalar caller;
+ Syntax::Keyword::Try->import::into($who);
+ Safe::Isa->import::into($who);
+ }
+1;
+
+This provides a safe isa operation, so for example L<Error> code below:
+
+ {
+ package Bomb;
+ sub new { bless {}, 'Bomb' };
+ sub explode { die 'bang' };
+ sub defuse { print STDERR 'fizzle' };
+ }
+
+ my $bomb = Bomb->new;
+ try {
+ $bomb->explode;
+ }
+ catch Bomb with {
+ $bomb->defuse;
+ };
+
+becomes via My::Exceptions :
+
+ try {
+ $bomb->explode;
+ }
+ catch {
+ die $@ unless $_->$_isa('Bomb');
+ $bomb->defuse
+}
+
+
+
+
=cut
sub import