Skip Menu |

This queue is for tickets about the Syntax-Keyword-Try CPAN distribution.

Report information
The Basics
Id: 124120
Status: rejected
Priority: 0/
Queue: Syntax-Keyword-Try

People
Owner: Nobody in particular
Requestors: ZARQUON [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



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
I'm not going to apply this, because design is in progress for finding a proper way to do typed dispatch anyway. See also https://rt.cpan.org/Ticket/Display.html?id=123918 -- Paul Evans