Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add :trytiny_var option for $_ default exception #15

Merged
merged 1 commit into from
Jun 21, 2017

Conversation

polettix
Copy link
Contributor

This proposed change allows (lexically) setting $_ as the default exception object for kiss, hug, barf, and bleep. This makes life easier when using Ouch in team with Try::Tiny, because the latter uses $_ as the exception object that is passed around.

So, instead of doing either of the following:

use Try::Tiny;
use Ouch;
try { ouch 500, 'OUCH!' }
catch {
   if (kiss 500, $_) { ... }
   else { ... }
};

try { ouch 404, 'No luck' }
catch {
   local $@ = $_;
   if (kiss 404) { ... }
   else { ... }
}

it's possible to "just" do this:

use Try::Tiny;
use Ouch qw<:trytiny_var>;
try { ouch 500, 'OUCH!' }
catch {
   if (kiss 500) { ... }
   else { ... }
};

i.e. get full Ouch laziness and DWIM-mery back.

The change also includes tests for the new feature and documentation.

This proposed change allows (lexically) setting $_ as the default
exception object for kiss, hug, barf, and bleep. This makes life easier
when using Ouch in team with Try::Tiny, because the latter uses $_ as
the exception object that is passed around.

So, instead of doing either of the following:

    use Try::Tiny;
    use Ouch;
    try { ouch 500, 'OUCH!' }
    catch {
       if (kiss 500, $_) { ... }
       else { ... }
    };

    try { ouch 404, 'No luck' }
    catch {
       local $@ = $_;
       if (kiss 404) { ... }
       else { ... }
    }

it's possible to "just" do this:

    use Try::Tiny;
    use Ouch qw<:trytiny_var>;
    try { ouch 500, 'OUCH!' }
    catch {
       if (kiss 500) { ... }
       else { ... }
    };

i.e. get full Ouch laziness and DWIM-mery back.

The change also includes tests for the new feature and documentation.
@polettix
Copy link
Contributor Author

Hi! Any news about this?

@rizen rizen merged commit 9d93e4a into rizen:master Jun 21, 2017
@rizen
Copy link
Owner

rizen commented Jun 21, 2017

Thanks for the reminder. Somehow I missed your pull request. I've released 0.0500 to CPAN that contains your pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants