Mojo :: Asset :: File (source)

TABLE OF CONTENTS

NAME

Mojo::Asset::File - File storage for HTTP content

SYNOPSIS

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;

DESCRIPTION

Mojo::Asset::File is a file storage backend for HTTP content.

EVENTS

Mojo::Asset::File inherits all events from Mojo::Asset.

ATTRIBUTES

Mojo::Asset::File inherits all attributes from Mojo::Asset and implements the following new ones.

cleanup

my $bool = $file->cleanup;
$file    = $file->cleanup($bool);

Delete file automatically once it's not used anymore.

handle

my $handle = $file->handle;
$file      = $file->handle(IO::File->new);

Filehandle, created on demand.

path

my $path = $file->path;
$file    = $file->path('/home/sri/foo.txt');

File path used to create "handle", can also be automatically generated if necessary.

tmpdir

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.

METHODS

Mojo::Asset::File inherits all methods from Mojo::Asset and implements the following new ones.

add_chunk

$file = $file->add_chunk('foo bar baz');

Add chunk of data.

contains

my $position = $file->contains('bar');

Check if asset contains a specific string.

get_chunk

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.

is_file

my $true = $file->is_file;

True.

move_to

$file = $file->move_to('/home/sri/bar.txt');

Move asset data into a specific file and disable "cleanup".

size

my $size = $file->size;

Size of asset data in bytes.

slurp

my $bytes = $file->slurp;

Read all asset data at once.

SEE ALSO

Mojolicious, Mojolicious::Guides, http://mojolicio.us.