CPANAuthors.pm

filter: Statementstmt 81.7% 76 / 93 Branchbran 54.3% 25 / 46 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 87.5% 14 / 16 Podpod 100% 10 / 10 totaltotal 76.4% 130 / 170 CC 29 SCAR 20.2
CC
29
Cov
73%
distributions
20.0
latest_distributions
20.0
look_for
9.2
CRAP 7.5
« CPANAuthors/Utils.pm ↑ Summary CPANAuthors/Utils/Packages.pm »
1 package Acme::CPANAuthors;
2  
3 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 7 ▶use Acme::CPANAuthors::Utils qw( cpan_authors cpan_packages );
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 7 our $VERSION = '0.27';
9  
10 3 ▶sub new {
Subroutine new: called CC=3 SCAR=11.0
Pod documented
11 3 my ($class, @categories) = @_;
12  
13 3 ▶ @categories = _list_categories() unless @categories;
Branch: 1 branch
BranchTrueFalseTotal
unless @categories 0 3 3
14  
15 3 my %authors;
16 3 foreach my $category ( @categories ) {
17 3 %authors = ( %authors, _get_authors_of($category) );
18 }
19  
20 bless {
21 3 categories => \@categories,
22 authors => \%authors,
23 }, $class;
24 }
25  
26 2 ▶sub count {
Subroutine count: called CC=1 SCAR=0.0
Pod documented
27 2 my $self = shift;
28  
29 2 return scalar keys %{ $self->{authors} };
30 }
31  
32 4 ▶sub id {
Subroutine id: called CC=3 SCAR=11.0
Pod documented
33 4 my ($self, $id) = @_;
34  
35 4 ▶ unless ( $id ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id) { } 2 2 4
36 2 my @ids = sort keys %{ $self->{authors} };
37 2 return @ids;
38 }
39 else {
40 2 ▶ return $self->{authors}{$id} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'authors'}{$id} ? : 2 0 2
41 }
42 }
43  
44 5 ▶sub name {
Subroutine name: called CC=2 SCAR=6.9
Pod documented
45 5 my ($self, $id) = @_;
46  
47 5 ▶ unless ( $id ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id) { } 3 2 5
48 2 return sort values %{ $self->{authors} };
49 }
50 else {
51 3 return $self->{authors}{$id};
52 }
53 }
54  
55 2 ▶sub categories {
Subroutine categories: called CC=1 SCAR=0.0
Pod documented
56 2 my $self = shift;
57 2 return @{$self->{categories}};
58 }
59  
60 0 ▶sub distributions {
Subroutine distributions: not called CC=4 SCAR=30.0
Pod documented
61 0 my ($self, $id) = @_;
62  
63 0 ▶ return unless $id;
Branch: 1 branch
BranchTrueFalseTotal
unless $id 0 0 0
64  
65 0 my @packages;
66 0 foreach my $package ( cpan_packages->distributions ) {
67 0 ▶ if ( $package->cpanid eq $id ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($package->cpanid eq $id) 0 0 0
68 0 push @packages, $package;
69 }
70 }
71  
72 0 return @packages;
73 }
74  
75 0 ▶sub latest_distributions {
Subroutine latest_distributions: not called CC=4 SCAR=30.0
Pod documented
76 0 my ($self, $id) = @_;
77  
78 0 ▶ return unless $id;
Branch: 1 branch
BranchTrueFalseTotal
unless $id 0 0 0
79  
80 0 my @packages;
81 0 foreach my $package ( cpan_packages->latest_distributions ) {
82 0 ▶ if ( $package->cpanid eq $id ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($package->cpanid eq $id) 0 0 0
83 0 push @packages, $package;
84 }
85 }
86  
87 0 return @packages;
88 }
89  
90 1 ▶sub avatar_url {
Subroutine avatar_url: called CC=5 SCAR=16.8
Pod documented
91 1 my ($self, $id, %options) = @_;
92  
93 1 ▶ return unless $id;
Branch: 1 branch
BranchTrueFalseTotal
unless $id 0 1 1
94  
95 1 ▶ eval {require Gravatar::URL; 1}
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Gravatar::URL; 1 } } or warn($@), return 1 0 1
96 or warn($@), return;
97 1 ▶ my $author = cpan_authors->author($id) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $author = &cpan_authors()->author($id) or return 1 0 1
98  
99 1 my $default = delete $options{default};
100 1 ▶ return Gravatar::URL::gravatar_url(
Branch: 1 branch
BranchTrueFalseTotal
$default ? : 0 1 1
101 email => $author->email,
102 %options,
103 default => Gravatar::URL::gravatar_url(
104 # Fall back to the CPAN address, as used by metacpan, which will in
105 # turn fall back to a generated image.
106 email => $id . '@cpan.org',
107 %options,
108 $default ? ( default => $default ) : (),
109 ),
110 );
111 }
112  
113 1 ▶sub kwalitee {
Subroutine kwalitee: called CC=2 SCAR=7.0
Pod documented
114 1 my ($self, $id) = @_;
115  
116 1 ▶ return unless $id;
Branch: 1 branch
BranchTrueFalseTotal
unless $id 0 1 1
117  
118 1 require Acme::CPANAuthors::Utils::Kwalitee;
119 1 return Acme::CPANAuthors::Utils::Kwalitee->fetch($id);
120 }
121  
122 5 ▶sub look_for {
Subroutine look_for: called CC=9 SCAR=22.2
Pod documented
123 5 my ($self, $id_or_name) = @_;
124  
125 5 ▶ return unless defined $id_or_name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $id_or_name 0 5 5
126 5 ▶ unless (ref $id_or_name eq 'Regexp') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $id_or_name eq "Regexp") 4 1 5
127 4 $id_or_name = qr/$id_or_name/i;
128 }
129  
130 5 my @found;
131 0 ▶ my @categories = ref $self ? @{ $self->{categories} } : ();
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 0 5 5
132 5 ▶ @categories = _list_categories() unless @categories;
Branch: 1 branch
BranchTrueFalseTotal
unless @categories 5 0 5
133 5 foreach my $category ( @categories ) {
134 10 my %authors = _get_authors_of($category);
135 10 ▶ while ( my ($id, $name) = each %authors ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %authors) 10 10 20
136 10 ▶ if ($id =~ /$id_or_name/ or $name =~ /$id_or_name/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id =~ /$id_or_name/ or $name =~ /$id_or_name/) 5 5 10
Condition100%3/3
$id =~ /$id_or_name/ or $name =~ /$id_or_name/
l!l&&r!l&&!r
235
MC/DC100%2/2
$id =~ /$id_or_name/ or $name =~ /$id_or_name/
$id =~ /$id_or_name/ $name =~ /$id_or_name/
Truth table100%3/3
A or B
A= $id =~ /$id_or_name/B= $name =~ /$id_or_name/
ABresult
1X1
011
000
137 5 push @found, {
138 id => $id,
139 name => $name,
140 category => $category,
141 };
142 }
143 }
144 }
145 5 return @found;
146 }
147  
148 5 ▶sub _list_categories {
Subroutine _list_categories: called CC=1 SCAR=0.0
149 5 require Module::Find;
150 25 return grep { $_ !~ /^(?:Register|Utils|Not|Search|Factory)$/ }
151 5 map { s/^Acme::CPANAuthors:://; $_ }
152 Module::Find::findsubmod( 'Acme::CPANAuthors' );
153 }
154  
155 13 ▶sub _get_authors_of {
Subroutine _get_authors_of: called CC=5 SCAR=17.0
156 13 my $category = shift;
157  
158 13 $category =~ s/^Acme::CPANAuthors:://;
159  
160 13 ▶ return if $category =~ /^(?:Register|Utils|Search)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $category =~ /^(?:Register|Utils|Search)$/ 0 13 13
161  
162 13 my $package = "Acme::CPANAuthors\::$category";
163 13 ▶ unless ($package->can('authors')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($package->can("authors")) 4 9 13
164 4 eval "require $package";
165 4 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 4 4
166 0 carp "$category CPAN Authors are not registered yet: $@";
167 0 return;
168 }
169 # some may actually lack 'authors' interface
170 4 ▶ return unless $package->can('authors');
Branch: 1 branch
BranchTrueFalseTotal
unless $package->can("authors") 0 4 4
171 }
172 13 $package->authors;
173 }
174  
175 7 1;
176  
177 __END__
« CPANAuthors/Utils.pm ↑ Summary CPANAuthors/Utils/Packages.pm »