File Coverage

blib/lib/Acme/CPANAuthors/You/re_using.pm
Criterion Covered Total %
statement 45 45 100.0
branch 15 20 75.0
condition 2 3 66.6
subroutine 10 10 100.0
pod 1 1 100.0
total 73 79 92.4


line stmt bran cond sub pod time code
1             package Acme::CPANAuthors::You::re_using;
2              
3 3     3   26444 use strict;
  3         7  
  3         129  
4 3     3   13 use warnings;
  3         5  
  3         82  
5              
6 3     3   11 use File::Find ();
  3         6  
  3         41  
7 3     3   1903 use Module::Metadata;
  3         49488  
  3         132  
8              
9 3     3   568 use Acme::CPANAuthors::Utils;
  3         683  
  3         178  
10              
11             =head1 NAME
12              
13             Acme::CPANAuthors::You::re_using - We are the CPAN authors that have written the modules installed on your perl!
14              
15             =head1 VERSION
16              
17             Version 0.08
18              
19             =cut
20              
21             our $VERSION;
22             BEGIN {
23 3     3   72 $VERSION = '0.08';
24             }
25              
26             =head1 SYNOPSIS
27              
28             use Acme::CPANAuthors;
29              
30             my $authors = Acme::CPANAuthors->new("You're_using");
31             print $authors->name($_) . " ($_)\n" for $authors->id;
32              
33             =head1 DESCRIPTION
34              
35             This module builds an L class by listing all the modules that are installed on the current C and then retrieving the name and the PAUSE id of their corresponding authors.
36              
37             It may take some time to load since it has to search all the directory trees given by your C<@INC> for modules, but also to get and parse CPAN indexes.
38              
39             =head1 FUNCTIONS
40              
41             =head2 C
42              
43             Fetches and registers the names into L.
44             This function is automatically called when you C this module, unless you have set the package variable C<$Acme::CPANAuthors::You're_using::SKIP> to true beforehand.
45              
46             =cut
47              
48 3     3   1717 BEGIN { require Acme::CPANAuthors::Register; }
49              
50             our $SKIP;
51              
52             sub register {
53 3 100   3 1 36 return if $SKIP;
54              
55 2         3 my %authors;
56              
57 2         12 my $pkgs = Acme::CPANAuthors::Utils::cpan_packages();
58 2 50       31321916 die 'Couldn\'t retrieve a valid Parse::CPAN::Packages object' unless $pkgs;
59              
60 2         11 my $auths = Acme::CPANAuthors::Utils::cpan_authors();
61 2 50       1631063 die 'Couldn\'t retrieve a valid Parse::CPAN::Authors object' unless $auths;
62              
63 2         6 my %modules;
64              
65             File::Find::find({
66             wanted => sub {
67 8216 100   8216   594431 return unless /\.pm$/;
68 2586         4052 my $mod = do {
69 2586         4325 local $@;
70 2586         5581 eval { Module::Metadata->new_from_file($_) }
  2586         21268  
71             };
72 2586 100       18833867 return unless $mod;
73 2585         15206 @modules{grep $_, $mod->packages_inside} = ();
74             },
75 2         289 follow => 0,
76             no_chdir => 1,
77             }, @INC);
78              
79 2         1244 for (keys %modules) {
80 2380         5094 my $mod = $pkgs->package($_);
81 2380 100       13615 next unless $mod;
82              
83 2314         4382 my $dist = $mod->distribution;
84 2314 50       10234 next unless $dist;
85              
86 2314         4266 my $cpanid = $dist->cpanid;
87 2314 100 66     16830 next if not $cpanid or exists $authors{$cpanid};
88              
89 180         520 my $auth = $auths->author($cpanid);
90              
91 180         914 my $name;
92 180 50       576 $name = $auth->name if defined $auth;
93              
94 180 50       1247 $authors{$cpanid} = defined $name ? $name : $cpanid;
95             }
96              
97 2         543 Acme::CPANAuthors::Register->import(%authors);
98             }
99              
100 3     3   1717 BEGIN { register() }
101              
102             =head1 DEPENDENCIES
103              
104             L (core since perl 5)
105              
106             L 0.16.
107              
108             L 1.000_017.
109              
110             =head1 SEE ALSO
111              
112             All others C modules.
113              
114             =head1 AUTHOR
115              
116             Vincent Pit, C<< >>, L.
117              
118             You can contact me by mail or on C (vincent).
119              
120             =head1 BUGS
121              
122             Please report any bugs or feature requests to C, or through the web interface at L. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
123              
124             =head1 SUPPORT
125              
126             You can find documentation for this module with the perldoc command.
127              
128             perldoc Acme::CPANAuthors::You::re_using
129              
130             =head1 COPYRIGHT & LICENSE
131              
132             Copyright 2009,2010,2011,2013,2015 Vincent Pit, all rights reserved.
133              
134             This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
135              
136             =cut
137              
138             1;