Perl::Critic::Policy::InputOutput::RequireCheckedClose(3pm)

Perl::Critic::Policy::InputOutput::RequireCheckedClose3pm

Write "my $error = close $fh;" instead of "close $fh;".

Affiliation

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

Overview

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.

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.

  1. 5.0
  2. 6.0
  3. 7
  4. 8
  5. 9
  6. 10
  7. 11
  8. 12
  9. 13
  10. Arch

Author

Andrew Moore <[email protected]>

From perl-perl-critic 1.156-3 in Arch Linux 2026-11-01. Parsed by carta from the page's man source.