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::RequireCheckedClose - Write "my $error = close $fh;" instead of "close

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 "close" returns a false value on failure. That value should be checked to
       ensure that the close was successful.

           my $error = close $filehandle;                   # ok
           close $filehandle or die "unable to close: $!";  # ok
           close $filehandle;                               # not ok

           use autodie qw< :io >;
           close $filehandle;                               # 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::RequireCheckedClose - Write "my $error = close $fh;" instead of "close
       $fh;".

See Also