Name
SPVM::Mojo::Asset::Memory - In-memory storage for HTTP content
Description
Mojo::Asset::Memory class in SPVM has methods to do someting.
Usage
use Mojo::Asset::Memory;
my $mem = Mojo::Asset::Memory->new;
$mem->add_chunk("foo bar baz");
say $mem->slurp;
Super Class
Events
upgrade
$mem->on(upgrade => method ($mem : Mojo::Asset::Memory, $file : Mojo::Asset::File) {...});
Emitted when asset gets upgraded to a Mojo::Asset::File object.
$mem->on(upgrade => method ($mem : Mojo::Asset::Memory, $file : Mojo::Asset::File) { $file->set_tmpdir("/tmp"); });
Fields
auto_upgrade
has auto_upgrade : rw byte;
Try to detect if content size exceeds "max_memory_size" limit and automatically upgrade to a Mojo::Asset::File object.
max_memory_size
has max_memory_size : rw int;
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 SPVM_MOJO_MAX_MEMORY_SIZE
environment variable or 262144
(256KiB).
mtime
has mtime : rw long;
Modification time of asset, defaults to the value of $^T
.
Class Methods
static method new : Mojo::Asset::Memory ();
Creates a new Mojo::Asset::Memory object, and returns it.
Instance Methods
add_chunk
method add_chunk : Mojo::Asset ($chunk : string);
Add chunk of data and upgrade to Mojo::Asset::File object if necessary.
contains
method contains : int ($string : string);
Check if asset contains a specific string.
get_chunk
method get_chunk : string ($offset : long, $max : int = -1);
Get chunk of data starting from a specific position, defaults to a maximum chunk size of 131072
bytes (128KiB).
move_to
method move_to : void ($file : string);
Move asset data into a specific file.
size
method size : long ();
Size of asset data in bytes.
slurp
method slurp : string ();
Read all asset data at once.
to_file
method to_file : Mojo::Asset::File ();
Convert asset to Mojo::Asset::File object.
See Also
Copyright & License
Copyright (c) 2025 Yuki Kimoto
MIT License