PurePerl/Loose.pm

filter: Statementstmt 48.7% 20 / 41 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 60.0% 6 / 10 Podpod 0.0% 0 / 3 totaltotal 44.8% 26 / 58 CC 3 SCAR 10.4
CC
3
Cov
44%
get_object
6.0
put_object
6.0
all_sha1s
2.0
CRAP 2.8
« PurePerl.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 sub get_object {
17 0 ▶ my ( $self, $sha1 ) = @_;
Subroutine get_object: not called CC=2 SCAR=17.9
Pod undocumented
18  
19 0 my $filename
20 = file( $self->directory, substr( $sha1, 0, 2 ), substr( $sha1, 2 ) );
21 0 ▶ return unless -f $filename;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $filename 0 0 0
22  
23 0 my $compressed = $filename->slurp;
24 0 my $data = uncompress($compressed);
25 0 my ( $kind, $size, $content ) = $data =~ /^(\w+) (\d+)\0(.+)$/s;
26 0 return ( $kind, $size, $content );
27 }
28  
29 sub put_object {
30 0 ▶ my ( $self, $object ) = @_;
Subroutine put_object: not called CC=2 SCAR=17.9
Pod undocumented
31  
32 0 my $filename = file(
33 $self->directory,
34 substr( $object->sha1, 0, 2 ),
35 substr( $object->sha1, 2 )
36 );
37 0 $filename->parent->mkpath;
38 0 my $compressed = compress( $object->raw );
39 0 my $fh = $filename->openw;
40 0 binmode($fh); #important for Win32
41 0 ▶ $fh->print($compressed) || die "Error writing to $filename: $!";
Branch: 1 branch
BranchTrueFalseTotal
$fh->print($compressed) or die "Error writing to ${filename}: $!" 0 0 0
42 }
43  
44 sub all_sha1s {
45 0 ▶ my $self = shift;
Subroutine all_sha1s: not called CC=1 SCAR=6.9
Pod undocumented
46 0 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 filter => sub {
52 0 [ map { m{([a-z0-9]{2})[/\\]([a-z0-9]{38})}; $1 . $2 }
53 0 ▶ grep {m{[/\\][a-z0-9]{2}[/\\]}} @$_
Subroutine __ANON__: not called CC=1 SCAR=6.9
54 ];
55 },
56 0 stream => $files,
57 );
58 }
59  
60 4 __PACKAGE__->meta->make_immutable;
61  
« PurePerl.pm ↑ Summary PurePerl/NewObject/Tree.pm »