Skip to content

Commit

Permalink
Refactor the walker a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
rafl committed Mar 30, 2012
1 parent 7a10d31 commit 0a356e9
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 13 deletions.
8 changes: 8 additions & 0 deletions lib/Glob/Publisher.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package Glob::Publisher;

use Moose::Role;
use namespace::autoclean;

requires 'publish';

1;
21 changes: 21 additions & 0 deletions lib/Glob/Publisher/ZeroMQ.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package Glob::Publisher::ZeroMQ;

use Moose;
use JSON;
use namespace::autoclean;

has socket => (
isa => 'ZeroMQ::Socket',
required => 1,
handles => ['send'],
);

method publish ($o) {
$self->send(encode_json $o);
}

with 'Glob::Publisher';

__PACKAGE__->meta->make_immutable;

1;
4 changes: 4 additions & 0 deletions lib/Glob/Types.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use Path::Class;
use MooseX::Types::Moose(':all');
use MooseX::Types -declare => [qw/
GlobRoot
Publisher
IPCPath
/];

subtype GlobRoot,
Expand All @@ -17,4 +19,6 @@ subtype IPCPath,
as Str,
where { m#ipc://.+# };

role_type Publisher, { class => 'Glob::Publisher' };

1;
72 changes: 59 additions & 13 deletions lib/Glob/Walker.pm
Original file line number Diff line number Diff line change
@@ -1,31 +1,77 @@
package Glob::Walker;

sub run_walker {
my $dist_rule = Path::Class::Rule->new->file->iname(
use Moose;
use syntax 'method';
use aliased 'Path::Class::Rule';
use aliased 'CPAN::DistnameInfo';
use MooseX::Types::Path::Class 'Dir';
use MooseX::Types::Moose 'CodeRef';
use Glob::Types 'Publisher';
use namespace::autoclean;

has publisher => (
isa => Publisher,
required => 1,
handles => {
publish_dist => 'publish',
},
);

has skip_predicate => (
traits => ['Code'],
isa => CodeRef,
default => sub { sub { 0 } },
handles => {
should_skip => 'execute',
},
);

has dist_dir => (
is => 'ro',
isa => Dir,
required => 1,
handles => {
absolute_dist_file => 'file',
},
);

has dist_rule => (
is => 'ro',
isa => 'Path::Class::Rule',
required => 1,
builder => '_build_dist_rule',
);

method _build_dist_rule {
return Rule->new->file->iname(
'*.tar', qr'\.tar[._-]gz$', '*.tgz', '*.tar.bz2', '*.tbz', '*.tar.Z', '*.zip',
);
}

my $next = $dist_rule->iter($backpan->subdir('authors'), {
method dist_iterator {
return $self->dist_rule->iter($self->dist_dir, {
follow_symlinks => 0,
depthfirst => -1,
});
}

my $ctx = ZeroMQ::Context->new;
my $pushsock = $ctx->socket(ZMQ_PUSH);
$pushsock->bind($ipc_path);
$pushsock->setsockopt(ZMQ_HWM, 32);

method run_walker {
warn "walking dists";

my $next = $self->dist_iterator;

while (my $abs_file = $next->()) {
my $cpan_file = $abs_file->relative($backpan);
my $dist = CPAN::DistnameInfo->new($cpan_file);
my $cpan_file = $abs_file->relative( $self->dist_dir );
my $dist = DistnameInfo->new($cpan_file);
my $normalised_distname = join '/' => map { $dist->$_ } qw(cpanid filename);

next if exists $existing_refs{ $normalised_distname };
$pushsock->send(encode_json {
next if $self->should_skip($normalised_distname);

$self->publish_dist({
action => 'store_dist',
dist => {
cpan_file => $cpan_file->stringify,
local_file => $backpan->file($cpan_file)->stringify,
local_file => $self->absolute_dist_file($cpan_file)->stringify,
normalised_name => $normalised_distname,
},
});
Expand Down

0 comments on commit 0a356e9

Please sign in to comment.