Getting exceptions from IO :: File?

The IO :: File, IO :: Socket :: INET modules have some advantages over the direct use of the perl built-in I / O functions, such as having explicit syntax for cleaning the descriptor.

However, they seem to have some drawbacks regarding the built-in I / O functions. For example, as far as I can tell, they cannot be combined with the autodie module to raise exceptions in case of failure, so I have to write more general template code for failing than with the built-in functions.

Is there a way to combine two or some other modules with combined functions? I noticed some limited-purpose I / O modules, such as File :: Slurp, allow more flexible error handling.

I am writing module code, and, ideally, the solution should fully work with perl 5.10.0.

+7
exception perl autodie perl-io
source share
1 answer

Have you looked at Path :: Tiny? The syntax is different, but it throws exceptions.

eg.

use Path::Tiny; path('/non/existent/file')->openr; 

will die with the Path :: Tiny :: Exception object (if you do not have such a file)

+2
source share

All Articles