blib/lib/OrePAN2/Repository.pm

filter: Statementstmt 100% 71 / 71 Branchbran 90.0% 9 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 20 / 20 Podpod 0.0% 0 / 5 totaltotal 94.3% 100 / 106 CC 7 SCAR 5.7
CC
7
Cov
99%
__ANON__
4.0
gc
3.0
index_file
2.0
CRAP 1.8
« blib/lib/OrePAN2/Auditor.pm ↑ Summary blib/lib/OrePAN2/CLI/Indexer.pm »
1 package OrePAN2::Repository;
2  
3 6 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 6 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 6 ▶use File::Find ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use File::Spec ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶use File::pushd ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 6 ▶use OrePAN2::Indexer ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 6 ▶use OrePAN2::Injector ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 6 ▶use OrePAN2::Repository::Cache ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 6 ▶use Types::Standard qw( Bool InstanceOf Str );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 6 ▶use Types::Path::Tiny qw( Path );
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 6 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 #<<<
19 6 has compress_index => ( is => 'ro', isa => Bool, default => !!1 );
20 6 has cache => ( is => 'lazy', isa => InstanceOf ['OrePAN2::Repository::Cache'], builder => 1, handles => { has_cache => 'is_hit', save_cache => 'save' } );
21 6 has directory => ( is => 'ro', isa => Path, coerce => 1, required => 1 );
22 6 has indexer => ( is => 'lazy', isa => InstanceOf ['OrePAN2::Indexer'], builder => 1 );
23 6 has injector => ( is => 'lazy', isa => InstanceOf ['OrePAN2::Injector'], builder => 1 );
24 6 has simple => ( is => 'ro', isa => Bool, default => !!0 );
25 #>>>
26  
27 5 ▶sub _build_cache {
Subroutine _build_cache: called CC=1 SCAR=0.0
28 5 my $self = shift;
29 5 return OrePAN2::Repository::Cache->new( directory => $self->directory );
30 }
31  
32 4 ▶sub _build_indexer {
Subroutine _build_indexer: called CC=1 SCAR=0.0
33 4 my $self = shift;
34 4 return OrePAN2::Indexer->new(
35 directory => $self->directory,
36 simple => $self->simple
37 );
38 }
39  
40 4 ▶sub _build_injector {
Subroutine _build_injector: called CC=1 SCAR=0.0
41 4 my $self = shift;
42 4 return OrePAN2::Injector->new( directory => $self->directory );
43 }
44  
45 4 ▶sub make_index {
Subroutine make_index: called CC=1 SCAR=0.0
Pod undocumented
46 4 my $self = shift;
47 4 $self->indexer->make_index( no_compress => !$self->compress_index );
48 }
49  
50 4 ▶sub inject {
Subroutine inject: called CC=1 SCAR=0.0
Pod undocumented
51 4 my ( $self, $stuff, $opts ) = @_;
52  
53 4 my $tarpath = $self->injector->inject( $stuff, $opts );
54 4 $self->cache->set( $stuff, $tarpath );
55 }
56  
57 6 ▶sub index_file {
Subroutine index_file: called CC=2 SCAR=6.9
Pod undocumented
58 6 my $self = shift;
59 6 ▶ return File::Spec->catfile(
Branch: 1 branch
BranchTrueFalseTotal
$self->compress_index ? : 4 2 6
60 $self->directory, 'modules',
61 '02packages.details.txt' . ( $self->compress_index ? '.gz' : q{} )
62 );
63 }
64  
65 3 ▶sub load_index {
Subroutine load_index: called CC=1 SCAR=0.0
Pod undocumented
66 3 my $self = shift;
67  
68 3 my $index = OrePAN2::Index->new();
69 3 $index->load( $self->index_file );
70 3 $index;
71 }
72  
73 # Remove files that are not referenced by the index file.
74 3 ▶sub gc {
Subroutine gc: called CC=3 SCAR=11.0
Pod undocumented
75 3 my ( $self, $callback ) = @_;
76  
77 3 ▶ return unless -f $self->index_file;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $self->index_file 0 3 3
78  
79 3 my $index = $self->load_index;
80 3 my %registered;
81 3 for my $package ( $index->packages ) {
82 2 my ( $version, $path ) = $index->lookup($package);
83 2 $registered{$path}++;
84 }
85  
86 3 my $pushd = File::pushd::pushd(
87 File::Spec->catdir( $self->directory, 'authors', 'id' ) );
88 File::Find::find(
89 {
90 no_chdir => 1,
91 17 ▶ wanted => sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
92 17 ▶ return unless -f $_;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $_ 12 5 17
93 5 $_ = File::Spec->canonpath($_);
94 5 ▶ unless ( $registered{$_} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($registered{$_}) 3 2 5
95 3 ▶ $callback ? $callback->($_) : unlink $_;
Branch: 1 branch
BranchTrueFalseTotal
$callback ? : 1 2 3
96 }
97 5 1;
98 },
99 },
100 3 '.'
101 );
102 }
103  
104 6 1;
105  
« blib/lib/OrePAN2/Auditor.pm ↑ Summary blib/lib/OrePAN2/CLI/Indexer.pm »