lib/File/FStore/Base.pm

filter: Statementstmt 93.5% 29 / 31 Branchbran 50.0% 2 / 4 Conditioncond 35.7% 5 / 14 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 90.9% 10 / 11 Podpod 100% 7 / 7 totaltotal 69.7% 53 / 76 CC 8 SCAR 8.5
CC
8
Cov
73%
contentise
4.3
db
2.3
extractor
2.3
CRAP 2.3
« blib/lib/File/FStore/Base.pm ↑ Summary
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 3 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 3 our $VERSION = v0.06;
17  
18  
19 sub contentise {
20 3 ▶ my ($self, %opts) = @_;
Subroutine contentise: called CC=4 SCAR=14.6
Pod documented
21 3 ▶ my $as = delete($opts{as}) // 'uuid';
Condition50%1/2
delete $opts{"as"} // "uuid"
l!l
03
MC/DC0%0/1
delete $opts{"as"} // "uuid"
delete $opts{"as"}
Truth table50%1/2
A
A= delete $opts{"as"}
Aresult
11
00
22  
23 3 ▶ croak 'Stray options passed' if scalar keys %opts;
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %opts 0 3 3
24 3 ▶ confess 'No contentise known for this file' unless defined $self->{contentise};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"contentise"} 0 3 3
25  
26 3 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 0 ▶ my ($self, @args) = @_;
Subroutine ise: not called CC=1 SCAR=6.9
Pod documented
35 0 return $self->contentise(@args);
36 }
37  
38  
39 sub as {
40 1 ▶ my ($self, $as, %opts) = @_;
Subroutine as: called CC=2 SCAR=7.6
Pod documented
41 1 ▶ $opts{store} //= $self->{store};
Condition33%1/3
$opts{"store"} //= $self->{"store"}
l!l&&r!l&&!r
010
MC/DC0%0/2
$opts{"store"} //= $self->{"store"}
$opts{"store"} $self->{"store"}
Truth table33%1/3
A //= B
A= $opts{"store"}B= $self->{"store"}
ABresult
1X1
011
000
42 1 return $self->Data::Identifier::as($as, %opts);
43 }
44  
45  
46 #@returns File::FStore
47 sub store {
48 36 ▶ my ($self) = @_;
Subroutine store: called CC=1 SCAR=0.0
Pod documented
49 36 return $self->{store};
50 }
51  
52  
53 #@returns Data::TagDB
54 sub db {
55 3 ▶ my ($self, %opts) = @_;
Subroutine db: called CC=2 SCAR=8.1
Pod documented
56 3 ▶ return $self->{db} //= $self->store->db(%opts);
Condition33%1/3
$self->{"db"} //= $self->store->db(%opts)
l!l&&r!l&&!r
003
MC/DC0%0/2
$self->{"db"} //= $self->store->db(%opts)
$self->{"db"} $self->store->db(%opts)
Truth table33%1/3
A //= B
A= $self->{"db"}B= $self->store->db(%opts)
ABresult
1X1
011
000
57 }
58  
59  
60 #@returns Data::URIID
61 sub extractor {
62 3 ▶ my ($self, %opts) = @_;
Subroutine extractor: called CC=2 SCAR=8.1
Pod documented
63 3 ▶ return $self->{extractor} //= $self->store->extractor(%opts);
Condition33%1/3
$self->{"extractor"} //= $self->store->extractor(%opts)
l!l&&r!l&&!r
003
MC/DC0%0/2
$self->{"extractor"} //= $self->store->extractor(%opts)
$self->{"extractor"} $self->store->extractor(%opts)
Truth table33%1/3
A //= B
A= $self->{"extractor"}B= $self->store->extractor(%opts)
ABresult
1X1
011
000
64 }
65  
66  
67 sub fii {
68 3 ▶ my ($self) = @_;
Subroutine fii: called CC=2 SCAR=8.1
Pod documented
69 3 ▶ return $self->{fii} //= $self->store->fii;
Condition33%1/3
$self->{"fii"} //= $self->store->fii
l!l&&r!l&&!r
030
MC/DC0%0/2
$self->{"fii"} //= $self->store->fii
$self->{"fii"} $self->store->fii
Truth table33%1/3
A //= B
A= $self->{"fii"}B= $self->store->fii
ABresult
1X1
011
000
70 }
71  
72 3 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
« blib/lib/File/FStore/Base.pm ↑ Summary