blib/lib/CPAN/Diff.pm

filter: Statementstmt 34.8% 39 / 112 Branchbran 0.0% 0 / 36 Conditioncond 0.0% 0 / 11 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 37.5% 9 / 24 Podpod 0.0% 0 / 7 totaltotal 24.3% 48 / 197 CC 24 SCAR 39.3
CC
24
Cov
25%
_build_cache
156.0
compare_version
56.0
cpan
12.0
CRAP 50.8
↑ Summary Build »
1 package CPAN::Diff;
2 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 1 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use ExtUtils::Installed;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use HTTP::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Module::Extract::Namespaces;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Module::Metadata;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Parse::CPAN::Packages::Fast;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use CPAN::Diff::Module;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 our $VERSION = "0.01";
14  
15 1 has mirror => (is => 'ro', builder => 1);
16 1 has exclude_core => (is => 'rw');
17 1 has local_lib => (is => 'rw');
18 1 has self_contained => (is => 'rw');
19  
20 1 has extra_modules => (is => 'rw', lazy => 1, builder => 1);
21 1 has newer_modules => (is => 'rw', lazy => 1, builder => 1);
22 1 has older_modules => (is => 'rw', lazy => 1, builder => 1);
23  
24 1 has core_modules => (is => 'rw', lazy => 1, builder => 1);
25 1 has tmp_dir => (is => 'rw', builder => 1);
26 1 has cache => (is => 'rw', lazy => 1, builder => 1);
27  
28 0 ▶sub _build_mirror { "http://cpan.org" };
Subroutine _build_mirror: not called CC=1 SCAR=6.9
29 0 ▶sub _build_tmp_dir { "/tmp" };
Subroutine _build_tmp_dir: not called CC=1 SCAR=6.9
30 sub _build_core_modules {
31 0 ▶ return undef unless shift->exclude_core;
Subroutine _build_core_modules: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
unless (shift())->exclude_core 0 0 0
32 0 require Module::CoreList;
33 0 $Module::CoreList::version{$]};
34 }
35  
36 0 ▶sub _build_extra_modules { shift->cache->{extra} }
Subroutine _build_extra_modules: not called CC=1 SCAR=6.9
37 0 ▶sub _build_newer_modules { shift->cache->{newer} }
Subroutine _build_newer_modules: not called CC=1 SCAR=6.9
38 0 ▶sub _build_older_modules { shift->cache->{older} }
Subroutine _build_older_modules: not called CC=1 SCAR=6.9
39  
40 0 ▶sub case_insensitive { lc($a) cmp lc($b) }
Subroutine case_insensitive: not called CC=1 SCAR=6.9
Pod undocumented
41  
42 sub _build_cache {
43 0 ▶ my ($self) = @_;
Subroutine _build_cache: not called CC=12 SCAR=50.5
44 0 my @inc = $self->make_inc;
45 0 my $cpan = $self->cpan;
46 0 my @local_pkgs = $self->get_local_pkgs(@inc);
47 0 my (@extra, @newer, @older);
48  
49 0 for my $local_pkg (sort case_insensitive @local_pkgs) {
50 0 my $pkg = $cpan->package($local_pkg);
51 0 ▶ my $local_version = $self->local_version_for($local_pkg, \@inc) || next;
Condition0%0/2
$self->local_version_for($local_pkg, \@inc) || (next)
l!l
00
MC/DC0%0/1
$self->local_version_for($local_pkg, \@inc) || (next)
$self->local_version_for($local_pkg, \@inc)
Truth table0%0/2
A
A= $self->local_version_for($local_pkg, \@inc)
Aresult
11
00
52 0 ▶ next unless $local_version =~ /[0-9]/;
Branch: 1 branch
BranchTrueFalseTotal
unless $local_version =~ /[0-9]/ 0 0 0
53 0 ▶ next if $self->core_modules && $self->core_modules->{$local_pkg};
Branch: 1 branch
BranchTrueFalseTotal
if $self->core_modules and $self->core_modules->{$local_pkg} 0 0 0
Condition0%0/3
$self->core_modules and $self->core_modules->{$local_pkg}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->core_modules and $self->core_modules->{$local_pkg}
$self->core_modules $self->core_modules->{$local_pkg}
Truth table0%0/3
A and B
A= $self->core_modulesB= $self->core_modules->{$local_pkg}
ABresult
0X0
100
111
54 0 ▶ my $metadata = CPAN::Diff::Module->new(
Branch: 2 branches
BranchTrueFalseTotal
$pkg ? : 0 0 0
$pkg ? : 0 0 0
55 name => $local_pkg,
56 local_version => $local_version,
57 cpan_version => $pkg ? $pkg->version : undef,
58 cpan_dist => $pkg ? $pkg->distribution : undef,
59 );
60  
61 0 ▶ if (!$pkg) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $pkg) { } 0 0 0
62 0 push @extra, $metadata;
63 }
64 else {
65 0 my $result = $self->compare_version($local_version, $pkg->version);
66 0 ▶ next if $result == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $result == 0 0 0 0
67 0 ▶ push @newer, $metadata if $result == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $result == 1 0 0 0
68 0 ▶ push @older, $metadata if $result == -1;
Branch: 1 branch
BranchTrueFalseTotal
if $result == -1 0 0 0
69 }
70 }
71  
72 0 return { extra => \@extra, newer => \@newer, older => \@older };
73 }
74  
75 sub cpan {
76 0 ▶ my $self = shift;
Subroutine cpan: not called CC=3 SCAR=24.8
Pod undocumented
77 0 my $file;
78  
79 0 ▶ if ($self->mirror =~ m|^file\://(.*)|i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->mirror =~ m[^file\://(.*)]i) { } 0 0 0
80 0 $file = $1;
81 }
82 else {
83 0 my $uri = $self->mirror;
84 0 $uri =~ s|/$||;
85 0 $uri = "$uri/modules/02packages.details.txt.gz";
86  
87 0 my $unique = $uri;
88 0 $unique =~ s|/|_|g;
89 0 $file = $self->tmp_dir . "/" . $unique;
90  
91 0 my $res = HTTP::Tiny->new->mirror($uri, $file);
92 die "failed to download $uri to $file:\n$res->{status} $res->{reason}\n"
93 0 ▶ unless $res->{success};
Branch: 1 branch
BranchTrueFalseTotal
unless $res->{"success"} 0 0 0
94 }
95 0 return Parse::CPAN::Packages::Fast->new($file);
96 }
97  
98 sub compare_version {
99 0 ▶ my ($self, $local_version, $version) = @_;
Subroutine compare_version: not called CC=7 SCAR=40.3
Pod undocumented
100 0 ▶ return 0 if $local_version eq $version;
Branch: 1 branch
BranchTrueFalseTotal
if $local_version eq $version 0 0 0
101  
102 0 ▶ my $local_version_obj = eval { version->new($local_version) } || version->new(permissive_filter($local_version));
Condition0%0/3
eval { do { 'version'->new($local_version) } } || 'version'->new(permissive_filter($local_version))
l!l&&r!l&&!r
000
MC/DC0%0/2
eval { do { 'version'->new($local_version) } } || 'version'->new(permissive_filter($local_version))
eval { do { 'version'->new($local_version) } } 'version'->new(permissive_filter($local_version))
Truth table0%0/3
A || B
A= eval { do { 'version'->new($local_version) } }B= 'version'->new(permissive_filter($local_version))
ABresult
1X1
011
000
103 0 ▶ my $version_obj = eval { version->new($version) } || version->new(permissive_filter($version));
Condition0%0/3
eval { do { 'version'->new($version) } } || 'version'->new(permissive_filter($version))
l!l&&r!l&&!r
000
MC/DC0%0/2
eval { do { 'version'->new($version) } } || 'version'->new(permissive_filter($version))
eval { do { 'version'->new($version) } } 'version'->new(permissive_filter($version))
Truth table0%0/3
A || B
A= eval { do { 'version'->new($version) } }B= 'version'->new(permissive_filter($version))
ABresult
1X1
011
000
104  
105 0 ▶ return 1 if $local_version_obj > $version_obj;
Branch: 1 branch
BranchTrueFalseTotal
if $local_version_obj > $version_obj 0 0 0
106 0 ▶ return -1 if $local_version_obj < $version_obj;
Branch: 1 branch
BranchTrueFalseTotal
if $local_version_obj < $version_obj 0 0 0
107 0 ▶ return 0 if $local_version_obj == $version_obj;
Branch: 1 branch
BranchTrueFalseTotal
if $local_version_obj == $version_obj 0 0 0
108 }
109  
110 # for broken packages.
111 sub permissive_filter {
112 0 ▶ local $_ = $_[0];
Subroutine permissive_filter: not called CC=1 SCAR=6.9
Pod undocumented
113 0 s/^[Vv](\d)/$1/; # Bioinf V2.0
114 0 s/^(\d+)_(\d+)$/$1.$2/; # VMS-IndexedFile 0_02
115 0 s/-[a-zA-Z]+$//; # Math-Polygon-Tree 0.035-withoutworldwriteables
116 0 s/([a-j])/ord($1)-ord('a')/gie; # DBD-Solid 0.20a
117 0 s/[_h-z-]/./gi; # makepp 1.50.2vs.070506
118 0 s/\.{2,}/./g;
119 0 $_;
120 }
121  
122 sub local_version_for {
123 0 ▶ my ($self, $pkg, $inc) = @_;
Subroutine local_version_for: not called CC=2 SCAR=17.9
Pod undocumented
124  
125 0 ▶ local $SIG{__WARN__} = sub {};
Subroutine __ANON__: not called CC=1 SCAR=6.9
126 0 my $meta = Module::Metadata->new_from_module($pkg, inc => $inc);
127 0 ▶ $meta ? $meta->version($pkg) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$meta ? : 0 0 0
128 }
129  
130 sub get_local_pkgs {
131 0 ▶ my ($self, @inc) = @_;
Subroutine get_local_pkgs: not called CC=1 SCAR=6.9
Pod undocumented
132 # TODO: if you want to filter the target modules, you can change them here.
133 0 ExtUtils::Installed->new(skip_cwd => 1, inc_override => \@inc)->modules;
134 }
135  
136 sub make_inc {
137 0 ▶ my ($self) = @_;
Subroutine make_inc: not called CC=3 SCAR=24.8
Pod undocumented
138  
139 0 ▶ if ($self->local_lib) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->local_lib) { } 0 0 0
140 0 require local::lib;
141 0 my @modified_inc = (
142 local::lib->install_base_perl_path($self->local_lib),
143 local::lib->install_base_arch_path($self->local_lib),
144 );
145 0 ▶ if ($self->self_contained) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->self_contained) { } 0 0 0
146 0 push @modified_inc, @Config{qw(privlibexp archlibexp)};
147 } else {
148 0 push @modified_inc, @INC;
149 }
150 0 return @modified_inc;
151 } else {
152 0 return @INC;
153 }
154 }
155  
156 1 1;
157 __END__
↑ Summary Build »