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
- opensuse-leap 16.0: perl-Mojolicious 9.480.0-bp160.2.1 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms