| 1 | package Mojo::Asset; | ||||||||||||||||||||
| 2 | 32 | ▶ | use Mojo::Base 'Mojo::EventEmitter'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | 32 | ▶ | use Carp qw(croak); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 32 | has 'end_range'; | |||||||||||||||||||
| 7 | 32 | has start_range => 0; | |||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 1 | ▶ | sub add_chunk { croak 'Method "add_chunk" not implemented by subclass' } | ||||||||||||||||||
|
Subroutine
add_chunk: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 10 | 1 | ▶ | sub contains { croak 'Method "contains" not implemented by subclass' } | ||||||||||||||||||
|
Subroutine
contains: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 11 | 1 | ▶ | sub get_chunk { croak 'Method "get_chunk" not implemented by subclass' } | ||||||||||||||||||
|
Subroutine
get_chunk: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 21 | ▶ | sub is_file {undef} | ||||||||||||||||||
|
Subroutine
is_file: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 12 | ▶ | sub is_range { !!($_[0]->end_range || $_[0]->start_range) } | ||||||||||||||||||
|
Subroutine
is_range: called CC=2 SCAR=6.9
Pod
documented
Condition100%3/3
$_[0]->end_range || $_[0]->start_range
MC/DC100%2/2
$_[0]->end_range || $_[0]->start_range
$_[0]->end_range
$_[0]->start_range
Truth table100%3/3
A || B
A= $_[0]->end_rangeB= $_[0]->start_range
| |||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | 1 | ▶ | sub move_to { croak 'Method "move_to" not implemented by subclass' } | ||||||||||||||||||
|
Subroutine
move_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 18 | 1 | ▶ | sub mtime { croak 'Method "mtime" not implemented by subclass' } | ||||||||||||||||||
|
Subroutine
mtime: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 19 | 1 | ▶ | sub size { croak 'Method "size" not implemented by subclass' } | ||||||||||||||||||
|
Subroutine
size: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 20 | 1 | ▶ | sub slurp { croak 'Method "slurp" not implemented by subclass' } | ||||||||||||||||||
|
Subroutine
slurp: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 21 | 1 | ▶ | sub to_file { croak 'Method "to_file" not implemented by subclass' } | ||||||||||||||||||
|
Subroutine
to_file: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 32 | 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, like L<Mojo::Asset::File> and | ||||||||||||||||||||
| 48 | 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 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<Mojo::Asset::File> object. | ||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | =head2 is_range | ||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | my $bool = $asset->is_range; | ||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | Check if asset has a L</"start_range"> or L</"end_range">. | ||||||||||||||||||||
| 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<Mojo::Asset::File> object. Meant to be overloaded in a subclass. | ||||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | =head1 SEE ALSO | ||||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | L<Mojolicious>, L<Mojolicious::Guides>, L<https://mojolicious.org>. | ||||||||||||||||||||
| 141 | |||||||||||||||||||||
| 142 | =cut | ||||||||||||||||||||