1Mojo::Asset::File(3)  User Contributed Perl Documentation Mojo::Asset::File(3)
2
3
4

NAME

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

SYNOPSIS

9         use Mojo::Asset::File;
10
11         # Temporary file
12         my $file = Mojo::Asset::File->new;
13         $file->add_chunk('foo bar baz');
14         say 'File contains "bar"' if $file->contains('bar') >= 0;
15         say $file->slurp;
16
17         # Existing file
18         my $file = Mojo::Asset::File->new(path => '/home/sri/foo.txt');
19         $file->move_to('/yada.txt');
20         say $file->slurp;
21

DESCRIPTION

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

EVENTS

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

ATTRIBUTES

29       Mojo::Asset::File inherits all attributes from Mojo::Asset and
30       implements the following new ones.
31
32   cleanup
33         my $bool = $file->cleanup;
34         $file    = $file->cleanup($bool);
35
36       Delete "path" automatically once the file is not used anymore.
37
38   handle
39         my $handle = $file->handle;
40         $file      = $file->handle(IO::File->new);
41
42       Filehandle, created on demand for "path", which can be generated
43       automatically and safely based on "tmpdir".
44
45   path
46         my $path = $file->path;
47         $file    = $file->path('/home/sri/foo.txt');
48
49       File path used to create "handle".
50
51   tmpdir
52         my $tmpdir = $file->tmpdir;
53         $file      = $file->tmpdir('/tmp');
54
55       Temporary directory used to generate "path", defaults to the value of
56       the "MOJO_TMPDIR" environment variable or auto-detection.
57

METHODS

59       Mojo::Asset::File inherits all methods from Mojo::Asset and implements
60       the following new ones.
61
62   add_chunk
63         $file = $file->add_chunk('foo bar baz');
64
65       Add chunk of data.
66
67   contains
68         my $position = $file->contains('bar');
69
70       Check if asset contains a specific string.
71
72   get_chunk
73         my $bytes = $file->get_chunk($offset);
74         my $bytes = $file->get_chunk($offset, $max);
75
76       Get chunk of data starting from a specific position, defaults to a
77       maximum chunk size of 131072 bytes (128KiB).
78
79   is_file
80         my $bool = $file->is_file;
81
82       True, this is a Mojo::Asset::File object.
83
84   move_to
85         $file = $file->move_to('/home/sri/bar.txt');
86
87       Move asset data into a specific file and disable "cleanup".
88
89   mtime
90         my $mtime = $file->mtime;
91
92       Modification time of asset.
93
94   new
95         my $file = Mojo::Asset::File->new;
96         my $file = Mojo::Asset::File->new(path => '/home/sri/test.txt');
97         my $file = Mojo::Asset::File->new({path => '/home/sri/test.txt'});
98
99       Construct a new Mojo::Asset::File object.
100
101   size
102         my $size = $file->size;
103
104       Size of asset data in bytes.
105
106   slurp
107         my $bytes = $file->slurp;
108
109       Read all asset data at once.
110
111   to_file
112         $file = $file->to_file;
113
114       Does nothing but return the invocant, since we already have a
115       Mojo::Asset::File object.
116

SEE ALSO

118       Mojolicious, Mojolicious::Guides, <https://mojolicious.org>.
119
120
121
122perl v5.30.0                      2019-07-26              Mojo::Asset::File(3)
Impressum