Mojo::A...::Memory(3)

🌸 NAME 🌸

okay so welcome to Mojo::A...::Memory(3) β€” yes, that's the manual page name β€” in the User Contributed Perl Documentation, bestie. The module being hyped here is Mojo::Asset::Memory, and it's literally in-memory storage for HTTP content. That's the vibe. πŸ’–

✨ SYNOPSIS ✨

use Mojo::Asset::Memory;

my $mem = Mojo::Asset::Memory->new;
$mem->add_chunk('foo bar baz');
say $mem->slurp;

πŸ’– DESCRIPTION πŸ’–

Mojo::Asset::Memory is an in-memory storage backend for HTTP content. That's the whole main-character job: HTTP content chills in memory. Slay. πŸ’…

πŸ¦‹ EVENTS πŸ¦‹

Mojo::Asset::Memory inherits all events from Mojo::Asset, and it can emit this new one: upgrade.

πŸ¦‹ upgrade πŸ¦‹

$mem->on(upgrade => sub ($mem, $file) {...});

Emitted when the asset gets upgraded to a Mojo::Asset::File object. It's a literal glow-up moment. ✨

Example, because we love a demo:

$mem->on(upgrade => sub ($mem, $file) { $file->tmpdir('/tmp') });

πŸŽ€ ATTRIBUTES πŸŽ€

Mojo::Asset::Memory inherits all attributes from Mojo::Asset and implements these new ones. 🫢

πŸŽ€ auto_upgrade πŸŽ€

my $bool = $mem->auto_upgrade;
$mem     = $mem->auto_upgrade($bool);

Try to detect if content size exceeds the max_memory_size limit and automatically upgrade to a Mojo::Asset::File object. It's giving self-aware asset energy. πŸ‘€

πŸŽ€ max_memory_size πŸŽ€

my $size = $mem->max_memory_size;
$mem     = $mem->max_memory_size(1024);

Maximum size in bytes of data to keep in memory before automatically upgrading to a Mojo::Asset::File object. Defaults to the value of the MOJO_MAX_MEMORY_SIZE environment variable or 262144 (256KiB). That's the limit, bestie. πŸ“

πŸŽ€ mtime πŸŽ€

my $mtime = $mem->mtime;
$mem      = $mem->mtime(1408567500);

Modification time of asset, defaults to the value of $^T. Time math but make it cute. πŸ•°οΈ

πŸ”₯ METHODS πŸ”₯

Mojo::Asset::Memory inherits all methods from Mojo::Asset and implements these new ones. Periodt. πŸ’…

πŸ”₯ add_chunk πŸ”₯

$mem     = $mem->add_chunk('foo bar baz');
my $file = $mem->add_chunk('abc' x 262144);

Add chunk of data and upgrade to Mojo::Asset::File object if necessary. That's it, that's the method. 😭

πŸ”₯ contains πŸ”₯

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

Check if asset contains a specific string. Cute and useful. πŸŽ€

πŸ”₯ get_chunk πŸ”₯

my $bytes = $mem->get_chunk($offset);
my $bytes = $mem->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. πŸ”₯

πŸ”₯ move_to πŸ”₯

$mem = $mem->move_to('/home/sri/foo.txt');

Move asset data into a specific file. The path in the example is exactly /home/sri/foo.txt, iykyk. πŸ¦‹

πŸ”₯ size πŸ”₯

my $size = $mem->size;

Size of asset data in bytes. Numbers, but make it slay. ⭐

πŸ”₯ slurp πŸ”₯

my $bytes = $mem->slurp;

Read all asset data at once. Literally the whole thing. πŸ’€

πŸ”₯ to_file πŸ”₯

my $file = $mem->to_file;

Convert asset to Mojo::Asset::File object. Upgrade era. πŸ‘‘

🌈 SEE ALSO 🌈

Mojolicious, Mojolicious::Guides, <https://mojolicious.org>. Go explore, bestie. 🌈


That's the whole page, bestie! 🫢 Cute sign-off: this is perl v5.42.0, dated 2026-07-15, and the manual name is Mojo::A...::Memory(3). Byeeee. βœ¨πŸ’–

πŸ“¦ where this page comes from