Mojo::Asset(3)

✨ Mojo::Asset ✨

okay so picture this: you're deep in the Mojo::Asset(3) manpage (yes bestie, that's the one you're reading rn πŸ’…) and you're like "wait, what even IS this?" β€” buckle up πŸŽ€

πŸ’– NAME πŸ’–

Mojo::Asset β€” the HTTP content storage base class. that's it. that's the whole vibe. it's the abstract parent energy, the main character that lets its kids shine 🌈


πŸ¦‹ SYNOPSIS πŸ¦‹

package Mojo::Asset::MyAsset;
use Mojo::Base 'Mojo::Asset';

sub add_chunk {...}
sub contains  {...}
sub get_chunk {...}
sub move_to   {...}
sub mtime     {...}
sub size      {...}
sub slurp     {...}
sub to_file   {...}

this is the whole "make your own subclass" starter pack fr fr 🫢


🌸 DESCRIPTION 🌸

so Mojo::Asset is an abstract base class for HTTP content storage backends β€” like Mojo::Asset::File and Mojo::Asset::Memory. think of it as the blueprint; you don't instantiate it directly, you build on top of it πŸ‘‘


⭐ EVENTS ⭐

Mojo::Asset inherits all events from Mojo::EventEmitter. every single one. no cap. πŸŽ€


πŸ’œ ATTRIBUTES πŸ’œ

Mojo::Asset implements the following attributes β€” let's go through them together, bestie:

πŸ’« end_range

my $end = $asset->end_range;
$asset  = $asset->end_range(8);

literally just pretending the file ends earlier than it actually does. manifesting a shorter file ✨

πŸ’« start_range

my $start = $asset->start_range;
$asset    = $asset->start_range(3);

and this one pretends the file starts later. again: pure imagination, no actual file changes πŸ™ˆ


πŸ”₯ METHODS πŸ”₯

Mojo::Asset inherits all methods from Mojo::EventEmitter and implements the following new ones. two things at once, iconic πŸ‘•

πŸ“ add_chunk

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

adds a chunk of data to the asset. meant to be overloaded in a subclass β€” so this is your homework, not mine 😭

πŸ“ contains

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

checks if the asset contains a specific string, and gives you back the position. also meant to be overloaded in a subclass πŸ’€

πŸ“ get_chunk

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

grabs a chunk of data starting from a specific position. defaults to a maximum chunk size of 131072 bytes (128KiB) β€” that's the number, memorize it bestie 🧠✨ and yes, meant to be overloaded in a subclass.

πŸ“ is_file

my $bool = $asset->is_file;

False. this is not a Mojo::Asset::File object. the audacity, honestly πŸ’…

πŸ“ is_file… no wait, is_range πŸ“

my $bool = $asset->is_range;

checks if the asset has a start_range or an end_range β€” i.e. is it in its pretend-the-bounds-are-different era πŸ¦‹

πŸ“ move_to

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

moves the asset data into a specific file. meant to be overloaded in a subclass πŸ“¦

πŸ“ mtime

my $mtime = $asset->mtime;

the modification time of the asset. meant to be overloaded in a subclass ⏰

πŸ“ size

my $size = $asset->size;

size of the asset data in bytes. meant to be overloaded in a subclass πŸ“

πŸ“ slurp

my $bytes = $asset->slurp;

reads all asset data at once. no crumbs, the whole thing 😌 meant to be overloaded in a subclass.

πŸ“ to_file

my $file = $asset->to_file;

converts the asset into a Mojo::Asset::File object. meant to be overloaded in a subclass 🧚


🌈 SEE ALSO 🌈


ngl, that "meant to be overloaded in a subclass" line shows up like eight times and honestly? that's the whole point of this page. it's a base class, bestie β€” she's not doing the work, she's delegating πŸ’…βœ¨

and that's a wrap on Mojo::Asset, manual page number 3 🫢 β€” this beauty came to you courtesy of perl v5.42.0, dated 2026-07-15. go forth and subclass responsibly, mwah πŸ˜˜πŸ’–

πŸ“¦ where this page comes from