| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 0 | my @packages; | |||||||||||||||||||||||||||
| 66 | 0 | foreach my $package ( cpan_packages->distributions ) { | |||||||||||||||||||||||||||
| 67 | 0 | ▶ | if ( $package->cpanid eq $id ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 0 | my @packages; | |||||||||||||||||||||||||||
| 81 | 0 | foreach my $package ( cpan_packages->latest_distributions ) { | |||||||||||||||||||||||||||
| 82 | 0 | ▶ | if ( $package->cpanid eq $id ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 1 | ▶ | eval {require Gravatar::URL; 1} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | or warn($@), return; | ||||||||||||||||||||||||||||
| 97 | 1 | ▶ | my $author = cpan_authors->author($id) or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 1 | my $default = delete $options{default}; | |||||||||||||||||||||||||||
| 100 | 1 | ▶ | return Gravatar::URL::gravatar_url( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 126 | 5 | ▶ | unless (ref $id_or_name eq 'Regexp') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 132 | 5 | ▶ | @categories = _list_categories() unless @categories; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 136 | 10 | ▶ | if ($id =~ /$id_or_name/ or $name =~ /$id_or_name/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$id =~ /$id_or_name/ or $name =~ /$id_or_name/
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/
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 13 | my $package = "Acme::CPANAuthors\::$category"; | |||||||||||||||||||||||||||
| 163 | 13 | ▶ | unless ($package->can('authors')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 164 | 4 | eval "require $package"; | |||||||||||||||||||||||||||
| 165 | 4 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||
| 172 | 13 | $package->authors; | |||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | 7 | 1; | |||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | __END__ | ||||||||||||||||||||||||||||