Jifty/CAS/Blob.pm untested

filter: Statementstmt 0.0% 0 / 19 Branchbran n/a Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 30 CC 1 SCAR 6.9
CC
1
Cov
0%
new
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package Jifty::CAS::Blob;
2 use strict;
3  
4 use base 'Class::Accessor::Fast';
5 use Digest::MD5 'md5_hex';
6 use Compress::Zlib ();
7  
8 =head1 NAME
9  
10 Jifty::CAS::Blob - An object in Jifty's content-addressed store
11  
12 =head1 SYNOPSIS
13  
14 my $blob = Jifty::CAS->retrieve('js', $key);
15 my $content = $blob->content;
16 my $meta = $blob->metadata;
17 my $key = $blob->key;
18  
19 =head1 DESCRIPTION
20  
21 Objects in the content-addressed store can have arbitrary metadata
22 associated with them, in addition to storing their contents.
23  
24 =head1 METHODS
25  
26 =head2 new HASHREF
27  
28 Takes a HASHREF, with possible keys L</content> and L</metadata>, and
29 creates a new object. Possible special keys in the metadata include:
30  
31 =over
32  
33 =item hash_with
34  
35 Provides the data to hash to generate the address. If no C<hash_with>
36 is provided, the content itself is hashed.
37  
38 =back
39  
40 =head2 content
41  
42 Returns the content of the blob.
43  
44 =head2 metadata
45  
46 Returns a hashref of metadata.
47  
48 =head2 key
49  
50 Returns the key calculated for this content.
51  
52 =cut
53  
54 __PACKAGE__->mk_accessors(qw(content metadata key));
55  
56 sub new {
57 my $class = shift;
58 my $args = shift;
59 my $self = $class->SUPER::new( {
60 content => "",
61 metadata => {},
62 %$args,
63 } );
64 $self->key( md5_hex( $self->metadata->{hash_with} || $self->content ) );
65 return $self;
66 }
67  
68 1;