Skip to content

Commit

Permalink
Adds permissions type for 06perms.
Browse files Browse the repository at this point in the history
  • Loading branch information
oalders committed Mar 16, 2014
1 parent 5d5281a commit 3aec64f
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 1 deletion.
1 change: 1 addition & 0 deletions cpanfile
Expand Up @@ -98,6 +98,7 @@ requires 'MooseX::Types::Path::Class';
requires 'MooseX::Types::Structured';
requires 'Mozilla::CA';
requires 'Net::Twitter';
requires 'PAUSE::Permissions';
requires 'Parse::CPAN::Packages::Fast', '0.04';
requires 'Parse::CSV';
requires 'Parse::PMFile', '0.05';
Expand Down
30 changes: 30 additions & 0 deletions lib/MetaCPAN/Document/Permissions.pm
@@ -0,0 +1,30 @@
package MetaCPAN::Document::Permissions;

use strict;
use warnings;

use Moose;
use ElasticSearchX::Model::Document;
use MetaCPAN::Util;
use MooseX::StrictConstructor;

has name => (
is => 'ro',
isa => 'Str',
required => 1,
);

has owner => (
is => 'ro',
isa => 'Str',
required => 0,
);

has co_maintainers => (
is => 'ro',
isa => 'ArrayRef',
required => 0,
);

__PACKAGE__->meta->make_immutable;
1;
2 changes: 1 addition & 1 deletion lib/MetaCPAN/Script/Mapping.pm
Expand Up @@ -81,5 +81,5 @@ sub map_perlmongers {

}

__PACKAGE__->meta->make_immutable;
__PACKAGE__->meta->make_immutable();
1;
70 changes: 70 additions & 0 deletions lib/MetaCPAN/Script/Permissions.pm
@@ -0,0 +1,70 @@
package MetaCPAN::Script::Permissions;

use strict;
use warnings;

use Moose;
with 'MooseX::Getopt', 'MetaCPAN::Role::Common';

use Log::Contextual qw( :log );
use PAUSE::Permissions;

#use MetaCPAN::Document::Permissions;

=head1 SYNOPSIS
Loads 06perms info into db. Does not require the presence of a local
CPAN/minicpan.
=cut

has author_fh => (
is => 'rw',
traits => ['NoGetopt'],
lazy => 1,
default => sub { shift->cpan . '/authors/00whois.xml' },
);

sub run {
my $self = shift;
$self->index_permissions;
$self->index->refresh;
}

sub index_permissions {
my $self = shift;

my $pp = PAUSE::Permissions->new;
my $type = $self->index->type('permissions');
my $bulk = $self->model->bulk( size => 100 );

my $iterator = $pp->module_iterator();
while ( my $mp = $iterator->next_module ) {
my $put = { name => $mp->name };
$put->{owner} = $mp->owner if $mp->owner;
$put->{co_maintainers} = $mp->co_maintainers if $mp->co_maintainers;
$bulk->put( $type->new_document($put) );
}

$self->index->refresh;
log_info {"done"};
}

#__PACKAGE__->meta->make_immutable;
1;

=pod
=head1 SYNOPSIS
Parse out CPAN author permissions.
my $perms = MetaCPAN::Script::Permissions->new;
my $result = $perms->index_permissions;
=head2 index_authors
Adds/updates all ownership and maintenance permissions in the CPAN index to
ElasticSearch.
=cut

0 comments on commit 3aec64f

Please sign in to comment.