]> git.vpit.fr Git - perl/modules/Acme-CPANAuthors-You-re_using.git/blob - lib/Acme/CPANAuthors/You/re_using.pm
Replace ExtUtils::Installed by File::Find/Module::Metadata
[perl/modules/Acme-CPANAuthors-You-re_using.git] / lib / Acme / CPANAuthors / You / re_using.pm
1 package Acme::CPANAuthors::You::re_using;
2
3 use strict;
4 use warnings;
5
6 use Carp qw/croak/;
7
8 use File::Find ();
9 use Module::Metadata;
10
11 use Acme::CPANAuthors::Utils;
12
13 =head1 NAME
14
15 Acme::CPANAuthors::You::re_using - We are the CPAN authors that have written the modules installed on your perl!
16
17 =head1 VERSION
18
19 Version 0.03
20
21 =cut
22
23 our $VERSION;
24 BEGIN {
25  $VERSION = '0.03';
26 }
27
28 =head1 SYNOPSIS
29
30     use Acme::CPANAuthors;
31
32     my $authors = Acme::CPANAuthors->new("You're_using");
33     print $authors->name($_) . " ($_)\n" for $authors->id;
34
35 =head1 DESCRIPTION
36
37 This module builds an L<Acme::CPANAuthors> class by listing all the modules that are installed on the current C<perl> and then retrieving the name and the PAUSE id of their corresponding authors.
38
39 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.
40
41 =head1 FUNCTIONS
42
43 =head2 C<register>
44
45 Fetches and registers the names into L<Acme::CPANAuthors::Register>.
46 This function is automatically called when you C<use> this module, unless you have set the package variable C<$Acme::CPANAuthors::You're_using::SKIP> to true beforehand.
47
48 =cut
49
50 BEGIN { require Acme::CPANAuthors::Register; }
51
52 our $SKIP;
53
54 sub register {
55  return if $SKIP;
56
57  my %authors;
58
59  my $pkgs = Acme::CPANAuthors::Utils::cpan_packages();
60  croak 'Couldn\'t retrieve a valid Parse::CPAN::Packages object' unless $pkgs;
61
62  my $auths = Acme::CPANAuthors::Utils::cpan_authors();
63  croak 'Couldn\'t retrieve a valid Parse::CPAN::Authors object' unless $auths;
64
65  my %modules;
66
67  File::Find::find({
68   wanted => sub {
69    return unless /\.pm$/;
70    my $mod = Module::Metadata->new_from_file($_);
71    return unless $mod;
72    @modules{grep $_, $mod->packages_inside} = ();
73   },
74   follow   => 0,
75   no_chdir => 1,
76  }, @INC);
77
78  for (keys %modules) {
79   my $mod = $pkgs->package($_);
80   next unless $mod;
81
82   my $dist = $mod->distribution;
83   next unless $dist;
84
85   my $cpanid = $dist->cpanid;
86   next if not $cpanid or exists $authors{$cpanid};
87
88   my $auth = $auths->author($cpanid);
89
90   my $name;
91   $name = $auth->name if defined $auth;
92  
93   $authors{$cpanid} = defined $name ? $name : $cpanid;
94  }
95
96  Acme::CPANAuthors::Register->import(%authors);
97 }
98
99 BEGIN { register() }
100
101 =head1 DEPENDENCIES
102
103 L<Carp>, L<File::Find>, L<Module::Metadata>, L<Acme::CPANAuthors>.
104
105 =head1 SEE ALSO
106
107 All others C<Acme::CPANAuthors::*> modules.
108
109 =head1 AUTHOR
110
111 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
112
113 You can contact me by mail or on C<irc.perl.org> (vincent).
114
115 =head1 BUGS
116
117 Please report any bugs or feature requests to C<bug-acme-cpanauthors-you-re_using at rt.cpan.org>, or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Acme-CPANAuthors-You-re_using>.  I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
118
119 =head1 SUPPORT
120
121 You can find documentation for this module with the perldoc command.
122
123     perldoc Acme::CPANAuthors::You::re_using
124
125 =head1 COPYRIGHT & LICENSE
126
127 Copyright 2009,2010,2011 Vincent Pit, all rights reserved.
128
129 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
130
131 =cut
132
133 1;