Digest/Driver.pm

filter: Statementstmt 75.0% 33 / 44 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 81.8% 9 / 11 Podpod n/a totaltotal 56.0% 42 / 75 CC 7 SCAR 24.4
CC
7
Cov
56%
__ANON__
30.0
__ANON__
12.0
BEGIN
1.0
CRAP 11.5
« Digest/HTTP.pm ↑ Summary Digest/Object.pm »
1 package Store::Digest::Driver;
2  
3 1 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use MooseX::Params::Validate ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use MooseX::Types::Moose qw(HashRef ArrayRef Str);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Store::Digest::Types qw(FiniteHandle DateTimeType RFC3066 DigestURI
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ContentType Token StoreObject);
15  
16 1 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 1 requires qw(add get remove forget list stats);
19  
20 # the primary digest algorithm (where the metadata is stored)
21 1 has _primary => (
22 is => 'rw',
23 isa => Token,
24 required => 0,
25 init_arg => 'primary',
26 );
27  
28 # all algorithms in use
29 1 has _algorithms => (
30 is => 'rw',
31 isa => ArrayRef[Token],
32 required => 0,
33 init_arg => 'algorithms',
34 );
35  
36 0 ▶around add => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
37 0 my $orig = shift;
38  
39 # jimmy this to accept either an object or a filehandle as a sole
40 # argument
41 0 ▶ if ($_[1] and ref $_[1]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[1] and ref $_[1]) 0 0 0
Condition0%0/3
$_[1] and ref $_[1]
!ll&&!rl&&r
000
MC/DC0%0/2
$_[1] and ref $_[1]
$_[1] ref $_[1]
Truth table0%0/3
A and B
A= $_[1]B= ref $_[1]
ABresult
0X0
100
111
42 }
43  
44 0 my ($self, %p) = MooseX::Params::Validate::validated_hash(
45 \@_,
46 content => {
47 isa => FiniteHandle,
48 optional => 0,
49 },
50 mtime => {
51 isa => DateTimeType,
52 optional => 1,
53 coerce => 1,
54 default => DateTime->now,
55 },
56 type => {
57 isa => ContentType,
58 optional => 1,
59 },
60 language => {
61 isa => RFC3066,
62 optional => 1,
63 },
64 charset => {
65 isa => Token,
66 optional => 1,
67 },
68 encoding => {
69 isa => Token,
70 optional => 1,
71 },
72 );
73  
74 0 $self->$orig(%p);
75 1 };
76  
77 # around get => sub {
78 # my $orig = shift;
79 # my ($self, $digest, $algo, $radix) =
80 # MooseX::Params::Validate::pos_validated_list(
81 # \@_,
82 # { is => Str|DigestURI }, # digest or ni: URI
83 # { is => Token, optional => 1 }, # optional algorithm
84 # { is => Token, optional => 1 }, # optional radix
85 # );
86  
87 # unless (Scalar::Util::blessed($digest)) {
88 # $digest = URI::ni->from_digest($digest, $algo, undef, $radix);
89 # }
90  
91 # #warn unpack("H*", $digest->digest);
92  
93 # $self->$orig($digest->digest, $digest->algorithm);
94 # };
95  
96 0 ▶around [qw(get remove forget)] => sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
97 0 my $orig = shift;
98 0 my ($self, $digest, $algo, $radix) =
99 MooseX::Params::Validate::pos_validated_list(
100 \@_,
101 { is => Str|DigestURI|StoreObject }, # digest, object or ni: URI
102 { is => Token, optional => 1 }, # optional algorithm
103 { is => Token, optional => 1 }, # optional radix
104 );
105  
106 # XXX: this can be blessed as a URI::ni and still messed up
107 0 ▶ unless (Scalar::Util::blessed($digest)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($digest)) 0 0 0
108 0 ▶ if ($digest =~ /^ni:/i and (!$radix or $radix != 256)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($digest =~ /^ni:/i and !$radix || $radix != 256) { } 0 0 0
Condition0%0/6
$digest =~ /^ni:/i and !$radix || $radix != 256
!ll&&!rl&&r
000
not $radix or $radix != 256
l!l&&r!l&&!r
000
MC/DC0%0/3
$digest =~ /^ni:/i and !$radix || $radix != 256
$digest =~ /^ni:/i not $radix $radix != 256
Truth table0%0/4
A and not(B) or C
A= $digest =~ /^ni:/iB= not $radixC= $radix != 256
ABCresult
0XX0
1000
11X1
1011
109 0 $digest = URI->new($digest);
110 }
111 else {
112 0 $digest = URI::ni->from_digest($digest, $algo, undef, $radix);
113 }
114 #warn $digest;
115 }
116  
117 0 $self->$orig($digest);
118 1 };
119  
120 =head1 NAME
121  
122 Store::Digest::Driver - Driver role for Store::Digest
123  
124 =head1 VERSION
125  
126 Version 0.01
127  
128 =cut
129  
130 1 our $VERSION = '0.01';
131  
132 =head1 SYNOPSIS
133  
134 =head1 METHODS
135  
136 =head2 new
137  
138 Create a new store, or bind to an existing one.
139  
140 =head2 get
141  
142 my $obj = $driver->get('sha-256' => $digest);
143  
144 # or
145  
146 my $obj = $driver->get($uri); # a URI::ni object
147  
148 Get an object from the store
149  
150 =cut
151  
152 =head2 about
153  
154 Get metadata about the store itself
155  
156 =cut
157  
158 =head2 add
159  
160 my $obj = $driver->add(
161 content => $fh,
162 language => 'en',
163 mtime => $datetime,
164 );
165  
166 Add an object to the store
167  
168 returns a metadata object
169  
170 =cut
171  
172 =head2 remove
173  
174 my $obj = $driver->remove('sha-256' => $digest);
175  
176 # $obj->content will be undef and $obj->dtime will be set
177  
178 Remove an object from the store, leaving its metadata
179  
180 =cut
181  
182 =head2 forget
183  
184 my $ok = $driver->forget('sha-256' => $digest);
185  
186 Forget about an object in addition to removing it. Ordinarily,
187 removing an object will only delete the content and preserve the
188 metadata.
189  
190 =cut
191  
192 =head2 list
193  
194 List the objects in the store
195  
196 =over 4
197  
198 =item algorithm
199  
200 Which cryptographic algorithm to be used as a key
201  
202 =item start
203  
204 Starting offset, beginning with 1
205  
206 =item end
207  
208 Ending offset, which should be equal to or larger than the starting
209 offset.
210  
211 =item sort
212  
213 Which field to use to sort the list
214  
215 =item invert
216  
217 Whether or not to invert the list
218  
219 =back
220  
221 =cut
222  
223 =head2 stats
224  
225 Retrieve statistics on the store
226  
227 =cut
228  
229 =head1 AUTHOR
230  
231 Dorian Taylor, C<< <dorian at cpan.org> >>
232  
233 =head1 BUGS
234  
235 Please report any bugs or feature requests to C<bug-store-digest at
236 rt.cpan.org>, or through the web interface at
237 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Store-Digest>. I
238 will be notified, and then you'll automatically be notified of
239 progress on your bug as I make changes.
240  
241 =head1 SUPPORT
242  
243 You can find documentation for this module with the perldoc command.
244  
245 perldoc Store::Digest::Driver
246  
247 You can also look for information at:
248  
249 =over 4
250  
251 =item * RT: CPAN's request tracker (report bugs here)
252  
253 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Store-Digest>
254  
255 =item * AnnoCPAN: Annotated CPAN documentation
256  
257 L<http://annocpan.org/dist/Store-Digest>
258  
259 =item * CPAN Ratings
260  
261 L<http://cpanratings.perl.org/d/Store-Digest>
262  
263 =item * Search CPAN
264  
265 L<http://search.cpan.org/dist/Store-Digest/>
266  
267 =back
268  
269  
270 =head1 ACKNOWLEDGEMENTS
271  
272  
273 =head1 LICENSE AND COPYRIGHT
274  
275 Copyright 2012 Dorian Taylor.
276  
277 Licensed under the Apache License, Version 2.0 (the "License"); you
278 may not use this file except in compliance with the License. You may
279 obtain a copy of the License at
280 L<http://www.apache.org/licenses/LICENSE-2.0>
281  
282 Unless required by applicable law or agreed to in writing, software
283 distributed under the License is distributed on an "AS IS" BASIS,
284 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
285 implied. See the License for the specific language governing
286 permissions and limitations under the License.
287  
288 =cut
289  
290 #__PACKAGE__->meta->make_immutable;
291  
292 1 1; # End of Store::Digest::Driver
« Digest/HTTP.pm ↑ Summary Digest/Object.pm »