PurePerl/Loose.pm

filter: Statementstmt 100% 41 / 41 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 3 totaltotal 91.3% 53 / 58 CC 3 SCAR 2.9
CC
3
Cov
96%
get_object
2.0
put_object
2.0
BEGIN
1.0
CRAP 1.3
« PurePerl/Object/Tree.pm ↑ Summary PurePerl/NewObject/Tree.pm »
1 package Git::PurePerl::Loose;
2 4 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use MooseX::StrictConstructor;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use MooseX::Types::Path::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use Compress::Zlib qw(compress uncompress);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use Path::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 4 has 'directory' => (
10 is => 'ro',
11 isa => 'Path::Class::Dir',
12 required => 1,
13 coerce => 1
14 );
15  
16 68 ▶sub get_object {
Subroutine get_object: called CC=2 SCAR=7.0
Pod undocumented
17 68 my ( $self, $sha1 ) = @_;
18  
19 68 my $filename
20 = file( $self->directory, substr( $sha1, 0, 2 ), substr( $sha1, 2 ) );
21 68 ▶ return unless -f $filename;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $filename 0 68 68
22  
23 68 my $compressed = $filename->slurp( iomode => '<:raw' );
24 68 my $data = uncompress($compressed);
25 68 my ( $kind, $size, $content ) = $data =~ /^(\w+) (\d+)\0(.*)$/s;
26 68 return ( $kind, $size, $content );
27 }
28  
29 14 ▶sub put_object {
Subroutine put_object: called CC=2 SCAR=7.0
Pod undocumented
30 14 my ( $self, $object ) = @_;
31  
32 14 my $filename = file(
33 $self->directory,
34 substr( $object->sha1, 0, 2 ),
35 substr( $object->sha1, 2 )
36 );
37 14 $filename->parent->mkpath;
38 14 my $compressed = compress( $object->raw );
39 14 my $fh = $filename->openw;
40 14 binmode($fh); #important for Win32
41 14 ▶ $fh->print($compressed) || die "Error writing to $filename: $!";
Branch: 1 branch
BranchTrueFalseTotal
$fh->print($compressed) or die "Error writing to ${filename}: $!" 14 0 14
42 }
43  
44 18 ▶sub all_sha1s {
Subroutine all_sha1s: called CC=1 SCAR=0.0
Pod undocumented
45 18 my $self = shift;
46 18 my $files = Data::Stream::Bulk::Path::Class->new(
47 dir => $self->directory,
48 only_files => 1,
49 );
50 return Data::Stream::Bulk::Filter->new(
51 14 ▶ filter => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
52 62 [ map { m{([a-z0-9]{2})[/\\]([a-z0-9]{38})}; $1 . $2 }
53 14 grep {m{[/\\][a-z0-9]{2}[/\\]}} @$_
54 ];
55 },
56 18 stream => $files,
57 );
58 }
59  
60 4 __PACKAGE__->meta->make_immutable;
61  
« PurePerl/Object/Tree.pm ↑ Summary PurePerl/NewObject/Tree.pm »