.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Mojo::Asset::Memory 3pm" .TH Mojo::Asset::Memory 3pm 2024-05-15 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Mojo::Asset::Memory \- In\-memory storage for HTTP content .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 1 \& use Mojo::Asset::Memory; \& \& my $mem = Mojo::Asset::Memory\->new; \& $mem\->add_chunk(\*(Aqfoo bar baz\*(Aq); \& say $mem\->slurp; .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" Mojo::Asset::Memory is an in-memory storage backend for HTTP content. .SH EVENTS .IX Header "EVENTS" Mojo::Asset::Memory inherits all events from Mojo::Asset and can emit the following new ones. .SS upgrade .IX Subsection "upgrade" .Vb 1 \& $mem\->on(upgrade => sub ($mem, $file) {...}); .Ve .PP Emitted when asset gets upgraded to a Mojo::Asset::File object. .PP .Vb 1 \& $mem\->on(upgrade => sub ($mem, $file) { $file\->tmpdir(\*(Aq/tmp\*(Aq) }); .Ve .SH ATTRIBUTES .IX Header "ATTRIBUTES" Mojo::Asset::Memory inherits all attributes from Mojo::Asset and implements the following new ones. .SS auto_upgrade .IX Subsection "auto_upgrade" .Vb 2 \& my $bool = $mem\->auto_upgrade; \& $mem = $mem\->auto_upgrade($bool); .Ve .PP Try to detect if content size exceeds "max_memory_size" limit and automatically upgrade to a Mojo::Asset::File object. .SS max_memory_size .IX Subsection "max_memory_size" .Vb 2 \& my $size = $mem\->max_memory_size; \& $mem = $mem\->max_memory_size(1024); .Ve .PP 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 \f(CW\*(C`MOJO_MAX_MEMORY_SIZE\*(C'\fR environment variable or \f(CW262144\fR (256KiB). .SS mtime .IX Subsection "mtime" .Vb 2 \& my $mtime = $mem\->mtime; \& $mem = $mem\->mtime(1408567500); .Ve .PP Modification time of asset, defaults to the value of \f(CW$^T\fR. .SH METHODS .IX Header "METHODS" Mojo::Asset::Memory inherits all methods from Mojo::Asset and implements the following new ones. .SS add_chunk .IX Subsection "add_chunk" .Vb 2 \& $mem = $mem\->add_chunk(\*(Aqfoo bar baz\*(Aq); \& my $file = $mem\->add_chunk(\*(Aqabc\*(Aq x 262144); .Ve .PP Add chunk of data and upgrade to Mojo::Asset::File object if necessary. .SS contains .IX Subsection "contains" .Vb 1 \& my $position = $mem\->contains(\*(Aqbar\*(Aq); .Ve .PP Check if asset contains a specific string. .SS get_chunk .IX Subsection "get_chunk" .Vb 2 \& my $bytes = $mem\->get_chunk($offset); \& my $bytes = $mem\->get_chunk($offset, $max); .Ve .PP Get chunk of data starting from a specific position, defaults to a maximum chunk size of \f(CW131072\fR bytes (128KiB). .SS move_to .IX Subsection "move_to" .Vb 1 \& $mem = $mem\->move_to(\*(Aq/home/sri/foo.txt\*(Aq); .Ve .PP Move asset data into a specific file. .SS size .IX Subsection "size" .Vb 1 \& my $size = $mem\->size; .Ve .PP Size of asset data in bytes. .SS slurp .IX Subsection "slurp" .Vb 1 \& my $bytes = $mem\->slurp; .Ve .PP Read all asset data at once. .SS to_file .IX Subsection "to_file" .Vb 1 \& my $file = $mem\->to_file; .Ve .PP Convert asset to Mojo::Asset::File object. .SH "SEE ALSO" .IX Header "SEE ALSO" Mojolicious, Mojolicious::Guides, .