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 {
24 my ($mem, $file) = @_;
25 ...
26 });
27
28 Emitted when asset gets upgraded to a Mojo::Asset::File object.
29
30 $mem->on(upgrade => sub {
31 my ($mem, $file) = @_;
32 $file->tmpdir('/tmp');
33 });
34
36 Mojo::Asset::Memory inherits all attributes from Mojo::Asset and
37 implements the following new ones.
38
39 auto_upgrade
40 my $bool = $mem->auto_upgrade;
41 $mem = $mem->auto_upgrade($bool);
42
43 Try to detect if content size exceeds "max_memory_size" limit and
44 automatically upgrade to a Mojo::Asset::File object.
45
46 max_memory_size
47 my $size = $mem->max_memory_size;
48 $mem = $mem->max_memory_size(1024);
49
50 Maximum size in bytes of data to keep in memory before automatically
51 upgrading to a Mojo::Asset::File object, defaults to the value of the
52 "MOJO_MAX_MEMORY_SIZE" environment variable or 262144 (256KiB).
53
54 mtime
55 my $mtime = $mem->mtime;
56 $mem = $mem->mtime(1408567500);
57
58 Modification time of asset, defaults to the value of $^T.
59
61 Mojo::Asset::Memory inherits all methods from Mojo::Asset and
62 implements the following new ones.
63
64 add_chunk
65 $mem = $mem->add_chunk('foo bar baz');
66 my $file = $mem->add_chunk('abc' x 262144);
67
68 Add chunk of data and upgrade to Mojo::Asset::File object if necessary.
69
70 contains
71 my $position = $mem->contains('bar');
72
73 Check if asset contains a specific string.
74
75 get_chunk
76 my $bytes = $mem->get_chunk($offset);
77 my $bytes = $mem->get_chunk($offset, $max);
78
79 Get chunk of data starting from a specific position, defaults to a
80 maximum chunk size of 131072 bytes (128KiB).
81
82 move_to
83 $mem = $mem->move_to('/home/sri/foo.txt');
84
85 Move asset data into a specific file.
86
87 size
88 my $size = $mem->size;
89
90 Size of asset data in bytes.
91
92 slurp
93 my $bytes = mem->slurp;
94
95 Read all asset data at once.
96
97 to_file
98 my $file = $mem->to_file;
99
100 Convert asset to Mojo::Asset::File object.
101
103 Mojolicious, Mojolicious::Guides, <https://mojolicious.org>.
104
105
106
107perl v5.30.1 2020-01-30 Mojo::Asset::Memory(3)