File Coverage

blib/lib/Mojo/Asset.pm
Criterion Covered Total %
statement 16 16 100.0
branch n/a
condition 3 3 100.0
subroutine 12 12 100.0
pod 10 10 100.0
total 41 41 100.0


line stmt bran cond sub pod time code
1             package Mojo::Asset;
2 62     62   475 use Mojo::Base 'Mojo::EventEmitter';
  62         164  
  62         556  
3              
4 62     62   415 use Carp qw(croak);
  62         797  
  62         23725  
5              
6             has 'end_range';
7             has start_range => 0;
8              
9 1     1 1 3223 sub add_chunk { croak 'Method "add_chunk" not implemented by subclass' }
10 1     1 1 791 sub contains { croak 'Method "contains" not implemented by subclass' }
11 1     1 1 725 sub get_chunk { croak 'Method "get_chunk" not implemented by subclass' }
12              
13 37     37 1 886 sub is_file {undef}
14              
15 12   100 12 1 68 sub is_range { !!($_[0]->end_range || $_[0]->start_range) }
16              
17 1     1 1 745 sub move_to { croak 'Method "move_to" not implemented by subclass' }
18 1     1 1 792 sub mtime { croak 'Method "mtime" not implemented by subclass' }
19 1     1 1 731 sub size { croak 'Method "size" not implemented by subclass' }
20 1     1 1 780 sub slurp { croak 'Method "slurp" not implemented by subclass' }
21 1     1 1 757 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 is an abstract base class for HTTP content storage backends, like L and
48             L.
49              
50             =head1 EVENTS
51              
52             L inherits all events from L.
53              
54             =head1 ATTRIBUTES
55              
56             L 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 inherits all methods from L and implements the following new ones.
75              
76             =head2 add_chunk
77              
78             $asset = $asset->add_chunk('foo bar baz');
79              
80             Add chunk of data to asset. Meant to be overloaded in a subclass.
81              
82             =head2 contains
83              
84             my $position = $asset->contains('bar');
85              
86             Check if asset contains a specific string. Meant to be overloaded in a subclass.
87              
88             =head2 get_chunk
89              
90             my $bytes = $asset->get_chunk($offset);
91             my $bytes = $asset->get_chunk($offset, $max);
92              
93             Get chunk of data starting from a specific position, defaults to a maximum chunk size of C<131072> bytes (128KiB).
94             Meant to be overloaded in a subclass.
95              
96             =head2 is_file
97              
98             my $bool = $asset->is_file;
99              
100             False, this is not a L object.
101              
102             =head2 is_range
103              
104             my $bool = $asset->is_range;
105              
106             Check if asset has a L or L.
107              
108             =head2 move_to
109              
110             $asset = $asset->move_to('/home/sri/foo.txt');
111              
112             Move asset data into a specific file. Meant to be overloaded in a subclass.
113              
114             =head2 mtime
115              
116             my $mtime = $asset->mtime;
117              
118             Modification time of asset. Meant to be overloaded in a subclass.
119              
120             =head2 size
121              
122             my $size = $asset->size;
123              
124             Size of asset data in bytes. Meant to be overloaded in a subclass.
125              
126             =head2 slurp
127              
128             my $bytes = $asset->slurp;
129              
130             Read all asset data at once. Meant to be overloaded in a subclass.
131              
132             =head2 to_file
133              
134             my $file = $asset->to_file;
135              
136             Convert asset to L object. Meant to be overloaded in a subclass.
137              
138             =head1 SEE ALSO
139              
140             L, L, L.
141              
142             =cut