Perl::...dClose(3pm)
π NAME
Okay so this page is Perl::...dClose(3pm) β the terminal squished it, it's literally Perl::Critic::Policy::InputOutput::RequireCheckedClose β and it's here to tell you: write my $error = close $fh; instead of just close $fh;. That's the whole vibe. β¨
π«Ά AFFILIATION
This policy is part of the core Perl::Critic distribution β so if you have Perl::Critic, congrats bestie, you already have this one. No extra install arc required. π
π₯ DESCRIPTION
So the perl builtin I/O function close returns a false value on failure. Like, it tells you when it didn't work. And that value should be checked, fr fr, so you actually know the close was successful and not silently falling apart. π«
my $error = close $filehandle; # ok
close $filehandle or die "unable to close: $!"; # ok
close $filehandle; # not ok
use autodie qw< :io >;
close $filehandle; # ok
See how the third one is just... sitting there, unbothered, not checking anything? Not ok. Do not be that line of code. π
You can use autodie, Fatal, or Fatal::Exception to get around this β they handle the checking for you, so the policy chills out. But heads up: currently, autodie is not properly treated as a pragma; its lexical effects aren't taken into account. So the vibe-check is imperfect, no cap. π
π CONFIGURATION
If you create a module that exports autodie, you can tell this policy about it with the autodie_modules setting β like this:
[InputOutput::RequireCheckedSyscalls]
autodie_modules = My::Thing
Yes, that's the key you want, bestie β autodie_modules. Go off. π
πΈ AUTHOR
Andrew Moore <amoore@mooresystems.com> β iconic, we stan. π
π¦ ACKNOWLEDGMENTS
This policy module is based heavily on policies written by Jeffrey Ryan Thalhammer <jeff@imaginative-software.com>. Shoutout to the originator, absolute main character energy. π
π COPYRIGHT
Copyright (c) 2007-2011 Andrew Moore. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of this license can be found in the LICENSE file included with this module. π
And that's the whole page, bestie β brought to you by perl v5.42.0, dated 2024-10-23, and by the letter C for CheckedClose. Go check your closes. ππβ¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-Perl-Critic 1.156.0-bp160.1.1 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms