Server/MetadataStore.pm

filter: Statementstmt 100% 18 / 18 Branchbran 100% 6 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 100% 2 / 2 totaltotal 100% 31 / 31 CC 5 SCAR 11.7
CC
5
Cov
100%
assert_implements
5.0
BEGIN
1.0
BEGIN
1.0
CRAP 3.2
« Server/BlobStore.pm ↑ Summary Server/Authorization.pm »
1 package Net::Blossom::Server::MetadataStore;
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(
9 deploy_schema with_transaction lock_blob find_blob insert_blob
10 upsert_owner delete_owner delete_owners owner_count delete_blob
11 list_blobs
12 );
13  
14 1 ▶sub required_methods {
Subroutine required_methods: called CC=1 SCAR=0.0
Pod documented
15 1 return @REQUIRED_METHODS;
16 }
17  
18 4 ▶sub assert_implements {
Subroutine assert_implements: called CC=5 SCAR=16.1
Pod documented
19 4 my ($class, $store) = @_;
20 4 ▶ croak "metadata store is required" unless defined $store;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $store 1 3 4
21 3 ▶ croak "metadata store must be an object" unless blessed($store);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($store) 1 2 3
22  
23 2 for my $method (@REQUIRED_METHODS) {
24 13 ▶ croak "metadata store must provide $method" unless $store->can($method);
Branch: 1 branch
BranchTrueFalseTotal
unless $store->can($method) 1 12 13
25 }
26  
27 1 return 1;
28 }
29  
30 2 1;
31  
32 =pod
33  
34 =head1 NAME
35  
36 Net::Blossom::Server::MetadataStore - Metadata storage contract for Blossom backends
37  
38 =head1 DESCRIPTION
39  
40 C<Net::Blossom::Server::MetadataStore> documents and validates the metadata
41 component used by a Blossom storage backend. A metadata store manages blob
42 records and owner records, but never stores blob bytes.
43  
44 Blob records are hash references with C<sha256>, C<storage_key>, C<size>,
45 C<type>, and C<uploaded> values. C<storage_key> is an opaque identifier owned by
46 the corresponding blob store.
47  
48 C<lock_blob> and every method that changes records must be called from a
49 C<with_transaction> callback. Database implementations must reject those calls
50 when the transaction is not active.
51  
52 =head1 METHODS
53  
54 =head2 deploy_schema
55  
56 Creates the metadata tables and indexes. It must be safe to call repeatedly.
57  
58 =head2 with_transaction
59  
60 my $result = $metadata->with_transaction(sub { ... });
61  
62 Runs the callback in a transaction, committing its result or rolling it back
63 when the callback dies.
64  
65 =head2 lock_blob
66  
67 $metadata->lock_blob($sha256);
68  
69 Prevents concurrent changes for the same hash from interleaving within the
70 current transaction. It may be a no-op only when the transaction model already
71 provides that serialization.
72  
73 =head2 find_blob
74  
75 my $record = $metadata->find_blob($sha256);
76  
77 Returns a blob record or C<undef>.
78  
79 =head2 insert_blob
80  
81 my $created = $metadata->insert_blob(%record);
82  
83 Inserts a blob record and returns true when it was created or false when the
84 hash already exists.
85  
86 =head2 upsert_owner
87  
88 $metadata->upsert_owner(%owner);
89  
90 Creates or updates the owner identified by C<pubkey> and C<sha256>. Owner data
91 also includes C<type> and C<uploaded>.
92  
93 =head2 delete_owner
94  
95 my $deleted = $metadata->delete_owner($sha256, $pubkey);
96  
97 Deletes one owner relationship and reports whether it existed.
98  
99 =head2 delete_owners
100  
101 $metadata->delete_owners($sha256);
102  
103 Deletes every owner relationship for a blob.
104  
105 =head2 owner_count
106  
107 my $count = $metadata->owner_count($sha256);
108  
109 Returns the number of owners for a blob.
110  
111 =head2 delete_blob
112  
113 my $deleted = $metadata->delete_blob($sha256);
114  
115 Deletes one blob record and reports whether it existed.
116  
117 =head2 list_blobs
118  
119 my $records = $metadata->list_blobs($pubkey, %options);
120  
121 Returns blob records for an owner using the ordering, C<cursor>, and C<limit>
122 rules from L<Net::Blossom::Server::Storage>.
123  
124 =head2 required_methods
125  
126 Returns the method names required from a metadata store.
127  
128 =head2 assert_implements
129  
130 Net::Blossom::Server::MetadataStore->assert_implements($metadata);
131  
132 Croaks unless C<$metadata> is an object implementing the contract.
133  
134 =cut
« Server/BlobStore.pm ↑ Summary Server/Authorization.pm »