| 1 | #!perl |
|---|
| 2 | |
|---|
| 3 | use strict; |
|---|
| 4 | use warnings; |
|---|
| 5 | use FindBin; |
|---|
| 6 | use lib "$FindBin::Bin/../lib"; |
|---|
| 7 | use Web::Scraper; |
|---|
| 8 | use URI; |
|---|
| 9 | use YAML; |
|---|
| 10 | use CPAN::Config; |
|---|
| 11 | use Parse::CPAN::Authors; |
|---|
| 12 | use Template; |
|---|
| 13 | use Time::Piece; |
|---|
| 14 | use Acme::CPANAuthors::CodeRepos; |
|---|
| 15 | |
|---|
| 16 | my %mapping = ( |
|---|
| 17 | # people whose coderepos id is not the same as their pause id |
|---|
| 18 | AMACHANG => 'ITWARRIOR', |
|---|
| 19 | AUTARCH => 'DROLSKY', |
|---|
| 20 | CASTAWAY => 'JROBINSON', |
|---|
| 21 | CHARSBAR => 'ISHIGAKI', |
|---|
| 22 | CLOUDER => 'KURIHARA', |
|---|
| 23 | DAISUKE => 'DMAKI', |
|---|
| 24 | FBIS => 'MIYAZAKI', |
|---|
| 25 | HANEKOMU => 'MARCEL', |
|---|
| 26 | HIDEK => 'HIDE', |
|---|
| 27 | HIROSE31 => 'HIROSE', |
|---|
| 28 | KAN => 'MIKIHOSHI', |
|---|
| 29 | MARCUS => 'MRAMBERG', |
|---|
| 30 | MATTHEWT => 'MSTROUT', |
|---|
| 31 | MOSELEY => 'HANK', |
|---|
| 32 | NIPOTAN => 'TANIGUCHI', |
|---|
| 33 | NOTHINGMUCH => 'NUFFIN', |
|---|
| 34 | TAKEMARU => 'TAKERU', |
|---|
| 35 | VKGTARO => 'TARO', |
|---|
| 36 | |
|---|
| 37 | # people whose coderepos id matches other person's pause id |
|---|
| 38 | BULB => '- other person -', |
|---|
| 39 | DANN => '- other person -', |
|---|
| 40 | OMEGA => '- other person -', |
|---|
| 41 | ); |
|---|
| 42 | |
|---|
| 43 | my $command = shift; # from @ARGV |
|---|
| 44 | |
|---|
| 45 | my $committers; |
|---|
| 46 | if ( $command && $command =~ /scraper/ ) { |
|---|
| 47 | my $scraper = scraper { |
|---|
| 48 | process "ul>li>a", |
|---|
| 49 | "committers[]" => sub { |
|---|
| 50 | my $e = shift; |
|---|
| 51 | return unless $e->attr('href') =~ m{/wiki/Committers/(\w+)$}; |
|---|
| 52 | return uc $1; |
|---|
| 53 | }; |
|---|
| 54 | }; |
|---|
| 55 | |
|---|
| 56 | $committers = $scraper->scrape( |
|---|
| 57 | URI->new('http://coderepos.org/share') |
|---|
| 58 | )->{committers}; |
|---|
| 59 | |
|---|
| 60 | YAML::DumpFile("$FindBin::Bin/coderepos_users.yml", $committers); |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | $committers ||= YAML::LoadFile("$FindBin::Bin/coderepos_users.yml"); |
|---|
| 64 | |
|---|
| 65 | my $authors_file; |
|---|
| 66 | foreach my $path ( |
|---|
| 67 | File::Spec->catdir($CPAN::Config->{keep_source_where}, 'authors'), |
|---|
| 68 | $CPAN::Config->{keep_source_where}, |
|---|
| 69 | "" |
|---|
| 70 | ) { |
|---|
| 71 | $authors_file = File::Spec->catfile( $path, '01mailrc.txt.gz' ); |
|---|
| 72 | last if -f $authors_file; |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | my $cpan = Parse::CPAN::Authors->new( $authors_file ); |
|---|
| 76 | |
|---|
| 77 | my %cpan_authors = Acme::CPANAuthors::CodeRepos->authors; |
|---|
| 78 | foreach my $committer ( @{ $committers || [] } ) { |
|---|
| 79 | my $pause_id = $mapping{$committer} || $committer; |
|---|
| 80 | |
|---|
| 81 | if ( my $author = $cpan->author($pause_id) ) { |
|---|
| 82 | $cpan_authors{ $pause_id } ||= $author->name; |
|---|
| 83 | } |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | my $target = "$FindBin::Bin/../lib/Acme/CPANAuthors/CodeRepos.pm"; |
|---|
| 87 | my $engine = Template->new; |
|---|
| 88 | my $template = get_template(); |
|---|
| 89 | |
|---|
| 90 | my $version = localtime(time)->strftime('0.%y%m%d'); |
|---|
| 91 | |
|---|
| 92 | $engine->process( |
|---|
| 93 | \$template, |
|---|
| 94 | { |
|---|
| 95 | authors => \%cpan_authors, |
|---|
| 96 | version => $version, |
|---|
| 97 | mapping => \%mapping |
|---|
| 98 | }, |
|---|
| 99 | $target, |
|---|
| 100 | ) or die $engine->error; |
|---|
| 101 | |
|---|
| 102 | sub get_template { return <<"TEMPLATE"; |
|---|
| 103 | package Acme::CPANAuthors::CodeRepos; |
|---|
| 104 | |
|---|
| 105 | use strict; |
|---|
| 106 | use warnings; |
|---|
| 107 | |
|---|
| 108 | our \$VERSION = '[% version %]'; |
|---|
| 109 | |
|---|
| 110 | # this is auto-generated by bin/update.pl |
|---|
| 111 | |
|---|
| 112 | use Acme::CPANAuthors::Register ( |
|---|
| 113 | [% FOREACH author IN authors -%] |
|---|
| 114 | [% author.key %] => '[% author.value %]', |
|---|
| 115 | [% END -%] |
|---|
| 116 | ); |
|---|
| 117 | |
|---|
| 118 | # people whose coderepos id doesn't match their pause id |
|---|
| 119 | sub _mapping {( |
|---|
| 120 | [% FOREACH committer IN mapping -%] |
|---|
| 121 | [% committer.key %] => '[% committer.value %]', |
|---|
| 122 | [% END -%] |
|---|
| 123 | )} |
|---|
| 124 | |
|---|
| 125 | 1; |
|---|
| 126 | |
|---|
| 127 | \__END__ |
|---|
| 128 | |
|---|
| 129 | \=head1 NAME |
|---|
| 130 | |
|---|
| 131 | Acme::CPANAuthors::CodeRepos - We are CPAN authors using CodeRepos |
|---|
| 132 | |
|---|
| 133 | \=head1 DESCRIPTION |
|---|
| 134 | |
|---|
| 135 | This class provides a hash of Pause ID/name of CPAN authors who use CodeRepos, our open source repository. |
|---|
| 136 | |
|---|
| 137 | \=head1 MAINTENANCE |
|---|
| 138 | |
|---|
| 139 | If you are a CodeRepos user and are not listed here, add your own id/name, or preferably update bin/update.pl in the repository (probably modify %mapping would suffice). |
|---|
| 140 | |
|---|
| 141 | \=head1 SVN REPOSITORY |
|---|
| 142 | |
|---|
| 143 | http://svn.coderepos.org/share/lang/perl/Acme-CPANAuthors-CodeRepos/ |
|---|
| 144 | |
|---|
| 145 | \=head1 AUTHOR |
|---|
| 146 | |
|---|
| 147 | Kenichi Ishigaki, E<lt>ishigaki\@cpan.orgE<gt>, and others in the CodeRepos repository. |
|---|
| 148 | |
|---|
| 149 | \=head1 COPYRIGHT AND LICENSE |
|---|
| 150 | |
|---|
| 151 | Copyright (C) 2008 by Kenichi Ishigaki. |
|---|
| 152 | |
|---|
| 153 | This program is free software; you can redistribute it and/or |
|---|
| 154 | modify it under the same terms as Perl itself. |
|---|
| 155 | |
|---|
| 156 | \=cut |
|---|
| 157 | TEMPLATE |
|---|
| 158 | } |
|---|