use strict;
use warnings;
-use Carp qw/croak/;
-
-use ExtUtils::Installed;
+use File::Find ();
+use Module::Metadata;
use Acme::CPANAuthors::Utils;
=head1 VERSION
-Version 0.01
+Version 0.08
=cut
our $VERSION;
BEGIN {
- $VERSION = '0.01';
+ $VERSION = '0.08';
}
=head1 SYNOPSIS
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.
-It may take some time to load since it has to get CPAN indexes at C<BEGIN> time.
+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.
+
+=head1 FUNCTIONS
+
+=head2 C<register>
+
+Fetches and registers the names into L<Acme::CPANAuthors::Register>.
+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.
=cut
-BEGIN {
- my %authors;
+BEGIN { require Acme::CPANAuthors::Register; }
- my $pkgs = Acme::CPANAuthors::Utils::cpan_packages();
- croak 'Couldn\'t retrieve a valid Parse::CPAN::Packages object' unless $pkgs;
+our $SKIP;
- my $auths = Acme::CPANAuthors::Utils::cpan_authors();
- croak 'Couldn\'t retrieve a valid Parse::CPAN::Authors object' unless $auths;
+sub register {
+ return if $SKIP;
- my $installed = ExtUtils::Installed->new(extra_libs => \@INC);
- croak 'Couldn\'t create a valid ExtUtils::Installed object' unless $installed;
+ my %authors;
- for ($installed->modules) {
- next unless defined and $_ ne 'Perl';
+ my $pkgs = Acme::CPANAuthors::Utils::cpan_packages();
+ die 'Couldn\'t retrieve a valid Parse::CPAN::Packages object' unless $pkgs;
+ my $auths = Acme::CPANAuthors::Utils::cpan_authors();
+ die 'Couldn\'t retrieve a valid Parse::CPAN::Authors object' unless $auths;
+
+ my %modules;
+
+ File::Find::find({
+ wanted => sub {
+ return unless /\.pm$/;
+ my $mod = do {
+ local $@;
+ eval { Module::Metadata->new_from_file($_) }
+ };
+ return unless $mod;
+ @modules{grep $_, $mod->packages_inside} = ();
+ },
+ follow => 0,
+ no_chdir => 1,
+ }, @INC);
+
+ for (keys %modules) {
my $mod = $pkgs->package($_);
next unless $mod;
my $name;
$name = $auth->name if defined $auth;
-
+
$authors{$cpanid} = defined $name ? $name : $cpanid;
}
- require Acme::CPANAuthors::Register;
Acme::CPANAuthors::Register->import(%authors);
}
+BEGIN { register() }
+
=head1 DEPENDENCIES
-L<Carp>, L<ExtUtils::Installed>, L<Acme::CPANAuthors>.
+L<File::Find> (core since perl 5)
+
+L<Acme::CPANAuthors> 0.16.
+
+L<Module::Metadata> 1.000_017.
=head1 SEE ALSO
=head1 COPYRIGHT & LICENSE
-Copyright 2009 Vincent Pit, all rights reserved.
+Copyright 2009,2010,2011,2013,2015 Vincent Pit, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.