blib/lib/OrePAN2/Repository.pm

filter: Statementstmt 71.7% 56 / 78 Branchbran 16.6% 2 / 12 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 82.6% 19 / 23 Podpod 0.0% 0 / 10 totaltotal 59.4% 79 / 133 CC 11 SCAR 13.6
CC
11
Cov
62%
gc
12.0
__ANON__
12.0
index_file
6.0
CRAP 3.9
« blib/lib/OrePAN2/CLI/Indexer.pm ↑ Summary Build »
1 package OrePAN2::Repository;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use 5.008_001;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 use Class::Accessor::Lite 0.05 (
10 3 rw => [qw(directory cache compress_index)],
11 3 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use File::Find;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 3 ▶use File::pushd;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 3 ▶use OrePAN2::Indexer;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 3 ▶use OrePAN2::Injector;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 3 ▶use OrePAN2::Repository::Cache;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 sub new {
20 2 ▶ my $class = shift;
Subroutine new: called CC=4 SCAR=15.0
Pod undocumented
21 2 ▶ my %args = @_ == 1 ? %{ $_[0] } : @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 0 2 2
22  
23 2 for my $key (qw(directory)) {
24 2 ▶ unless ( exists $args{$key} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $args{$key}) 0 2 2
25 0 Carp::croak("Missing mandatory parameter: $key");
26 }
27 }
28 2 my $self = bless {
29 compress_index => 1,
30 %args,
31 }, $class;
32 $self->{cache}
33 2 = OrePAN2::Repository::Cache->new( directory => $self->{directory} );
34  
35 2 return $self;
36 }
37  
38 sub injector {
39 1 ▶ my $self = shift;
Subroutine injector: called CC=2 SCAR=8.1
Pod undocumented
40 1 ▶ $self->{injector} ||= OrePAN2::Injector->new(
Condition33%1/3
$self->{"injector"} ||= "OrePAN2::Injector"->new("directory", $self->directory)
l!l&&r!l&&!r
010
MC/DC0%0/2
$self->{"injector"} ||= "OrePAN2::Injector"->new("directory", $self->directory)
$self->{"injector"} "OrePAN2::Injector"->new("directory", $self->directory)
Truth table33%1/3
A ||= B
A= $self->{"injector"}B= "OrePAN2::Injector"->new("directory", $self->directory)
ABresult
1X1
011
000
41 directory => $self->directory,
42 );
43 }
44  
45 sub indexer {
46 1 ▶ my $self = shift;
Subroutine indexer: called CC=2 SCAR=8.1
Pod undocumented
47 $self->{indexer} ||= OrePAN2::Indexer->new(
48 directory => $self->directory,
49 simple => $self->{simple},
50 1 ▶ );
Condition33%1/3
$self->{"indexer"} ||= "OrePAN2::Indexer"->new("directory", $self->directory, "simple", $self->{"simple"})
l!l&&r!l&&!r
010
MC/DC0%0/2
$self->{"indexer"} ||= "OrePAN2::Indexer"->new("directory", $self->directory, "simple", $self->{"simple"})
$self->{"indexer"} "OrePAN2::Indexer"->new("directory", $self->directory, "simple", $self->{"simple"})
Truth table33%1/3
A ||= B
A= $self->{"indexer"}B= "OrePAN2::Indexer"->new("directory", $self->directory, "simple", $self->{"simple"})
ABresult
1X1
011
000
51 }
52  
53 sub has_cache {
54 2 ▶ my ( $self, $stuff ) = @_;
Subroutine has_cache: called CC=1 SCAR=0.0
Pod undocumented
55 2 $self->cache->is_hit($stuff);
56 }
57  
58 sub make_index {
59 1 ▶ my $self = shift;
Subroutine make_index: called CC=1 SCAR=0.0
Pod undocumented
60 1 $self->indexer->make_index( no_compress => !$self->compress_index );
61 }
62  
63 sub inject {
64 1 ▶ my ( $self, $stuff, $opts ) = @_;
Subroutine inject: called CC=1 SCAR=0.0
Pod undocumented
65  
66 1 my $tarpath = $self->injector->inject( $stuff, $opts );
67 1 $self->cache->set( $stuff, $tarpath );
68 }
69  
70 sub index_file {
71 0 ▶ my $self = shift;
Subroutine index_file: not called CC=2 SCAR=17.9
Pod undocumented
72 0 ▶ return File::Spec->catfile(
Branch: 1 branch
BranchTrueFalseTotal
$self->compress_index ? : 0 0 0
73 $self->directory, 'modules',
74 '02packages.details.txt' . ( $self->compress_index ? '.gz' : '' )
75 );
76 }
77  
78 sub save_cache {
79 1 ▶ my $self = shift;
Subroutine save_cache: called CC=1 SCAR=0.0
Pod undocumented
80 1 $self->cache->save;
81 }
82  
83 sub load_index {
84 0 ▶ my $self = shift;
Subroutine load_index: not called CC=1 SCAR=6.9
Pod undocumented
85  
86 0 my $index = OrePAN2::Index->new();
87 0 $index->load( $self->index_file );
88 0 $index;
89 }
90  
91 # Remove files that are not referenced by the index file.
92 sub gc {
93 0 ▶ my ($self) = @_;
Subroutine gc: not called CC=3 SCAR=24.8
Pod undocumented
94  
95 0 ▶ return unless -f $self->index_file;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $self->index_file 0 0 0
96  
97 0 my $index = $self->load_index;
98 0 my %registered;
99 0 for my $package ( $index->packages ) {
100 0 my ( $version, $path ) = $index->lookup($package);
101 0 $registered{$path}++;
102 }
103  
104 0 my $pushd = File::pushd::pushd(
105 File::Spec->catdir( $self->directory, 'authors', 'id' ) );
106 File::Find::find(
107 {
108 no_chdir => 1,
109 wanted => sub {
110 0 ▶ return unless -f $_;
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
unless -f $_ 0 0 0
111 0 $_ = File::Spec->canonpath($_);
112 0 ▶ unless ( $registered{$_} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($registered{$_}) 0 0 0
113 0 unlink $_;
114 }
115 0 1;
116 },
117 },
118 0 '.'
119 );
120 }
121  
122 3 1;
123  
« blib/lib/OrePAN2/CLI/Indexer.pm ↑ Summary Build »