Acme-CPANAuthors

 view release on metacpan or  search on metacpan

lib/Acme/CPANAuthors.pm  view on Meta::CPAN

  unless ( $id ) {
    my @ids = sort keys %{ $self->{authors} };
    return @ids;
  }
  else {
    return $self->{authors}{$id} ? 1 : 0;
  }
}

sub name {
  my ($self, $id) = @_;

  unless ( $id ) {
    return sort values %{ $self->{authors} };
  }
  else {
    return $self->{authors}{$id};
  }
}

sub categories {
  my $self = shift;
  return @{$self->{categories}};
}

sub distributions {
  my ($self, $id) = @_;

  return unless $id;

  my @packages;
  foreach my $package ( cpan_packages->distributions ) {
    if ( $package->cpanid eq $id ) {
      push @packages, $package;
    }
  }

  return @packages;
}

sub latest_distributions {
  my ($self, $id) = @_;

  return unless $id;

  my @packages;
  foreach my $package ( cpan_packages->latest_distributions ) {
    if ( $package->cpanid eq $id ) {
      push @packages, $package;
    }
  }

  return @packages;
}

sub avatar_url {
  my ($self, $id, %options) = @_;

  return unless $id;

  eval {require Gravatar::URL; 1}
      or warn($@), return;
  my $author = cpan_authors->author($id) or return;

  my $default = delete $options{default};
  return Gravatar::URL::gravatar_url(
    email => $author->email,
    %options,
    default => Gravatar::URL::gravatar_url(
      # Fall back to the CPAN address, as used by metacpan, which will in
      # turn fall back to a generated image.
      email => $id . '@cpan.org',
      %options,
      $default ? ( default => $default ) : (),
    ),
  );
}

sub kwalitee {
  my ($self, $id) = @_;

  return unless $id;

  require Acme::CPANAuthors::Utils::Kwalitee;
  return  Acme::CPANAuthors::Utils::Kwalitee->fetch($id);
}

sub look_for {
  my ($self, $id_or_name) = @_;

  return unless defined $id_or_name;
  unless (ref $id_or_name eq 'Regexp') {
    $id_or_name = qr/$id_or_name/i;
  }

  my @found;
  my @categories = ref $self ? @{ $self->{categories} } : ();
  @categories = _list_categories() unless @categories;
  foreach my $category ( @categories ) {
    my %authors = _get_authors_of($category);
    while ( my ($id, $name) = each %authors ) {
      if ($id =~ /$id_or_name/ or $name =~ /$id_or_name/) {
        push @found, {
          id       => $id,
          name     => $name,
          category => $category,
        };
      }
    }
  }
  return @found;
}

sub _list_categories {
  require Module::Find;
  return grep { $_ !~ /^(?:Register|Utils|Not|Search|Factory)$/ }
         map  { s/^Acme::CPANAuthors:://; $_ }
         Module::Find::findsubmod( 'Acme::CPANAuthors' );
}

sub _get_authors_of {
  my $category = shift;

  $category =~ s/^Acme::CPANAuthors:://;

  return if $category =~ /^(?:Register|Utils|Search)$/;

  my $package = "Acme::CPANAuthors\::$category";
  unless ($package->can('authors')) {
    eval "require $package";
    if ( $@ ) {
      carp "$category CPAN Authors are not registered yet: $@";
      return;
    }
    # some may actually lack 'authors' interface
    return unless $package->can('authors');
  }
  $package->authors;
}

1;

__END__

=head1 NAME

Acme::CPANAuthors - We are CPAN authors

=head1 SYNOPSIS

    use Acme::CPANAuthors;

    my $authors = Acme::CPANAuthors->new('Japanese');

    my $number   = $authors->count;
    my @ids      = $authors->id;
    my @distros  = $authors->distributions('ISHIGAKI');
    my $url      = $authors->avatar_url('ISHIGAKI');
    my $kwalitee = $authors->kwalitee('ISHIGAKI');
    my @info     = $authors->look_for('ishigaki');

  If you don't like this interface, just use a specific authors list.

    use Acme::CPANAuthors::Japanese;

    my %authors = Acme::CPANAuthors::Japanese->authors;

    # note that ->author is context sensitive. however, you can't
    # write this without dereference for older perls as "keys"
    # checks the type (actually, the number) of args.
    for my $name (keys %{ Acme::CPANAuthors::Japanese->authors }) {
      print Acme::CPANAuthors::Japanese->authors->{$name}, "\n";
    }

=head1 DESCRIPTION

Sometimes we just want to know something to confirm we're not
alone, or to see if we're doing right things, or to look for
someone we can rely on. This module provides you some basic
information on us.

=head1 WHY THIS MODULE?

We've been holding a Kwalitee competition for Japanese CPAN Authors
since 2006. Though Japanese names are rather easy to distinguish
from Westerner's names (as our names have lots of vowels), it's
tedious to look for Japanese authors every time we hold the contest.
That's why I wrote this module and started maintaining the Japanese
authors list with a script to look for candidates whose name looks
like Japanese by the help of L<Lingua::JA::Romaji::Valid> I coined.



( run in 2.676 seconds using v1.01-cache-2.11-cpan-98e64b0badf )