1Mojo::Asset::Memory(3)User Contributed Perl DocumentationMojo::Asset::Memory(3)
2
3
4
6 Mojo::Asset::Memory - In-memory storage for HTTP content
7
9 use Mojo::Asset::Memory;
10
11 my $mem = Mojo::Asset::Memory->new;
12 $mem->add_chunk('foo bar baz');
13 say $mem->slurp;
14
16 Mojo::Asset::Memory is an in-memory storage backend for HTTP content.
17
19 Mojo::Asset::Memory inherits all events from Mojo::Asset and can emit
20 the following new ones.
21
22 upgrade
23 $mem->on(upgrade => sub ($mem, $file) {...});
24
25 Emitted when asset gets upgraded to a Mojo::Asset::File object.
26
27 $mem->on(upgrade => sub ($mem, $file) { $file->tmpdir('/tmp') });
28
30 Mojo::Asset::Memory inherits all attributes from Mojo::Asset and
31 implements the following new ones.
32
33 auto_upgrade
34 my $bool = $mem->auto_upgrade;
35 $mem = $mem->auto_upgrade($bool);
36
37 Try to detect if content size exceeds "max_memory_size" limit and
38 automatically upgrade to a Mojo::Asset::File object.
39
40 max_memory_size
41 my $size = $mem->max_memory_size;
42 $mem = $mem->max_memory_size(1024);
43
44 Maximum size in bytes of data to keep in memory before automatically
45 upgrading to a Mojo::Asset::File object, defaults to the value of the
46 "MOJO_MAX_MEMORY_SIZE" environment variable or 262144 (256KiB).
47
48 mtime
49 my $mtime = $mem->mtime;
50 $mem = $mem->mtime(1408567500);
51
52 Modification time of asset, defaults to the value of $^T.
53
55 Mojo::Asset::Memory inherits all methods from Mojo::Asset and
56 implements the following new ones.
57
58 add_chunk
59 $mem = $mem->add_chunk('foo bar baz');
60 my $file = $mem->add_chunk('abc' x 262144);
61
62 Add chunk of data and upgrade to Mojo::Asset::File object if necessary.
63
64 contains
65 my $position = $mem->contains('bar');
66
67 Check if asset contains a specific string.
68
69 get_chunk
70 my $bytes = $mem->get_chunk($offset);
71 my $bytes = $mem->get_chunk($offset, $max);
72
73 Get chunk of data starting from a specific position, defaults to a
74 maximum chunk size of 131072 bytes (128KiB).
75
76 move_to
77 $mem = $mem->move_to('/home/sri/foo.txt');
78
79 Move asset data into a specific file.
80
81 size
82 my $size = $mem->size;
83
84 Size of asset data in bytes.
85
86 slurp
87 my $bytes = $mem->slurp;
88
89 Read all asset data at once.
90
91 to_file
92 my $file = $mem->to_file;
93
94 Convert asset to Mojo::Asset::File object.
95
97 Mojolicious, Mojolicious::Guides, <https://mojolicious.org>.
98
99
100
101perl v5.34.0 2021-07-22 Mojo::Asset::Memory(3)