| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Cogit::Loose; | 
| 2 |  |  |  |  |  |  | $Cogit::Loose::VERSION = '0.001001'; | 
| 3 | 4 |  |  | 4 |  | 20 | use Moo; | 
|  | 4 |  |  |  |  | 6 |  | 
|  | 4 |  |  |  |  | 24 |  | 
| 4 | 4 |  |  | 4 |  | 7745 | use MooX::Types::MooseLike::Base 'InstanceOf'; | 
|  | 4 |  |  |  |  | 4 |  | 
|  | 4 |  |  |  |  | 232 |  | 
| 5 | 4 |  |  | 4 |  | 2279 | use Compress::Zlib qw(compress uncompress); | 
|  | 4 |  |  |  |  | 168544 |  | 
|  | 4 |  |  |  |  | 324 |  | 
| 6 | 4 |  |  | 4 |  | 30 | use Path::Class; | 
|  | 4 |  |  |  |  | 6 |  | 
|  | 4 |  |  |  |  | 168 |  | 
| 7 | 4 |  |  | 4 |  | 17 | use Check::ISA; | 
|  | 4 |  |  |  |  | 7 |  | 
|  | 4 |  |  |  |  | 34 |  | 
| 8 | 4 |  |  | 4 |  | 1716 | use namespace::clean; | 
|  | 4 |  |  |  |  | 8 |  | 
|  | 4 |  |  |  |  | 43 |  | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | has directory => ( | 
| 11 |  |  |  |  |  |  | is       => 'ro', | 
| 12 |  |  |  |  |  |  | isa      => InstanceOf['Path::Class::Dir'], | 
| 13 |  |  |  |  |  |  | required => 1, | 
| 14 |  |  |  |  |  |  | coerce   => sub { dir($_[0]) if !obj($_[0], 'Path::Class::Dir'); $_[0]; }, | 
| 15 |  |  |  |  |  |  | ); | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | sub get_object { | 
| 18 | 72 |  |  | 72 | 0 | 696 | my ( $self, $sha1 ) = @_; | 
| 19 |  |  |  |  |  |  |  | 
| 20 | 72 |  |  |  |  | 473 | my $filename | 
| 21 |  |  |  |  |  |  | = file( $self->directory, substr( $sha1, 0, 2 ), substr( $sha1, 2 ) ); | 
| 22 | 72 | 50 |  |  |  | 5464 | return unless -f $filename; | 
| 23 |  |  |  |  |  |  |  | 
| 24 | 72 |  |  |  |  | 4184 | my $compressed = $filename->slurp( iomode => '<:raw' ); | 
| 25 | 72 |  |  |  |  | 11291 | my $data       = uncompress($compressed); | 
| 26 | 72 |  |  |  |  | 3649 | my ( $kind, $size, $content ) = $data =~ /^(\w+) (\d+)\0(.*)$/s; | 
| 27 | 72 |  |  |  |  | 443 | return ( $kind, $size, $content ); | 
| 28 |  |  |  |  |  |  | } | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  | sub put_object { | 
| 31 | 14 |  |  | 14 | 0 | 103 | my ( $self, $object ) = @_; | 
| 32 |  |  |  |  |  |  |  | 
| 33 | 14 |  |  |  |  | 279 | my $filename = file( | 
| 34 |  |  |  |  |  |  | $self->directory, | 
| 35 |  |  |  |  |  |  | substr( $object->sha1, 0, 2 ), | 
| 36 |  |  |  |  |  |  | substr( $object->sha1, 2 ) | 
| 37 |  |  |  |  |  |  | ); | 
| 38 | 14 |  |  |  |  | 1558 | $filename->parent->mkpath; | 
| 39 | 14 |  |  |  |  | 2597 | my $compressed = compress( $object->raw ); | 
| 40 | 14 |  |  |  |  | 3416 | my $fh         = $filename->openw; | 
| 41 | 14 |  |  |  |  | 2590 | binmode($fh); #important for Win32 | 
| 42 | 14 | 50 |  |  |  | 50 | $fh->print($compressed) || die "Error writing to $filename: $!"; | 
| 43 |  |  |  |  |  |  | } | 
| 44 |  |  |  |  |  |  |  | 
| 45 |  |  |  |  |  |  | sub all_sha1s { | 
| 46 | 18 |  |  | 18 | 0 | 816 | my $self  = shift; | 
| 47 | 18 |  |  |  |  | 743 | my $files = Data::Stream::Bulk::Path::Class->new( | 
| 48 |  |  |  |  |  |  | dir        => $self->directory, | 
| 49 |  |  |  |  |  |  | only_files => 1, | 
| 50 |  |  |  |  |  |  | ); | 
| 51 |  |  |  |  |  |  | return Data::Stream::Bulk::Filter->new( | 
| 52 |  |  |  |  |  |  | filter => sub { | 
| 53 | 14 | 100 |  | 14 |  | 39739 | [   map { m{[/\\]([a-z0-9]{2})[/\\]([a-z0-9]{38})} ? $1 . $2 : () } | 
|  | 74 |  |  |  |  | 1501 |  | 
| 54 |  |  |  |  |  |  | @$_ | 
| 55 |  |  |  |  |  |  | ]; | 
| 56 |  |  |  |  |  |  | }, | 
| 57 | 18 |  |  |  |  | 2393 | stream => $files, | 
| 58 |  |  |  |  |  |  | ); | 
| 59 |  |  |  |  |  |  | } | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | 1; | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  | __END__ | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  | =pod | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | =encoding UTF-8 | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | =head1 NAME | 
| 70 |  |  |  |  |  |  |  | 
| 71 |  |  |  |  |  |  | Cogit::Loose | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | =head1 VERSION | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | version 0.001001 | 
| 76 |  |  |  |  |  |  |  | 
| 77 |  |  |  |  |  |  | =head1 AUTHOR | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | Arthur Axel "fREW" Schmidt <cogit@afoolishmanifesto.com> | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | =head1 COPYRIGHT AND LICENSE | 
| 82 |  |  |  |  |  |  |  | 
| 83 |  |  |  |  |  |  | This software is copyright (c) 2017 by Arthur Axel "fREW" Schmidt. | 
| 84 |  |  |  |  |  |  |  | 
| 85 |  |  |  |  |  |  | This is free software; you can redistribute it and/or modify it under | 
| 86 |  |  |  |  |  |  | the same terms as the Perl 5 programming language system itself. | 
| 87 |  |  |  |  |  |  |  | 
| 88 |  |  |  |  |  |  | =cut |