NAME

Nuvol::Role::File - Role for files

SYNOPSIS

    my $file = $drive->item('path/to/file');

    $file->copy_from;
    $file->copy_to;
    $file->spurt;
    $file->slurp;
    $file->download_url;
    $file->remove;

DESCRIPTION

Nuvol::Role::File is a file role for items. It is automatically applied if an item is recognized as a file.

METHODS

copy_from

    $file = $file->copy_from($source);

Copies the content of a source into the file. The source can be another Nuvol::Role::File, a string with a path on the current drive, a Mojo::File, or a Mojo::URL. It is the reverse of "copy_to".

    $source = $drive->item('path/to/source');
    $file   = $file->copy_from($source);

Copies the file from another Nuvol::Role::File.

    $source = 'path/to/source';
    $file   = $file->copy_from($source);

Copies the file from another file defined as source on the current drive.

    $source = Mojo::File->new('path/to/local_file');
    $file   = $file->copy_from($source);

Uploads the content of a local Mojo::File.

    $source = Mojo::URL->new('https://url/of/the/file');

Downloads the content from a Mojo::URL.

copy_to

    $target = $file->copy_to($target);

Copies the content of the file to a target that can be another Nuvol::Role::File, a string with the path on the current drive, or a Mojo::File. It is the reverse of "copy_from" and returns the object where the content was copied to.

    $targetfile = $drive->item('path/to/targetfile');
    $targetfile = $file->copy_to($targetfile);

    $target_path = 'path/to/targetfile';
    $targetfile  = $file->copy_to($target_path);

Copies the file to another file, defined as Nuvol::Role::File or a path to this file.

    $targetfolder = $drive->item('path/to/targetfolder/');
    $targetfile   = $file->copy_to($targetfolder);

    $target_path = 'path/to/targetfolder/';
    $targetfile  = $file->copy_to($target_path);

Copies the file to another file with the same name in the target folder, defined as Nuvol::Role::Folder or a path to this folder.

    $targetfile = Mojo::File->new('path/to/local_file');
    $targetfile = $file->copy_to($targetfile);

Copies the content to a file in the local file system, defined as Mojo::File.

download_url

    $url = $file->download_url;

Getter for a short-lived URL to download the content.

remove

    $file = $file->remove;

Removes the file.

slurp

    $data = $file->slurp;

Reads the content at once.

spurt

    $file = $file->spurt(@data);

Writes data directly to the file and replaces its content.

SEE ALSO

Nuvol::Item, Nuvol::Role::Folder.