What is the difference between Perl modules autodie and Fatal?
Asked Answered
T

3

6

The Perl modules autodie and Fatal seem to be doing similar things. What are the reasons for using one in preference to the other?

Tichon answered 5/4, 2010 at 11:17 Comment(1)
Paul Fenwick's article autodie - The art of Klingon Programming starts with an explanation of some of Fatal's shortcomings.Chaves
H
11

The Fatal module was added to the Perl core in version 5.05 (1998). The Fatal module has some significant shortcomings and inconsistencies in its API which couldn't be fixed in a backwards compatible way (ie: fixing the API would break existing code which used Fatal).

The newer autodie module was written to provide a more consistent API and to allow the effect of the pragma to be lexically scoped rather than global (which can have unexpected side effects).

If you have a choice, you should definitely prefer autodie. It will be included as a core module in the upcoming 5.12 release of Perl.

The autodie module requires Perl 5.8. About the only reason you'd use Fatal is if you were stuck with a really old version of Perl (eg: 5.6), but 5.8 has been out since 2002 so hopefully that won't be the case for you.

Heterogony answered 6/4, 2010 at 1:2 Comment(0)
A
7

To quote the Fatal documentation

Fatal has been obsoleted by the new autodie pragma. Please use autodie in preference to Fatal. autodie supports lexical scoping, throws real exception objects, and provides much nicer error messages.

Amor answered 5/4, 2010 at 11:23 Comment(0)
J
2

Another reason to use autodie instead of Fatal is to avoid this bug (from the BUGS section of the Fatal docs):

Fatal clobbers the context in which a function is called and always makes it a scalar context, except when the :void tag is used. This problem does not exist in autodie.

Jittery answered 5/4, 2010 at 13:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.