Mojo::Asset::File − File storage for HTTP content
use
Mojo::Asset::File;
# Temporary file
my $file = Mojo::Asset::File−>new;
$file−>add_chunk('foo bar baz');
say 'File contains "bar"' if
$file−>contains('bar') >= 0;
say $file−>slurp;
# Existing file
my $file = Mojo::Asset::File−>new(path =>
'/home/sri/foo.txt');
$file−>move_to('/yada.txt');
say $file−>slurp;
Mojo::Asset::File is a file storage backend for HTTP content.
Mojo::Asset::File inherits all events from Mojo::Asset.
Mojo::Asset::File inherits all attributes from Mojo::Asset and implements the following new ones.
my $bool =
$file−>cleanup;
$file = $file−>cleanup($bool);
Delete "path" automatically once the file is not used anymore.
my $handle =
$file−>handle;
$file = $file−>handle(IO::File−>new);
Filehandle, created on demand for "path", which can be generated automatically and safely based on "tmpdir".
my $path =
$file−>path;
$file = $file−>path('/home/sri/foo.txt');
File path used to create "handle".
my $tmpdir =
$file−>tmpdir;
$file = $file−>tmpdir('/tmp');
Temporary directory used to generate "path", defaults to the value of the "MOJO_TMPDIR" environment variable or auto-detection.
Mojo::Asset::File inherits all methods from Mojo::Asset and implements the following new ones.
$file = $file−>add_chunk('foo bar baz');
Add chunk of data.
my $position = $file−>contains('bar');
Check if asset contains a specific string.
my $bytes =
$file−>get_chunk($offset);
my $bytes = $file−>get_chunk($offset, $max);
Get chunk of data starting from a specific position, defaults to a maximum chunk size of 131072 bytes (128KiB).
my $bool = $file−>is_file;
True, this is a Mojo::Asset::File object.
$file = $file−>move_to('/home/sri/bar.txt');
Move asset data into a specific file and disable "cleanup".
my $mtime = $file−>mtime;
Modification time of asset.
my $file =
Mojo::Asset::File−>new;
my $file = Mojo::Asset::File−>new(path =>
'/home/sri/test.txt');
my $file = Mojo::Asset::File−>new({path =>
'/home/sri/test.txt'});
Construct a new Mojo::Asset::File object.
my $size = $file−>size;
Size of asset data in bytes.
my $bytes = $file−>slurp;
Read all asset data at once.
$file = $file−>to_file;
Does nothing but return the invocant, since we already have a Mojo::Asset::File object.
Mojolicious, Mojolicious::Guides, <https://mojolicious.org>.