1 | package Mojo::Asset;
|
---|
2 | use Mojo::Base 'Mojo::EventEmitter';
|
---|
3 |
|
---|
4 | use Carp 'croak';
|
---|
5 |
|
---|
6 | has 'end_range';
|
---|
7 | has start_range => 0;
|
---|
8 |
|
---|
9 | sub add_chunk { croak 'Method "add_chunk" not implemented by subclass' }
|
---|
10 | sub contains { croak 'Method "contains" not implemented by subclass' }
|
---|
11 | sub get_chunk { croak 'Method "get_chunk" not implemented by subclass' }
|
---|
12 |
|
---|
13 | sub is_file {undef}
|
---|
14 |
|
---|
15 | sub is_range { !!($_[0]->end_range || $_[0]->start_range) }
|
---|
16 |
|
---|
17 | sub move_to { croak 'Method "move_to" not implemented by subclass' }
|
---|
18 | sub mtime { croak 'Method "mtime" not implemented by subclass' }
|
---|
19 | sub size { croak 'Method "size" not implemented by subclass' }
|
---|
20 | sub slurp { croak 'Method "slurp" not implemented by subclass' }
|
---|
21 | sub to_file { croak 'Method "to_file" not implemented by subclass' }
|
---|
22 |
|
---|
23 | 1;
|
---|
24 |
|
---|
25 | =encoding utf8
|
---|
26 |
|
---|
27 | =head1 NAME
|
---|
28 |
|
---|
29 | Mojo::Asset - HTTP content storage base class
|
---|
30 |
|
---|
31 | =head1 SYNOPSIS
|
---|
32 |
|
---|
33 | package Mojo::Asset::MyAsset;
|
---|
34 | use Mojo::Base 'Mojo::Asset';
|
---|
35 |
|
---|
36 | sub add_chunk {...}
|
---|
37 | sub contains {...}
|
---|
38 | sub get_chunk {...}
|
---|
39 | sub move_to {...}
|
---|
40 | sub mtime {...}
|
---|
41 | sub size {...}
|
---|
42 | sub slurp {...}
|
---|
43 | sub to_file {...}
|
---|
44 |
|
---|
45 | =head1 DESCRIPTION
|
---|
46 |
|
---|
47 | L<Mojo::Asset> is an abstract base class for HTTP content storage backends,
|
---|
48 | like L<Mojo::Asset::File> and L<Mojo::Asset::Memory>.
|
---|
49 |
|
---|
50 | =head1 EVENTS
|
---|
51 |
|
---|
52 | L<Mojo::Asset> inherits all events from L<Mojo::EventEmitter>.
|
---|
53 |
|
---|
54 | =head1 ATTRIBUTES
|
---|
55 |
|
---|
56 | L<Mojo::Asset> implements the following attributes.
|
---|
57 |
|
---|
58 | =head2 end_range
|
---|
59 |
|
---|
60 | my $end = $asset->end_range;
|
---|
61 | $asset = $asset->end_range(8);
|
---|
62 |
|
---|
63 | Pretend file ends earlier.
|
---|
64 |
|
---|
65 | =head2 start_range
|
---|
66 |
|
---|
67 | my $start = $asset->start_range;
|
---|
68 | $asset = $asset->start_range(3);
|
---|
69 |
|
---|
70 | Pretend file starts later.
|
---|
71 |
|
---|
72 | =head1 METHODS
|
---|
73 |
|
---|
74 | L<Mojo::Asset> inherits all methods from L<Mojo::EventEmitter> and implements
|
---|
75 | the following new ones.
|
---|
76 |
|
---|
77 | =head2 add_chunk
|
---|
78 |
|
---|
79 | $asset = $asset->add_chunk('foo bar baz');
|
---|
80 |
|
---|
81 | Add chunk of data to asset. Meant to be overloaded in a subclass.
|
---|
82 |
|
---|
83 | =head2 contains
|
---|
84 |
|
---|
85 | my $position = $asset->contains('bar');
|
---|
86 |
|
---|
87 | Check if asset contains a specific string. Meant to be overloaded in a
|
---|
88 | subclass.
|
---|
89 |
|
---|
90 | =head2 get_chunk
|
---|
91 |
|
---|
92 | my $bytes = $asset->get_chunk($offset);
|
---|
93 | my $bytes = $asset->get_chunk($offset, $max);
|
---|
94 |
|
---|
95 | Get chunk of data starting from a specific position, defaults to a maximum
|
---|
96 | chunk size of C<131072> bytes (128KiB). Meant to be overloaded in a subclass.
|
---|
97 |
|
---|
98 | =head2 is_file
|
---|
99 |
|
---|
100 | my $bool = $asset->is_file;
|
---|
101 |
|
---|
102 | False, this is not a L<Mojo::Asset::File> object.
|
---|
103 |
|
---|
104 | =head2 is_range
|
---|
105 |
|
---|
106 | my $bool = $asset->is_range;
|
---|
107 |
|
---|
108 | Check if asset has a L</"start_range"> or L</"end_range">.
|
---|
109 |
|
---|
110 | =head2 move_to
|
---|
111 |
|
---|
112 | $asset = $asset->move_to('/home/sri/foo.txt');
|
---|
113 |
|
---|
114 | Move asset data into a specific file. Meant to be overloaded in a subclass.
|
---|
115 |
|
---|
116 | =head2 mtime
|
---|
117 |
|
---|
118 | my $mtime = $asset->mtime;
|
---|
119 |
|
---|
120 | Modification time of asset. Meant to be overloaded in a subclass.
|
---|
121 |
|
---|
122 | =head2 size
|
---|
123 |
|
---|
124 | my $size = $asset->size;
|
---|
125 |
|
---|
126 | Size of asset data in bytes. Meant to be overloaded in a subclass.
|
---|
127 |
|
---|
128 | =head2 slurp
|
---|
129 |
|
---|
130 | my $bytes = $asset->slurp;
|
---|
131 |
|
---|
132 | Read all asset data at once. Meant to be overloaded in a subclass.
|
---|
133 |
|
---|
134 | =head2 to_file
|
---|
135 |
|
---|
136 | my $file = $asset->to_file;
|
---|
137 |
|
---|
138 | Convert asset to L<Mojo::Asset::File> object. Meant to be overloaded in a
|
---|
139 | subclass.
|
---|
140 |
|
---|
141 | =head1 SEE ALSO
|
---|
142 |
|
---|
143 | L<Mojolicious>, L<Mojolicious::Guides>, L<https://mojolicious.org>.
|
---|
144 |
|
---|
145 | =cut
|
---|