Skip to content

Commit 19fa756

Browse files
committed
D::File includes now a list of modules, D::Module not indexed anymore
1 parent 6bc44eb commit 19fa756

File tree

15 files changed

+78
-195
lines changed

15 files changed

+78
-195
lines changed

lib/MetaCPAN/Document/File.pm

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use Plack::MIME;
1111
use List::MoreUtils qw(uniq);
1212
use MetaCPAN::Pod::Lines;
1313
use MetaCPAN::Types qw(:all);
14+
use MooseX::Types::Moose qw(ArrayRef);
1415

1516
Plack::MIME->add_type( ".t" => "text/x-script.perl" );
1617
Plack::MIME->add_type( ".pod" => "text/x-script.perl" );
@@ -19,10 +20,10 @@ Plack::MIME->add_type( ".xs" => "text/x-c" );
1920
has id => ( id => [qw(author release path)] );
2021

2122
has [qw(path author name distribution)] => ();
22-
has module => ( required => 0, is => 'rw' );
23+
has module => ( required => 0, is => 'ro', isa => Module, coerce => 1 );
2324
has documentation => ( required => 0, is => 'rw' );
2425
has release => ( parent => 1 );
25-
has url => ( lazy_build => 1, index => 'no' );
26+
has date => ( isa => 'DateTime' );
2627
has stat => ( isa => Stat, required => 0 );
2728
has sloc => ( isa => 'Int', lazy_build => 1 );
2829
has slop => ( isa => 'Int', is => 'rw', default => 0 );
@@ -49,6 +50,7 @@ sub is_perl_file {
4950
sub _build_indexed {
5051
my $self = shift;
5152
return 1 unless(my $pkg = $self->module);
53+
$pkg = $pkg->[0]->{name} || return 0;;
5254
my $content = ${$self->content};
5355
return $content =~ / # match a package declaration
5456
^[\h\{;]* # intro chars on a line
@@ -116,14 +118,6 @@ sub _build_path {
116118
return join( '/', $self->release->name, $self->name );
117119
}
118120

119-
sub _build_path_uri {
120-
URI::Escape::uri_escape( URI::Escape::uri_escape( shift->path ) );
121-
}
122-
123-
sub _build_url {
124-
'http://search.metacpan.org/source/' . shift->path;
125-
}
126-
127121
sub _build_pod_lines {
128122
my $self = shift;
129123
return [] unless ( $self->is_perl_file );

lib/MetaCPAN/Document/Mirror.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ has [qw(tz src http rsync ftp freq note dnsrr ccode aka_name A_or_CNAME)]
1111
=> ( required => 0 );
1212
has location => ( isa => Location, coerce => 1, required => 0 );
1313
has contact => ( isa => 'ArrayRef' );
14-
has [qw(inceptdate reitredate)] => ( isa => ESDateTime, required => 0, coerce => 1 );
14+
has [qw(inceptdate reitredate)] => ( isa => 'DateTime', required => 0, coerce => 1 );
1515

1616
__PACKAGE__->meta->make_immutable;

lib/MetaCPAN/Document/Module.pm

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,16 @@
11
package MetaCPAN::Document::Module;
22
use Moose;
33
use ElasticSearchX::Model::Document;
4-
54
use MetaCPAN::Util;
6-
use URI::Escape ();
75

8-
has id => ( id => [qw(author release name)] );
9-
has version_numified => ( isa => 'Num', lazy_build => 1 );
10-
has [qw(author distribution)] => ();
11-
has [qw(path file_id)] => ( lazy_build => 1 );
12-
has release => ( parent => 1 );
136
has name => ( index => 'analyzed' );
14-
has [qw(version)] => ( required => 0 );
15-
has date => ( isa => 'DateTime' );
16-
has abstract => ( index => 'analyzed', lazy_build => 1 );
17-
has status => ( default => 'cpan' );
18-
has maturity => ( default => 'released' );
19-
20-
has file => ( property => 0, required => 0 );
21-
22-
sub BUILD {
23-
my $self = shift;
24-
$self->file->module($self->name) if($self->file);
25-
return $self;
26-
}
7+
has version => ( required => 0 );
8+
has version_numified => ( isa => 'Num', lazy_build => 1 );
279

2810
sub _build_version_numified {
29-
return MetaCPAN::Util::numify_version( shift->version );
30-
}
31-
32-
sub _build_path {
33-
shift->file->path;
34-
}
35-
36-
sub _build_file_id {
37-
shift->file->id;
38-
}
39-
40-
sub _build_abstract {
41-
shift->file->abstract;
11+
my $self = shift;
12+
return 0 unless($self->version);
13+
return MetaCPAN::Util::numify_version( $self->version );
4214
}
4315

44-
__PACKAGE__->meta->make_immutable;
16+
__PACKAGE__->meta->make_immutable;

lib/MetaCPAN/Plack/Module.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ use base 'MetaCPAN::Plack::Base';
33
use strict;
44
use warnings;
55

6-
sub index { 'module' }
6+
sub index { 'file' }
77

88
sub query {
99
shift;
1010
return { query => { match_all => {} },
11-
filter => { term => { "name.raw" => shift } },
11+
filter => { term => { "file.module.name.raw" => shift } },
1212
size => 1,
1313
sort => { date => { reverse => \1 } }
1414
};

lib/MetaCPAN/Plack/Pod.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use MetaCPAN::Pod::XHTML;
99
sub handle {
1010
my ( $self, $env ) = @_;
1111
if ( $env->{REQUEST_URI} =~ m{\A/pod/([^\/]*?)\/?$} ) {
12-
$self->rewrite_request($env);
12+
use Devel::Dwarn; DwarnN($env);
1313
my $res =
1414
Plack::App::Proxy->new( backend => 'LWP', remote => "http://" . $self->remote . "/cpan" )
1515
->to_app->($env);

lib/MetaCPAN/Plack/Source.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ sub file_path {
4545
my ($tarball) = File::Find::Rule->new->file->name("$distvname.tar.gz")->in($author, $http);
4646
return unless ( $tarball && -e $tarball );
4747
my $arch = Archive::Tar::Wrapper->new();
48-
$distvname =~ s/-TRIAL$//;
48+
$distvname =~ s/-TRIAL$//; # FIXME: while(my $entry = $arch->list_next()) {
4949
my $logic_path = "$distvname/$file"; # path within unzipped archive
5050
$arch->read( $tarball, $logic_path ); # read only one file
5151
my $phys_path = $arch->locate( $logic_path );

lib/MetaCPAN/Pod/XHTML.pm

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
package MetaCPAN::Pod::XHTML;
22

33
use Moose;
4-
54
extends 'Pod::Simple::XHTML';
65

7-
use feature 'say';
8-
use Data::Dump qw( dump );
9-
use HTML::Entities;
10-
use IO::File;
11-
use Path::Class::File;
12-
136
sub start_L {
147
my ( $self, $flags ) = @_;
158
my ( $type, $to, $section ) = @{$flags}{ 'type', 'to', 'section' };

lib/MetaCPAN/Role/Common.pm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use ElasticSearch;
55
use Log::Contextual qw( set_logger :dlog );
66
use Log::Log4perl ':easy';
77
use MetaCPAN::Types qw(:all);
8+
use ElasticSearchX::Model::Document::Types qw(:all);
89
use MetaCPAN::Model;
910

1011
has 'cpan' => ( is => 'rw',
@@ -72,7 +73,7 @@ sub _build_cpan {
7273
}
7374

7475
sub remote {
75-
shift->es->transport->servers->[0];
76+
shift->es->transport->default_servers->[0];
7677
}
7778

7879
sub run { }

lib/MetaCPAN/Script/Latest.pm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ sub run {
3838
next if ( $row->{_source}->{status} eq 'latest' );
3939
log_info { "Upgrading $row->{_source}->{name} to latest" };
4040

41-
for (qw(file module dependency)) {
41+
for (qw(file dependency)) {
4242
log_debug { "Upgrading $_" };
4343
$self->reindex( $_, $row->{_id}, 'latest' );
4444
}
@@ -50,7 +50,7 @@ sub run {
5050
} elsif ( $row->{_source}->{status} eq 'latest' ) {
5151
log_info { "Downgrading $row->{_source}->{name} to cpan" };
5252

53-
for (qw(file module dependency)) {
53+
for (qw(file dependency)) {
5454
log_debug { "Downgrading $_" };
5555
$self->reindex( $_, $row->{_id}, 'cpan' );
5656
}
@@ -79,7 +79,7 @@ sub reindex {
7979
my $rs = $es->search(%$search);
8080
while ( my $row = shift @{ $rs->{hits}->{hits} } ) {
8181
log_debug { $status eq 'latest' ? "Upgrading " : "Downgrading ",
82-
$type, " ", $row->{_source}->{name} || $row->{_source}->{module} || '' };
82+
$type, " ", $row->{_source}->{name} || '' };
8383
$es->index( index => 'cpan',
8484
type => $type,
8585
id => $row->{_id},
@@ -106,5 +106,5 @@ __END__
106106
=head1 DESCRIPTION
107107
108108
After importing releases from cpan, this script will set the status
109-
to latest on the most recent release, its files, modules and dependencies.
109+
to latest on the most recent release, its files and dependencies.
110110
It also makes sure that there is only one latest release per distribution.

0 commit comments

Comments
 (0)