| 1 | package Net::Blossom::Server::BlobStore; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use strictures 2; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 2 | ▶ | use Carp qw(croak); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 2 | ▶ | use Scalar::Util qw(blessed); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 2 | my @REQUIRED_METHODS = qw(deploy_schema begin_upload get_blob delete_blob); | |||||||||
| 9 | 2 | my @REQUIRED_UPLOAD_METHODS = qw(write prepare commit abort); | |||||||||
| 10 | |||||||||||
| 11 | 1 | ▶ | sub required_methods { | ||||||||
|
Subroutine
required_methods: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 12 | 1 | return @REQUIRED_METHODS; | |||||||||
| 13 | } | ||||||||||
| 14 | |||||||||||
| 15 | 1 | ▶ | sub required_upload_methods { | ||||||||
|
Subroutine
required_upload_methods: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 16 | 1 | return @REQUIRED_UPLOAD_METHODS; | |||||||||
| 17 | } | ||||||||||
| 18 | |||||||||||
| 19 | 3 | ▶ | sub assert_implements { | ||||||||
|
Subroutine
assert_implements: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||
| 20 | 3 | my ($class, $store) = @_; | |||||||||
| 21 | 3 | ▶ | croak "blob store is required" unless defined $store; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | 2 | ▶ | croak "blob store must be an object" unless blessed($store); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | |||||||||||
| 24 | 1 | for my $method (@REQUIRED_METHODS) { | |||||||||
| 25 | 4 | ▶ | croak "blob store must provide $method" unless $store->can($method); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | } | ||||||||||
| 27 | |||||||||||
| 28 | 1 | return 1; | |||||||||
| 29 | } | ||||||||||
| 30 | |||||||||||
| 31 | 4 | ▶ | sub assert_upload { | ||||||||
|
Subroutine
assert_upload: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||
| 32 | 4 | my ($class, $upload) = @_; | |||||||||
| 33 | 4 | ▶ | croak "blob upload is required" unless defined $upload; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | 3 | ▶ | croak "blob upload must be an object" unless blessed($upload); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | |||||||||||
| 36 | 2 | for my $method (@REQUIRED_UPLOAD_METHODS) { | |||||||||
| 37 | 5 | ▶ | croak "blob upload must provide $method" unless $upload->can($method); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | 1 | return 1; | |||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | 2 | 1; | |||||||||
| 44 | |||||||||||
| 45 | =pod | ||||||||||
| 46 | |||||||||||
| 47 | =head1 NAME | ||||||||||
| 48 | |||||||||||
| 49 | Net::Blossom::Server::BlobStore - Byte storage contract for Blossom backends | ||||||||||
| 50 | |||||||||||
| 51 | =head1 DESCRIPTION | ||||||||||
| 52 | |||||||||||
| 53 | C<Net::Blossom::Server::BlobStore> documents and validates the component that | ||||||||||
| 54 | stores blob bytes. Metadata stores refer to bytes through opaque storage keys. | ||||||||||
| 55 | |||||||||||
| 56 | Uploads use a two-phase lifecycle. C<prepare> stages bytes and returns a storage | ||||||||||
| 57 | key while the coordinating metadata transaction is open. After that transaction | ||||||||||
| 58 | succeeds, C<commit> finalizes local upload resources. C<abort> discards an | ||||||||||
| 59 | unfinished or rolled-back upload. | ||||||||||
| 60 | |||||||||||
| 61 | =head1 STORE METHODS | ||||||||||
| 62 | |||||||||||
| 63 | =head2 deploy_schema | ||||||||||
| 64 | |||||||||||
| 65 | Creates any byte-storage tables required by the implementation. Stores without | ||||||||||
| 66 | a database schema may implement this as a no-op. | ||||||||||
| 67 | |||||||||||
| 68 | =head2 begin_upload | ||||||||||
| 69 | |||||||||||
| 70 | my $upload = $blobs->begin_upload(%context); | ||||||||||
| 71 | |||||||||||
| 72 | Starts an upload and returns a blob upload writer. | ||||||||||
| 73 | The context is the same as for | ||||||||||
| 74 | L<Net::Blossom::Server::Storage/begin_upload>. | ||||||||||
| 75 | |||||||||||
| 76 | =head2 get_blob | ||||||||||
| 77 | |||||||||||
| 78 | my $body = $blobs->get_blob($storage_key); | ||||||||||
| 79 | |||||||||||
| 80 | Returns blob bytes as a scalar or stream object, or C<undef> when absent. | ||||||||||
| 81 | |||||||||||
| 82 | =head2 get_blob_range | ||||||||||
| 83 | |||||||||||
| 84 | my $body = $blobs->get_blob_range( | ||||||||||
| 85 | $storage_key, | ||||||||||
| 86 | offset => $offset, | ||||||||||
| 87 | length => $length, | ||||||||||
| 88 | size => $size, | ||||||||||
| 89 | ); | ||||||||||
| 90 | |||||||||||
| 91 | Optional method for efficient byte-range reads. C<offset> is zero-based and | ||||||||||
| 92 | C<length> is positive. It returns exactly C<length> bytes as a scalar or stream, | ||||||||||
| 93 | or C<undef> when the storage key is absent. C<size> may be supplied as the | ||||||||||
| 94 | expected full blob size. | ||||||||||
| 95 | |||||||||||
| 96 | =head2 delete_blob | ||||||||||
| 97 | |||||||||||
| 98 | my $deleted = $blobs->delete_blob($storage_key); | ||||||||||
| 99 | |||||||||||
| 100 | Deletes the bytes identified by C<$storage_key> and reports whether they | ||||||||||
| 101 | existed. A database blob store must perform deletion in the transaction that | ||||||||||
| 102 | removes the corresponding metadata and reject the call when that transaction | ||||||||||
| 103 | is not active. | ||||||||||
| 104 | |||||||||||
| 105 | =head2 required_methods | ||||||||||
| 106 | |||||||||||
| 107 | Returns the method names required from a blob store. | ||||||||||
| 108 | |||||||||||
| 109 | =head2 required_upload_methods | ||||||||||
| 110 | |||||||||||
| 111 | Returns the method names required from a blob upload writer. | ||||||||||
| 112 | |||||||||||
| 113 | =head2 assert_implements | ||||||||||
| 114 | |||||||||||
| 115 | Net::Blossom::Server::BlobStore->assert_implements($blobs); | ||||||||||
| 116 | |||||||||||
| 117 | Croaks unless C<$blobs> is an object implementing the store contract. | ||||||||||
| 118 | |||||||||||
| 119 | =head2 assert_upload | ||||||||||
| 120 | |||||||||||
| 121 | Net::Blossom::Server::BlobStore->assert_upload($upload); | ||||||||||
| 122 | |||||||||||
| 123 | Croaks unless C<$upload> is an object implementing the upload contract. | ||||||||||
| 124 | |||||||||||
| 125 | =head1 UPLOAD METHODS | ||||||||||
| 126 | |||||||||||
| 127 | =head2 write | ||||||||||
| 128 | |||||||||||
| 129 | $upload->write($bytes); | ||||||||||
| 130 | |||||||||||
| 131 | Appends one byte chunk to the staged upload. | ||||||||||
| 132 | |||||||||||
| 133 | =head2 prepare | ||||||||||
| 134 | |||||||||||
| 135 | my $storage_key = $upload->prepare(%metadata); | ||||||||||
| 136 | |||||||||||
| 137 | Stages the bytes and returns their opaque storage key. Before metadata commits, | ||||||||||
| 138 | the bytes must either be durable already or be part of the same database | ||||||||||
| 139 | transaction. A database blob store must reject the call when its paired metadata | ||||||||||
| 140 | transaction is not active. C<%metadata> contains C<sha256>, C<size>, C<type>, | ||||||||||
| 141 | C<uploaded>, and optionally C<pubkey>. | ||||||||||
| 142 | |||||||||||
| 143 | =head2 commit | ||||||||||
| 144 | |||||||||||
| 145 | $upload->commit; | ||||||||||
| 146 | |||||||||||
| 147 | Marks a prepared upload successful and releases staging resources. A | ||||||||||
| 148 | coordinator must not report a durable upload as failed solely because this | ||||||||||
| 149 | post-commit cleanup fails. | ||||||||||
| 150 | |||||||||||
| 151 | =head2 abort | ||||||||||
| 152 | |||||||||||
| 153 | $upload->abort; | ||||||||||
| 154 | |||||||||||
| 155 | Discards staging resources. It must be safe to call more than once. | ||||||||||
| 156 | It must not delete pre-existing bytes that use the same storage key. | ||||||||||
| 157 | |||||||||||
| 158 | =cut | ||||||||||