Perl::Critic::Policy::InputOutput::RequireCheckedOpen3pm
Write "my $error = open $fh, $mode, $filename;" instead of "open $fh, $mode, $filename;".
Affiliation
This Policy is part of the core Perl::Critic distribution.
Overview
The perl builtin I/O function "open" returns a false value on failure. That value should always be checked to ensure that the open was successful.
my $error = open( $filehandle, $mode, $filename ); # okopen( $filehandle, $mode, $filename ) or die "unable to open: $!"; # okopen( $filehandle, $mode, $filename ); # not okuse autodie;open $filehandle, $mode, $filename; # ok
You can use autodie, Fatal, or Fatal::Exception to get around this. Currently, autodie is not properly treated as a pragma; its lexical effects aren't taken into account.
Configuration
If you create a module that exports "autodie" you can tell this policy about it with the "autodie_modules" setting:
[InputOutput::RequireCheckedSyscalls]autodie_modules = My::Thing
Acknowledgments
This policy module is based heavily on policies written by Jeffrey Ryan Thalhammer <[email protected]>.
Releases
10 releases since Debian 5.0 (Lenny); the text changed 9 times.