logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

Perl::Critic::Policy::InputOutput::RequireCheckedOpen - Write "my $error = open $fh, $mode, $filename;"

Acknowledgments

       This policy module is based heavily on policies written by Jeffrey Ryan Thalhammer
       <jeff@imaginative-software.com>.

Affiliation

       This Policy is part of the core Perl::Critic distribution.

Author

       Andrew Moore <amoore@mooresystems.com>

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

Description

       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 );                  # ok
           open( $filehandle, $mode, $filename ) or die "unable to open: $!";  # ok
           open( $filehandle, $mode, $filename );                              # not ok

           use 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.

Name

       Perl::Critic::Policy::InputOutput::RequireCheckedOpen - Write "my $error = open $fh, $mode, $filename;"
       instead of "open $fh, $mode, $filename;".

See Also