]> git.vpit.fr Git - perl/modules/Acme-CPANAuthors-You-re_using.git/blob - lib/Acme/CPANAuthors/You/re_using.pm
Guard against exceptions thrown by 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 File::Find ();
7 use Module::Metadata;
8
9 use Acme::CPANAuthors::Utils;
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.06
18
19 =cut
20
21 our $VERSION;
22 BEGIN {
23  $VERSION = '0.06';
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<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.
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<register>
42
43 Fetches and registers the names into L<Acme::CPANAuthors::Register>.
44 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.
45
46 =cut
47
48 BEGIN { require Acme::CPANAuthors::Register; }
49
50 our $SKIP;
51
52 sub register {
53  return if $SKIP;
54
55  my %authors;
56
57  my $pkgs = Acme::CPANAuthors::Utils::cpan_packages();
58  die 'Couldn\'t retrieve a valid Parse::CPAN::Packages object' unless $pkgs;
59
60  my $auths = Acme::CPANAuthors::Utils::cpan_authors();
61  die 'Couldn\'t retrieve a valid Parse::CPAN::Authors object' unless $auths;
62
63  my %modules;
64
65  File::Find::find({
66   wanted => sub {
67    return unless /\.pm$/;
68    my $mod = do {
69     local $@;
70     eval { Module::Metadata->new_from_file($_) }
71    };
72    return unless $mod;
73    @modules{grep $_, $mod->packages_inside} = ();
74   },
75   follow   => 0,
76   no_chdir => 1,
77  }, @INC);
78
79  for (keys %modules) {
80   my $mod = $pkgs->package($_);
81   next unless $mod;
82
83   my $dist = $mod->distribution;
84   next unless $dist;
85
86   my $cpanid = $dist->cpanid;
87   next if not $cpanid or exists $authors{$cpanid};
88
89   my $auth = $auths->author($cpanid);
90
91   my $name;
92   $name = $auth->name if defined $auth;
93
94   $authors{$cpanid} = defined $name ? $name : $cpanid;
95  }
96
97  Acme::CPANAuthors::Register->import(%authors);
98 }
99
100 BEGIN { register() }
101
102 =head1 DEPENDENCIES
103
104 L<File::Find>, L<Module::Metadata>, L<Acme::CPANAuthors>.
105
106 =head1 SEE ALSO
107
108 All others C<Acme::CPANAuthors::*> modules.
109
110 =head1 AUTHOR
111
112 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
113
114 You can contact me by mail or on C<irc.perl.org> (vincent).
115
116 =head1 BUGS
117
118 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.
119
120 =head1 SUPPORT
121
122 You can find documentation for this module with the perldoc command.
123
124     perldoc Acme::CPANAuthors::You::re_using
125
126 =head1 COPYRIGHT & LICENSE
127
128 Copyright 2009,2010,2011,2013 Vincent Pit, all rights reserved.
129
130 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
131
132 =cut
133
134 1;