NAME

Exception::Delayed - Execute code and throw exceptions later

VERSION

version 0.002

SYNOPSIS

my $x = Exception::Delayed->wantscalar(sub {
    ...
    die "meh";
    ...
}); # code is immediately executed

my $y = $x->result; # dies with "meh"

DESCRIPTION

This module is useful whenever an exception should be thrown at a later moment, without using Try::Tiny or similiar.

Since the context cannot be guessed, this module provides two entry-points: "wantscalar" and "wantlist".

METHODS

wantscalar

my $x = Exception::Delayed->wantscalar($coderef, @arguments)->result;
# same as:
my $x = scalar $coderef->(@arguments);

Execute code in a scalar context. If an exception is thrown, it will be catched and stored, but not thrown (yet).

wantlist

my @x = Exception::Delayed->wantscalar($coderef, @arguments)->result;
# same as:
my @x = $coderef->(@arguments);

Execute code in a list context. If an exception is thrown, it will be catched and stored, but not thrown (yet).

wantany

sub xxx {
    my $x = Exception::Delayed->wantany(wantarray, $coderef, @arguments);
    retrun $x->result;
}

Execute code in a list context or in a scalar context, depending on the first parameter, which should be the return value of wantarray().

result

Return the result of the executed code. Or dies, if there was any exception.

BUGS

Please report any bugs or feature requests on the bugtracker website https://github.com/zurborg/libexception-delayed-perl/issues

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.

AUTHOR

David Zurborg <zurborg@cpan.org>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2015 by David Zurborg.

This is free software, licensed under:

The ISC License