blib/lib/File/FStore/Base.pm untested

filter: Statementstmt 0.0% 0 / 32 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 14 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 68 CC 3 SCAR 14.6
CC
3
Cov
0%
contentise
12.0
ise
2.0
as
2.0
CRAP 4.3
1 # Copyright (c) 2025 Philipp Schafft
2  
3 # licensed under Artistic License 2.0 (see LICENSE file)
4  
5 # ABSTRACT: Module for interacting with file stores
6  
7  
8 package File::FStore::Base;
9  
10 use v5.10;
11 use strict;
12 use warnings;
13  
14 use Carp;
15  
16 our $VERSION = v0.06;
17  
18  
19 sub contentise {
20 my ($self, %opts) = @_;
21 my $as = delete($opts{as}) // 'uuid';
22  
23 croak 'Stray options passed' if scalar keys %opts;
24 confess 'No contentise known for this file' unless defined $self->{contentise};
25  
26 return $self->{contentise}->as($as,
27 db => $self->db(default => undef),
28 extractor => $self->extractor(default => undef),
29 );
30 }
31  
32  
33 sub ise {
34 my ($self, @args) = @_;
35 return $self->contentise(@args);
36 }
37  
38  
39 sub as {
40 my ($self, $as, %opts) = @_;
41 $opts{store} //= $self->{store};
42 return $self->Data::Identifier::as($as, %opts);
43 }
44  
45  
46 #@returns File::FStore
47 sub store {
48 my ($self) = @_;
49 return $self->{store};
50 }
51  
52  
53 #@returns Data::TagDB
54 sub db {
55 my ($self, %opts) = @_;
56 return $self->{db} //= $self->store->db(%opts);
57 }
58  
59  
60 #@returns Data::URIID
61 sub extractor {
62 my ($self, %opts) = @_;
63 return $self->{extractor} //= $self->store->extractor(%opts);
64 }
65  
66  
67 sub fii {
68 my ($self) = @_;
69 return $self->{fii} //= $self->store->fii;
70 }
71  
72 1;
73  
74 __END__
75  
76 =pod
77  
78 =encoding UTF-8
79  
80 =head1 NAME
81  
82 File::FStore::Base - Module for interacting with file stores
83  
84 =head1 VERSION
85  
86 version v0.06
87  
88 =head1 SYNOPSIS
89  
90 use File::FStore;
91  
92 my File::FStore::Base $obj = ...;
93  
94 This package is the base package for other packages, containing common methods.
95  
96 =head1 METHODS
97  
98 =head2 contentise
99  
100 my $ise = $file->contentise;
101 # or:
102 my $ise = $file->contentise(as => ...);
103  
104 Returns the content based ISE (identifier) for the file.
105 This can be used as a primary key for the given file in databases.
106 It is globally unique (so can be transfered to unrelated systems without the worry of collisions).
107  
108 Takes a single optional option C<as> which is documented in L<Data::Identifier/as>.
109 Defaulting to C<uuid>.
110  
111 B<Note:>
112 Calculation of this identifier requires the values for C<size> from the C<properties> domain
113 and the values for C<sha-1-160> and C<sha-3-512> from the C<digests> domain.
114  
115 B<Note:>
116 This value is only available on files that are in final state.
117 For L<File::FStore::Adder> this means the file file must at least be L<File::FStore::Adder/done>.
118  
119 =head2 ise
120  
121 my $ise = $file->ise;
122 # or:
123 my $ise = $file->ise(%opts);
124  
125 Returns an ISE (identifier) for this file.
126  
127 Currently an alias for L</contentise>. Later versions may add more logic.
128  
129 =head2 as
130  
131 my $xxx = $base->as($as, [ %opts ] );
132  
133 Proxy for L<Data::Identifier/as>.
134  
135 Automatically adds C<store> to C<%opts> if any is known (see L</store>).
136  
137 =head2 store
138  
139 my File::FStore $store = $file->store;
140  
141 Returns the store this file belongs to.
142  
143 =head2 db
144  
145 my Data::TagDB $db = $file->db;
146 # or:
147 my Data::TagDB $db = $file->db(default => $def);
148  
149 Proxy for L<File::FStore/db>.
150  
151 =head2 extractor
152  
153 my Data::URIID $extractor = $file->extractor;
154 # or:
155 my Data::URIID $extractor = $file->extractor(default => $def);
156  
157 Proxy for L<File::FStore/extractor>.
158  
159 =head2 fii
160  
161 my File::Information $fii = $file->fii;
162  
163 Proxy for L<File::FStore/fii>.
164  
165 =head1 AUTHOR
166  
167 Philipp Schafft <lion@cpan.org>
168  
169 =head1 COPYRIGHT AND LICENSE
170  
171 This software is Copyright (c) 2025 by Philipp Schafft <lion@cpan.org>.
172  
173 This is free software, licensed under:
174  
175 The Artistic License 2.0 (GPL Compatible)
176  
177 =cut