File::...Default(3pm)
π File::Policy::Default π
the default policy for file I/O functions β it's the Perl doc page from the User Contributed Perl Documentation collection, bestie, and yes it's lowkey the chillest policy that ever policied π
β¨ SYNOPSIS β¨
okay so here's how you actually use it, no cap:
use File::Policy;
use File::Policy qw/check_safe/; # to import a specific subroutine
use File::Policy qw/:all/; # to import all subroutines
#Checking I/O policy
check_safe($filename, 'r');
check_safe($filename, 'w');
#Portable directory locations
$logdir = get_log_dir();
$tmpdir = get_temp_dir();
first line pulls in the module, then you got your two import flavors β either grab one specific subroutine or literally all of them with :all. pick your fighter π
πΈ DESCRIPTION πΈ
This defines the default (unrestricted) policy for file I/O with modules such as File::Slurp::WithinPolicy. You may replace this default policy with one for your organisation.
so likeβ¦ it's the starter pack policy, the "no rules, we're just vibing" policy, and if your org needs to be strict about it, you swap it out for your own. main character energy, honestly π¦
π FUNCTIONS π
check_safe
check_safe( FILENAME , MODE );
Checks a filename is safe β and dies if not π. MODE is r (read) or w (write). Default is no restrictions on file I/O.
so it's doing a vibe check on your filename, and if it fails the vibe check it literally kills your program. dramatic but iconic. (in this default policy though, nothing ever fails, because there are no restrictions π)
get_temp_dir
$temporary_directory = get_temp_dir();
Returns the path to temporary directory from the TEMP environment variable or File::Spec::Functions::tmpdir(). Note that any return value will have been cleared of a trailing slash.
so it snags your temp dir from TEMP if you set it, otherwise it asks File::Spec::Functions::tmpdir() β and either way, that trailing slash is gone. trimmed. cleaned. periodt βοΈ
get_log_dir
$log_directory = get_log_dir();
Returns the path to log directory from the LOGDIR environment variable or the current directory. Note that any return value will have been cleared of a trailing slash.
same deal as the temp one but for logs β LOGDIR env var if it exists, otherwise it just points at the current directory. and again: trailing slash? removed. she's tidy π§
β VERSION β
$Revision: 1.6 $ on $Date: 2005/05/18 15:57:28 $ by $Author: johna $
π AUTHOR π
John Alden <cpan _at_ bbc _dot_ co _dot_ uk>
π COPYRIGHT π
(c) BBC 2005. This program is free software; you can redistribute it and/or modify it under the GNU GPL.
See the file COPYING in this distribution, or http://www.gnu.org/licenses/gpl.txt
and that's the whole page, bestie!! π«Ά this lil gem comes from perl v5.36.0 and was dated 2022-12-07 β shoutout to the File::...Default(3pm) era, we love a legacy icon ππβ¨
π¦ where this page comes from
- debian bookworm: libfile-policy-perl 1.005-4 Β· GPL-2.0-or-later
- debian trixie: libfile-policy-perl 1.005-4 Β· GPL-2.0-or-later
- ubuntu noble: libfile-policy-perl 1.005-4 Β· GPL-2.0-or-later
- ubuntu resolute: libfile-policy-perl 1.005-4 Β· GPL-2.0-or-later
- ubuntu stonking: libfile-policy-perl 1.005-4 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms