blib/lib/Template/Plugin/CPAN/Packages.pm

filter: Statementstmt 96.6% 57 / 59 Branchbran 62.5% 15 / 24 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 8 / 8 Podpod 75.0% 3 / 4 totaltotal 85.7% 84 / 98 CC 18 SCAR 18.4
CC
18
Cov
86%
bundle_by_dist_prefix
9.5
bundle_for_author
7.2
get_primary_package
4.1
CRAP 6.3
↑ Summary
1 package Template::Plugin::CPAN::Packages;
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 Parse::CPAN::Packages;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7  
8 3 our $VERSION = '0.03';
9  
10  
11 3 ▶use base 'Template::Plugin';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13  
14 2 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
15 2 my ($class, $context, $packages_file) = @_;
16  
17 2 bless {
18 _CONTEXT => $context,
19 packages_file => $packages_file,
20 packages => Parse::CPAN::Packages->new($packages_file),
21 }, $class;
22 }
23  
24  
25 27 ▶sub get_primary_package {
Subroutine get_primary_package: called CC=4 SCAR=14.1
Pod undocumented
26 27 my ($self, $dist) = @_;
27  
28 # Only take those packages whose names start with the equivalent of the
29 # dist, i.e., for Foo-Bar, only use Foo::Bar and packages below that.
30  
31 27 (my $base_pkg = $dist->dist) =~ s/-/::/g;
32  
33 27 ▶ my @packages = @{ $dist->packages || [] };
Condition50%1/2
$dist->packages || []
l!l
270
MC/DC0%0/1
$dist->packages || []
$dist->packages
Truth table50%1/2
A
A= $dist->packages
Aresult
11
00
34  
35 27 ▶ unless (@packages) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@packages) 0 27 27
36 0 warn sprintf "dist [%s] doesn't contain any packages?\n", $dist->dist;
37 0 return;
38 }
39  
40 my @dist_packages =
41 503 sort { length($a) <=> length($b) }
42 162 grep { index($_, $base_pkg) == 0 }
43 27 map { $_->package }
44 @packages;
45  
46 27 ▶ unless (@dist_packages) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@dist_packages) 1 26 27
47 1 my $other_package = $packages[0]->package;
48 1 warn sprintf
49 "couldn't get primary package for dist [%s], using [%s]\n",
50 $dist->dist, $other_package;
51 1 return $other_package;
52 }
53  
54 26 $dist_packages[0];
55 }
56  
57  
58 1 ▶sub bundle_for_author {
Subroutine bundle_for_author: called CC=7 SCAR=19.7
Pod documented
59 1 my ($self, $args) = @_;
60  
61 1 ▶ defined $args->{cpanid} || die "bundle_for_author(): need 'cpanid' key\n";
Branch: 1 branch
BranchTrueFalseTotal
defined $args->{"cpanid"} or die "bundle_for_author(): need 'cpanid' key\n" 1 0 1
62  
63 1 my @unwanted;
64 1 ▶ if (exists $args->{unwanted}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{"unwanted"}) 1 0 1
65 @unwanted = ref $args->{unwanted} eq 'ARRAY'
66 1 ? @{ $args->{unwanted} }
67 1 ▶ : ($args->{unwanted});
Branch: 1 branch
BranchTrueFalseTotal
ref $args->{'unwanted'} eq 'ARRAY' ? : 1 0 1
68 }
69  
70 1 my %req;
71  
72 1 for my $dist ($self->{packages}->distributions) {
73 360 ▶ next unless $dist->cpanid eq $args->{cpanid};
Branch: 1 branch
BranchTrueFalseTotal
unless $dist->cpanid eq $args->{"cpanid"} 349 11 360
74 11 $req{ $self->get_primary_package($dist) } = 1;
75 }
76  
77 1 delete $req{$_} for @unwanted;
78 1 join "\n\n" => sort keys %req;
79 }
80  
81  
82 1 ▶sub bundle_by_dist_prefix {
Subroutine bundle_by_dist_prefix: called CC=9 SCAR=22.5
Pod documented
83 1 my ($self, $args) = @_;
84  
85 defined $args->{prefix} ||
86 1 ▶ die "bundle_by_dist_prefix(): need 'prefix' key\n";
Branch: 1 branch
BranchTrueFalseTotal
defined $args->{"prefix"} or die "bundle_by_dist_prefix(): need 'prefix' key\n" 1 0 1
87  
88 1 my @unwanted;
89 1 ▶ if (exists $args->{unwanted}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{"unwanted"}) 1 0 1
90 @unwanted = ref $args->{unwanted} eq 'ARRAY'
91 1 ? @{ $args->{unwanted} }
92 1 ▶ : ($args->{unwanted});
Branch: 1 branch
BranchTrueFalseTotal
ref $args->{'unwanted'} eq 'ARRAY' ? : 1 0 1
93 }
94  
95 1 my %req;
96  
97 1 for my $dist ($self->{packages}->distributions) {
98 360 my $name = $dist->dist;
99 360 ▶ next unless $name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 360 360
100 360 ▶ next if index($name, 'Bundle') != -1;
Branch: 1 branch
BranchTrueFalseTotal
if index($name, "Bundle") != -1 0 360 360
101 360 ▶ next unless index($name, $args->{prefix}) == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless index($name, $args->{"prefix"}) == 0 344 16 360
102 16 $req{ $self->get_primary_package($dist) } = 1;
103 }
104  
105 1 delete $req{$_} for @unwanted;
106 1 join "\n\n" => sort keys %req;
107 }
108  
109  
110 3 1;
111  
112  
113 __END__
↑ Summary