Newer Older
127 lines | 2.652kb
copy gitweblite soruce code
root authored on 2012-11-23
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

            
upgraded Mojolicious to v3.7...
Yuki Kimoto authored on 2013-01-28
15
sub is_range { !!($_[0]->end_range || $_[0]->start_range) }
16

            
copy gitweblite soruce code
root authored on 2012-11-23
17
sub move_to { croak 'Method "move_to" not implemented by subclass' }
18
sub size    { croak 'Method "size" not implemented by subclass' }
19
sub slurp   { croak 'Method "slurp" not implemented by subclass' }
20

            
21
1;
22

            
update Mojolicious to 4.57
Yuki Kimoto authored on 2013-12-02
23
=encoding utf8
24

            
copy gitweblite soruce code
root authored on 2012-11-23
25
=head1 NAME
26

            
upgraded Mojolicious to v3.7...
Yuki Kimoto authored on 2013-01-28
27
Mojo::Asset - HTTP content storage base class
copy gitweblite soruce code
root authored on 2012-11-23
28

            
29
=head1 SYNOPSIS
30

            
upgraded Mojolicious to v3.7...
Yuki Kimoto authored on 2013-01-28
31
  package Mojo::Asset::MyAsset;
copy gitweblite soruce code
root authored on 2012-11-23
32
  use Mojo::Base 'Mojo::Asset';
33

            
upgraded Mojolicious to v3.7...
Yuki Kimoto authored on 2013-01-28
34
  sub add_chunk {...}
35
  sub contains  {...}
36
  sub get_chunk {...}
37
  sub move_to   {...}
38
  sub size      {...}
39
  sub slurp     {...}
40

            
copy gitweblite soruce code
root authored on 2012-11-23
41
=head1 DESCRIPTION
42

            
upgraded Mojolicious to v3.7...
Yuki Kimoto authored on 2013-01-28
43
L<Mojo::Asset> is an abstract base class for HTTP content storage.
copy gitweblite soruce code
root authored on 2012-11-23
44

            
update Mojolicious and added...
Yuki Kimoto authored on 2013-03-20
45
=head1 EVENTS
46

            
47
L<Mojo::Asset> inherits all events from L<Mojo::EventEmitter>.
48

            
copy gitweblite soruce code
root authored on 2012-11-23
49
=head1 ATTRIBUTES
50

            
51
L<Mojo::Asset> implements the following attributes.
52

            
update Mojolicious and added...
Yuki Kimoto authored on 2013-03-20
53
=head2 end_range
copy gitweblite soruce code
root authored on 2012-11-23
54

            
55
  my $end = $asset->end_range;
56
  $asset  = $asset->end_range(8);
57

            
58
Pretend file ends earlier.
59

            
update Mojolicious and added...
Yuki Kimoto authored on 2013-03-20
60
=head2 start_range
copy gitweblite soruce code
root authored on 2012-11-23
61

            
62
  my $start = $asset->start_range;
update Mojolicious to 4.57
Yuki Kimoto authored on 2013-12-02
63
  $asset    = $asset->start_range(3);
copy gitweblite soruce code
root authored on 2012-11-23
64

            
65
Pretend file starts later.
66

            
67
=head1 METHODS
68

            
69
L<Mojo::Asset> inherits all methods from L<Mojo::EventEmitter> and implements
70
the following new ones.
71

            
update Mojolicious and added...
Yuki Kimoto authored on 2013-03-20
72
=head2 add_chunk
copy gitweblite soruce code
root authored on 2012-11-23
73

            
74
  $asset = $asset->add_chunk('foo bar baz');
75

            
upgraded Mojolicious to v3.7...
Yuki Kimoto authored on 2013-01-28
76
Add chunk of data to asset. Meant to be overloaded in a subclass.
copy gitweblite soruce code
root authored on 2012-11-23
77

            
update Mojolicious and added...
Yuki Kimoto authored on 2013-03-20
78
=head2 contains
copy gitweblite soruce code
root authored on 2012-11-23
79

            
80
  my $position = $asset->contains('bar');
81

            
upgraded Mojolicious to v3.7...
Yuki Kimoto authored on 2013-01-28
82
Check if asset contains a specific string. Meant to be overloaded in a
copy gitweblite soruce code
root authored on 2012-11-23
83
subclass.
84

            
update Mojolicious and added...
Yuki Kimoto authored on 2013-03-20
85
=head2 get_chunk
copy gitweblite soruce code
root authored on 2012-11-23
86

            
update Mojolicious and added...
Yuki Kimoto authored on 2013-03-20
87
  my $bytes = $asset->get_chunk($offset);
update Mojolicious 4.07
Yuki Kimoto authored on 2013-06-03
88
  my $bytes = $asset->get_chunk($offset, $max);
copy gitweblite soruce code
root authored on 2012-11-23
89

            
update Mojolicious 4.07
Yuki Kimoto authored on 2013-06-03
90
Get chunk of data starting from a specific position, defaults to a maximum
91
chunk size of C<131072> bytes. Meant to be overloaded in a subclass.
copy gitweblite soruce code
root authored on 2012-11-23
92

            
update Mojolicious and added...
Yuki Kimoto authored on 2013-03-20
93
=head2 is_file
copy gitweblite soruce code
root authored on 2012-11-23
94

            
95
  my $false = $asset->is_file;
96

            
97
False.
98

            
update Mojolicious and added...
Yuki Kimoto authored on 2013-03-20
99
=head2 is_range
upgraded Mojolicious to v3.7...
Yuki Kimoto authored on 2013-01-28
100

            
update Mojolicious to 4.57
Yuki Kimoto authored on 2013-12-02
101
  my $bool = $asset->is_range;
upgraded Mojolicious to v3.7...
Yuki Kimoto authored on 2013-01-28
102

            
update Mojolicious to 4.57
Yuki Kimoto authored on 2013-12-02
103
Check if asset has a L</"start_range"> or L</"end_range">.
upgraded Mojolicious to v3.7...
Yuki Kimoto authored on 2013-01-28
104

            
update Mojolicious and added...
Yuki Kimoto authored on 2013-03-20
105
=head2 move_to
copy gitweblite soruce code
root authored on 2012-11-23
106

            
upgraded Mojolicious to v3.7...
Yuki Kimoto authored on 2013-01-28
107
  $asset = $asset->move_to('/home/sri/foo.txt');
copy gitweblite soruce code
root authored on 2012-11-23
108

            
upgraded Mojolicious to v3.7...
Yuki Kimoto authored on 2013-01-28
109
Move asset data into a specific file. Meant to be overloaded in a subclass.
copy gitweblite soruce code
root authored on 2012-11-23
110

            
update Mojolicious and added...
Yuki Kimoto authored on 2013-03-20
111
=head2 size
copy gitweblite soruce code
root authored on 2012-11-23
112

            
113
  my $size = $asset->size;
114

            
upgraded Mojolicious to v3.7...
Yuki Kimoto authored on 2013-01-28
115
Size of asset data in bytes. Meant to be overloaded in a subclass.
copy gitweblite soruce code
root authored on 2012-11-23
116

            
update Mojolicious and added...
Yuki Kimoto authored on 2013-03-20
117
=head2 slurp
copy gitweblite soruce code
root authored on 2012-11-23
118

            
update Mojolicious and added...
Yuki Kimoto authored on 2013-03-20
119
  my $bytes = $asset->slurp;
copy gitweblite soruce code
root authored on 2012-11-23
120

            
121
Read all asset data at once. Meant to be overloaded in a subclass.
122

            
123
=head1 SEE ALSO
124

            
125
L<Mojolicious>, L<Mojolicious::Guides>, L<http://mojolicio.us>.
126

            
127
=cut