File::...Default(3pm)

πŸ“¦
version 1.005 Β· 2 versions
  • 1.005 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 1.005 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– 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>


(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 πŸŒˆπŸ’–βœ¨