ソースフィルタを使わないでtry/catchを提供してくれるTryCatch

http://marcus.nordaaker.com/2009/03/a-proper-trycatch-for-perl/

メモ 後で書く

{
    package HTTPStatus;
    use Moose;
    has code => (is => 'rw', isa => 'Int', required => 1);
    __PACKAGE__->meta->make_immutable;
}

use strict;
use warnings;

use TryCatch;

sub foo {
    my $code = shift;

    try {
        die HTTPStatus->new(code => $code);
    } catch (HTTPStatus $e where {$_->code >= 400 && $_->code < 500}) {
        return '4xx client error';
    } catch (HTTPStatus $e where {$_->code >= 500 && $_->code < 600}) {
        return '5xx server error';
    } catch (HTTPStatus $e where {$_->code < 200 || $_->code >= 600}) {
        return 'Unknown error';
    }
    return 'ok';
}

warn foo(200); #ok         
warn foo(500); #'5xx server error