7

The IO::File, IO::Socket::INET modules have some advantages over directly using perl's built-in IO functions, such as having explicit syntax to flush a handle.

However, they seem to have some disadvantages over the built-in IO functions. For example, as far as I can tell they can't be combined with the autodie module to raise exceptions on failure, so I'm finding myself having to write overall more boilerplate code to handle failures than I was with built-in functions.

Is there a way to combine the two, or some other modules that have the combined functionality? I've noticed some limited-purpose IO modules, such as File::Slurp, do allow more flexible error handling.

I'm writing module code, and ideally, the solution should work all the way back to perl 5.10.0.

John Dough
  • 400
  • 3
  • 9
  • 8
    Note that file handles are/contain `IO::File` objects anyway (given a sufficiently modern perl, and maybe an `use IO::File` to load the methods) – so you can use the builtins like `open` without giving up the OOP features. – amon Dec 19 '13 at 20:59

1 Answers1

2

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

E.G.

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

will die with a Path::Tiny::Exception object (assuming you don't have such a file)