Mojo::Asset::File(3)

πŸ’– NAME πŸ’–

okay so bestie, welcome to Mojo::Asset::File(3) β€” this is the User Contributed Perl Documentation page for Mojo::Asset::File, and it is literally File storage for HTTP content. no cap, that's the whole vibe. πŸ’…


✨ SYNOPSIS ✨

Here's the copy-paste era, exact and untouched:

use Mojo::Asset::File;

# Temporary file
my $file = Mojo::Asset::File->new;
$file->add_chunk('foo bar baz');
say 'File contains "bar"' if $file->contains('bar') >= 0;
say $file->slurp;

# Existing file
my $file = Mojo::Asset::File->new(path => '/home/sri/foo.txt');
$file->move_to('/yada.txt');
say $file->slurp;

🌸 DESCRIPTION 🌸

Mojo::Asset::File is a file storage backend for HTTP content. That's it, that's the job. It's giving "I hold files for HTTP" and honestly? iconic. πŸ¦‹


πŸ¦‹ EVENTS πŸ¦‹

Mojo::Asset::File inherits all events from Mojo::Asset. So no new event lore here, bestie β€” it's all inherited. 🫢


πŸ’… ATTRIBUTES πŸ’…

Mojo::Asset::File inherits all attributes from Mojo::Asset and implements the following new ones. periodt.

πŸŽ€ cleanup πŸŽ€

my $bool = $file->cleanup;
$file    = $file->cleanup($bool);

This one deletes path automatically once the file is not used anymore. Auto-cleanup era β€” so tidy, so demure. 🧚

πŸŽ€ handle πŸŽ€

my $handle = $file->handle;
$file      = $file->handle(IO::File->new);

This is the filehandle, created on demand for path β€” and path can be generated automatically and safely based on tmpdir. automatic and safe? we love to see it. ✨

πŸŽ€ path πŸŽ€

my $path = $file->path;
$file    = $file->path('/home/sri/foo.txt');

File path used to create handle. the path is the moment. πŸ›£οΈ

πŸŽ€ tmpdir πŸŽ€

my $tmpdir = $file->tmpdir;
$file      = $file->tmpdir('/tmp');

Temporary directory used to generate path. It defaults to the value of the MOJO_TMPDIR environment variable or auto-detection. environment variable girlies rise. 🌱


πŸ‘‘ METHODS πŸ‘‘

Mojo::Asset::File inherits all methods from Mojo::Asset and implements the following new ones. Let's go through them, bestie. ⭐

🌈 add_chunk 🌈

$file = $file->add_chunk('foo bar baz');

Add chunk of data. Chunk by chunk, we build. πŸ’š

🌈 contains 🌈

my $position = $file->contains('bar');

Check if asset contains a specific string. string detective behavior. πŸ”

🌈 get_chunk 🌈

my $bytes = $file->get_chunk($offset);
my $bytes = $file->get_chunk($offset, $max);

Get chunk of data starting from a specific position, defaults to a maximum chunk size of 131072 bytes (128KiB). big chunk energy. πŸ“

🌈 is_file 🌈

my $bool = $file->is_file;

True, this is a Mojo::Asset::File object. main character confirmation. πŸ‘‘

🌈 move_to 🌈

$file = $file->move_to('/home/sri/bar.txt');

Move asset data into a specific file and disable cleanup. moving day, but make it filesystem. 🚚

🌈 mtime 🌈

my $mtime = $file->mtime;

Modification time of asset. time stamps are lowkey iconic. πŸ•°οΈ

🌈 new 🌈

my $file = Mojo::Asset::File->new;
my $file = Mojo::Asset::File->new(path => '/home/sri/test.txt');
my $file = Mojo::Asset::File->new({path => '/home/sri/test.txt'});

Construct a new Mojo::Asset::File object. fresh object, fresh vibe. πŸŽ€

🌈 size 🌈

my $size = $file->size;

Size of asset data in bytes. numbers girlies stay winning. πŸ“

🌈 slurp 🌈

my $bytes = $file->slurp;

Read all asset data at once. slurp it up. πŸ₯€

🌈 to_file 🌈

$file = $file->to_file;

Does nothing but return the invocant, since we already have a Mojo::Asset::File object. zero thoughts, just vibes. πŸ’œ


🌟 SEE ALSO 🌟


xoxo, your Unix bestie πŸ’– β€” page source vibes: perl v5.42.0, dated 2026-07-15. slay and read your manpages. πŸ’…

πŸ“¦ where this page comes from