Dancer...leUtils(3pm)

πŸ’– Dancer::FileUtils β€” bestie edition πŸ’–

okay so this is Dancer::FileUtils(3pm), from the User Contributed Perl Documentation corner of the universe, and it's genuinely one of those little helper modules that just gets you. it's giving "I do your file chores so you don't have to write your own file-reading subroutines" energy. no cap. 🌸


✨ NAME ✨

Dancer::FileUtils β€” a lil helper that hands you file utilities πŸŽ€


🌈 VERSION 🌈

version 1.3522 β€” yes queen, that's the one πŸ‘‘


πŸ¦‹ SYNOPSIS πŸ¦‹

okay so here's the vibe, look at this:

use Dancer::FileUtils qw/dirname path/;

# for 'path/to/file'
my $dir  = dirname($path); # returns 'path/to'
my $path = path($path);    # returns '/abs/path/to/file'

use Dancer::FileUtils qw/path read_file_content/;

my $content = read_file_content( path( 'folder', 'folder', 'file' ) );
my @content = read_file_content( path( 'folder', 'folder', 'file' ) );

use Dancer::FileUtils qw/read_glob_content set_file_mode/;

open my $fh, '<', $file or die "$!\n";
set_file_mode($fh);
my @content = read_file_content($fh);
my $content = read_file_content($fh);

like literally just import what you need and go πŸ’…


πŸ’œ DESCRIPTION πŸ’œ

Dancer::FileUtils includes a few file-related utilities β€” the ones Dancer uses internally, iykyk. and here's the tea: developers may use it instead of writing their own file reading subroutines or dragging in additional modules. so like, why would you hand-roll that? exactly. you wouldn't. 🫢


πŸŽ€ SUBROUTINES/METHODS πŸŽ€

🌟 dirname

use Dancer::FileUtils 'dirname';

my $dir = dirname($path);

Exposes File::Basename's dirname, so you can fetch a directory name out of a path. on most OS, it returns all but the last level of the file path. see File::Basename for the details, bestie β€” it's got the receipts. literally the main character of path-splitting. πŸ’…


🌟 open_file

use Dancer::FileUtils 'open_file';
my $fh = open_file('<', $file) or die $message;

Calls open and returns a filehandle. it takes into account the 'charset' setting from Dancer's configuration to open the file in the proper encoding β€” or defaults to utf-8 if that setting isn't present. considerate. thoughtful. iconic. ✨


🌟 path

use Dancer::FileUtils 'path';

my $path = path( 'folder', 'folder', 'filename');

Provides comfortable path resolving, internally using File::Spec. it's giving convenience, it's giving "let me assemble this path for you." πŸ¦‹


🌟 read_file_content

use Dancer::FileUtils 'read_file_content';

my @content = read_file_content($file);
my $content = read_file_content($file);

Returns either the content of a file (whose filename is the input), or undef if the file could not be opened. harsh but fair.

In array context it returns each line (as defined by $/) as a separate element; in scalar context it returns the entire contents of the file. same sub, two personalities. main character energy fr fr. 😭


🌟 read_glob_content

use Dancer::FileUtils 'read_glob_content';

open my $fh, '<', $file or die "$!\n";
my @content = read_glob_content($fh);
my $content = read_glob_content($fh);

Same as read_file_content, only it accepts a file handle. Returns the content and closes the file handle. so polite of it to clean up after itself 🧚


🌟 set_file_mode

use Dancer::FileUtils 'set_file_mode';

set_file_mode($fh);

Applies charset setting from Dancer's configuration. Defaults to utf-8 if there's no charset setting. consistent queen. 🌸


πŸ“ EXPORT πŸ“

Nothing by default. You can provide a list of subroutines to import. so like β€” you gotta ask for what you want. boundaries! we love that. πŸ’–


πŸ‘‘ AUTHOR πŸ‘‘

Dancer Core Developers


This software is copyright (c) 2010 by Alexis Sukrieh.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

ok important: that's the license, fr fr, same terms as Perl 5 itself. keep it cute, keep it legal. πŸ’…

and that's the whole page, bestie!! this was Dancer::FileUtils(3pm) from perl v5.40.1, footer-dated 2026-05-05. go forth and read files responsibly πŸŒˆβœ¨πŸ’œ

πŸ“¦ where this page comes from