Aran Clary Deltac

NAME

Perl::Critic::Policy::TryTiny::RequireUse - Requires that code which utilizes Try::Tiny actually use()es it.

DESCRIPTION

A common problem with Try::Tiny is forgetting to use the module in the first place. For example:

    perl -e 'try { print "hello" } catch { print "world" }'
    Can't call method "catch" without a package or object reference at -e line 1.
    helloworld

If you forget this then both code blocks will be run and an exception will be thrown. While this seems like a rare issue, when I first implemented this policy I found several cases of this issue in real live code and due to layers of exception handling it had gotten lost and nobody realized that there was a bug happening due to the missing use statements.

This policy is OK if you use Error, Syntax::Feature::Try, Try, Try::Catch, and TryCatch modules which also export the try function.

SEE ALSO

AUTHOR

Aran Clary Deltac <bluefeet@gmail.com>

ACKNOWLEDGEMENTS

Thanks to ZipRecruiter for encouraging their employees to contribute back to the open source ecosystem. Without their dedication to quality software development this distribution would not exist.

LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.