OrePAN2/Repository.pm

filter: Statementstmt 97.3% 72 / 74 Branchbran 75.0% 9 / 12 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 90.9% 20 / 22 Podpod 12.5% 1 / 8 totaltotal 86.5% 103 / 119 CC 9 SCAR 6.6
CC
9
Cov
93%
__ANON__
4.0
new
3.0
gc
3.0
CRAP 1.9
« OrePAN2/Role/HasLogger.pm ↑ Summary OrePAN2/Logger.pm »
1 package OrePAN2::Repository;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use File::Find ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use File::Spec ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use File::pushd ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use OrePAN2::Indexer ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use OrePAN2::Injector ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use OrePAN2::Repository::Cache ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 2 ▶use parent qw(Class::Accessor::Fast);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 __PACKAGE__->mk_accessors(
17 qw(
18 compress_index
19 cache
20 directory
21 indexer
22 injector
23 simple
24 )
25 );
26  
27 2 our $VERSION = '2.0.0';
28  
29 2 ▶sub new {
Subroutine new: called CC=3 SCAR=11.1
Pod documented
30 2 my ( $class, @args ) = @_;
31 2 ▶ my $options = ref $args[0] ? $args[0] : {@args};
Branch: 1 branch
BranchTrueFalseTotal
ref $args[0] ? : 0 2 2
32  
33 2 ▶ $options->{compress_index} //= 1;
Condition50%1/2
$options->{"compress_index"} //= 1
l!l
02
MC/DC0%0/1
$options->{"compress_index"} //= 1
$options->{"compress_index"}
Truth table50%1/2
A
A= $options->{"compress_index"}
Aresult
11
00
34  
35 2 my $self = $class->SUPER::new($options);
36 2 $self->_build_cache;
37 2 $self->_build_indexer;
38 2 $self->_build_injector;
39  
40 2 return $self;
41 }
42  
43 0 ▶sub has_cache { return $_[0]->cache->is_hit( @_[ 1 .. $#_ ] ) }
Subroutine has_cache: not called CC=1 SCAR=6.9
Pod undocumented
44 0 ▶sub save_cache { return $_[0]->cache->save( @_[ 1 .. $#_ ] ) }
Subroutine save_cache: not called CC=1 SCAR=6.9
Pod undocumented
45  
46 2 ▶sub _build_cache {
Subroutine _build_cache: called CC=1 SCAR=0.0
47 2 my ($self) = @_;
48 2 $self->cache( OrePAN2::Repository::Cache->new( directory => $self->directory ) );
49 }
50  
51 2 ▶sub _build_indexer {
Subroutine _build_indexer: called CC=1 SCAR=0.0
52 2 my ($self) = @_;
53  
54 2 return $self->indexer(
55 OrePAN2::Indexer->new(
56 directory => $self->directory,
57 simple => $self->simple
58 )
59 );
60 }
61  
62 2 ▶sub _build_injector {
Subroutine _build_injector: called CC=1 SCAR=0.0
63 2 my ($self) = @_;
64 2 return $self->injector( OrePAN2::Injector->new( directory => $self->directory ) );
65 }
66  
67 2 ▶sub make_index {
Subroutine make_index: called CC=1 SCAR=0.0
Pod undocumented
68 2 my ($self) = @_;
69 2 return $self->indexer->make_index( no_compress => !$self->compress_index );
70 }
71  
72 2 ▶sub inject {
Subroutine inject: called CC=1 SCAR=0.0
Pod undocumented
73 2 my ( $self, $stuff, $opts ) = @_;
74  
75 2 my $tarpath = $self->injector->inject( $stuff, $opts );
76  
77 2 return $self->cache->set( $stuff, $tarpath );
78 }
79  
80 4 ▶sub index_file {
Subroutine index_file: called CC=2 SCAR=7.2
Pod undocumented
81 4 my ($self) = @_;
82  
83 4 ▶ return File::Spec->catfile( $self->directory, 'modules', '02packages.details.txt' . ( $self->compress_index ? '.gz' : q{} ) );
Branch: 1 branch
BranchTrueFalseTotal
$self->compress_index ? : 4 0 4
84 }
85  
86 2 ▶sub load_index {
Subroutine load_index: called CC=1 SCAR=0.0
Pod undocumented
87 2 my ($self) = @_;
88  
89 2 my $index = OrePAN2::Index->new();
90 2 $index->load( $self->index_file );
91  
92 2 return $index;
93 }
94  
95 # Remove files that are not referenced by the index file.
96 2 ▶sub gc {
Subroutine gc: called CC=3 SCAR=11.0
Pod undocumented
97 2 my ( $self, $callback ) = @_;
98  
99 2 ▶ return if !-f $self->index_file;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $self->index_file 0 2 2
100  
101 2 my $index = $self->load_index;
102 2 my %registered;
103 2 for my $package ( $index->packages ) {
104 2 my ( $version, $path ) = $index->lookup($package);
105 2 $registered{$path}++;
106 }
107  
108 2 my $pushd = File::pushd::pushd( File::Spec->catdir( $self->directory, 'authors', 'id' ) );
109  
110 return File::Find::find(
111 { no_chdir => 1,
112 12 ▶ wanted => sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
113 12 ▶ return if !-f $_;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $_ 8 4 12
114 4 $_ = File::Spec->canonpath($_);
115 4 ▶ if ( !$registered{$_} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($registered{$_}) 2 2 4
116 2 ▶ $callback ? $callback->($_) : unlink $_;
Branch: 1 branch
BranchTrueFalseTotal
$callback ? : 1 1 2
117 }
118 4 1;
119 },
120 },
121 2 q{.}
122 );
123 }
124  
125 2 1;
126  
« OrePAN2/Role/HasLogger.pm ↑ Summary OrePAN2/Logger.pm »