Skip to content
Browse files

take advantage of new shiny ESX::Model API

  • Loading branch information...
1 parent 26752eb commit 11607a9db9852b0442e502d5232e2537d432904e @monken monken committed Aug 16, 2011
2 inc/monken/p5-elasticsearch-model
@@ -1 +1 @@
-Subproject commit f93678c241ac457148fc45fa2084e1636a403f53
+Subproject commit a72277dbb2ccfd3aaf659ef09952c6475184b73c
View
55 lib/MetaCPAN/Document/Author.pm
@@ -83,43 +83,64 @@ analyzed JSON string.
=cut
-has name => ( index => 'analyzed', isa => NonEmptySimpleStr );
-has asciiname =>
- ( index => 'analyzed', isa => NonEmptySimpleStr, required => 0 );
-has [qw(website email)] => ( isa => ArrayRef, coerce => 1 );
-has pauseid => ( id => 1 );
-has dir => ( lazy_build => 1 );
+has name => (
+ is => 'ro',
+ required => 1,
+ index => 'analyzed',
+ isa => NonEmptySimpleStr
+);
+has asciiname => (
+ is => 'ro',
+ required => 1,
+ index => 'analyzed',
+ isa => NonEmptySimpleStr,
+ required => 0
+);
+has [qw(website email)] =>
+ ( is => 'ro', required => 1, isa => ArrayRef, coerce => 1 );
+has pauseid => ( is => 'ro', required => 1, id => 1 );
+has dir => ( is => 'ro', required => 1, lazy_build => 1 );
has gravatar_url =>
- ( required => 0, lazy_build => 1, isa => NonEmptySimpleStr );
+ ( is => 'ro', lazy_build => 1, isa => NonEmptySimpleStr );
has profile => (
+ is => 'ro',
isa => Profile,
coerce => 1,
type => 'nested',
required => 0,
include_in_root => 1,
);
has blog => (
+ is => 'ro',
isa => Blog,
coerce => 1,
required => 0,
dynamic => 1,
);
has perlmongers => (
+ is => 'ro',
isa => PerlMongers,
coerce => 1,
required => 0,
dynamic => 1
);
has donation => (
- isa => ArrayRef [ Dict [ name => NonEmptySimpleStr, id => Str ] ],
+ is => 'ro',
+ isa => ArrayRef [ Dict [ name => NonEmptySimpleStr, id => Str ] ],
required => 0,
dynamic => 1
);
-has [qw(city region country)] => ( required => 0, isa => NonEmptySimpleStr );
-has location => ( isa => Location, coerce => 1, required => 0 );
-has extra =>
- ( isa => 'HashRef', source_only => 1, dynamic => 1, required => 0 );
-has updated => ( isa => 'DateTime', required => 0 );
+has [qw(city region country)] =>
+ ( is => 'ro', required => 0, isa => NonEmptySimpleStr );
+has location => ( is => 'ro', isa => Location, coerce => 1, required => 0 );
+has extra => (
+ is => 'ro',
+ isa => 'HashRef',
+ source_only => 1,
+ dynamic => 1,
+ required => 0
+);
+has updated => ( is => 'ro', isa => 'DateTime', required => 0 );
sub _build_dir {
my $pauseid = ref $_[0] ? shift->pauseid : shift;
@@ -128,6 +149,7 @@ sub _build_dir {
sub _build_gravatar_url {
my $self = shift;
+
# We do not use the author personal address ($self->email[0])
# because we want to show the author's CPAN identity.
# Using another e-mail than the CPAN one removes flexibility for
@@ -136,9 +158,10 @@ sub _build_gravatar_url {
# (by assigning an image to his author@cpan.org)
# and now by changing this URL from metacpa.org
return Gravatar::URL::gravatar_url(
- email => $self->{pauseid} . '@cpan.org',
- size => 130,
- https => 1,
+ email => $self->{pauseid} . '@cpan.org',
+ size => 130,
+ https => 1,
+
# Fallback to a generated image
default => 'identicon',
);
View
4 lib/MetaCPAN/Document/Author/Profile.pm
@@ -3,7 +3,7 @@ use Moose;
use ElasticSearchX::Model::Document;
use MetaCPAN::Util;
-has name => ( isa => 'Str' );
-has id => ( isa => 'Str', analyzer => ['simple'] );
+has name => ( is => 'ro', required => 1, isa => 'Str' );
+has id => ( is => 'ro', isa => 'Str', analyzer => ['simple'] );
__PACKAGE__->meta->make_immutable;
View
7 lib/MetaCPAN/Document/Dependency.pm
@@ -3,11 +3,12 @@ use Moose;
use ElasticSearchX::Model::Document;
use MetaCPAN::Util;
-has [qw(phase relationship module version)];
-has version_numified => ( isa => 'Num', lazy_build => 1 );
+has [qw(phase relationship module version)] => ( is => 'ro', required => 1 );
+has version_numified =>
+ ( is => 'ro', required => 1, isa => 'Num', lazy_build => 1 );
sub _build_version_numified {
- return MetaCPAN::Util::numify_version( shift->version )
+ return MetaCPAN::Util::numify_version( shift->version );
}
__PACKAGE__->meta->make_immutable;
View
11 lib/MetaCPAN/Document/Favorite.pm
@@ -5,14 +5,19 @@ use MetaCPAN::Types qw(:all);
use DateTime;
use MetaCPAN::Util;
-has id => ( id => [qw(user distribution)] );
+has id => ( is => 'ro', id => [qw(user distribution)] );
has release_id => ( is => 'ro', required => 1, parent => 1, lazy_build => 1 );
has [qw(author release user distribution)] => ( is => 'ro', required => 1 );
-has date => ( is => 'ro', isa => 'DateTime', default => sub { DateTime->now } );
+has date => (
+ is => 'ro',
+ required => 1,
+ isa => 'DateTime',
+ default => sub { DateTime->now }
+);
sub _build_release_id {
my $self = shift;
- return MetaCPAN::Util::digest($self->author, $self->release);
+ return MetaCPAN::Util::digest( $self->author, $self->release );
}
__PACKAGE__->meta->make_immutable;
View
274 lib/MetaCPAN/Document/File.pm
@@ -138,42 +138,70 @@ version could not be parsed.
=cut
-has id => ( id => [qw(author release path)] );
-
-has [qw(path author name release)];
-has distribution => ( analyzer => [qw(standard camelcase)] );
-has module => ( required => 0, is => 'rw', isa => Module, coerce => 1, clearer => 'clear_module' );
-has documentation => ( is => 'rw', lazy_build => 1, index => 'analyzed', predicate => 'has_documentation', analyzer => [qw(standard camelcase)] );
-has release_id => ( parent => 1 );
-has date => ( isa => 'DateTime' );
-has stat => ( isa => Stat, required => 0, dynamic => 1 );
-has sloc => ( isa => 'Int', lazy_build => 1 );
-has slop => ( isa => 'Int', is => 'rw', lazy_build => 1 );
-has pod_lines => ( isa => 'ArrayRef', type => 'integer', lazy_build => 1, index => 'no' );
+has id => ( is => 'ro', id => [qw(author release path)] );
+
+has [qw(path author name release)] => ( is => 'ro', required => 1 );
+has distribution =>
+ ( is => 'ro', required => 1, analyzer => [qw(standard camelcase)] );
+has module => (
+ required => 0,
+ is => 'rw',
+ isa => Module,
+ coerce => 1,
+ clearer => 'clear_module'
+);
+has documentation => (
+ required => 1,
+ is => 'rw',
+ lazy_build => 1,
+ index => 'analyzed',
+ predicate => 'has_documentation',
+ analyzer => [qw(standard camelcase)]
+);
+has release_id => ( is => 'ro', required => 1, parent => 1 );
+has date => ( is => 'ro', required => 1, isa => 'DateTime' );
+has stat => ( is => 'ro', isa => Stat, required => 0, dynamic => 1 );
+has sloc => ( is => 'ro', required => 1, isa => 'Int', lazy_build => 1 );
+has slop =>
+ ( is => 'ro', required => 1, isa => 'Int', is => 'rw', lazy_build => 1 );
+has pod_lines => (
+ is => 'ro',
+ required => 1,
+ isa => 'ArrayRef',
+ type => 'integer',
+ lazy_build => 1,
+ index => 'no'
+);
has pod => (
- isa => 'ScalarRef',
- lazy_build => 1,
- index => 'analyzed',
- not_analyzed => 0,
- store => 'no',
- term_vector => 'with_positions_offsets' );
-
-has mime => ( lazy_build => 1 );
-has abstract => ( lazy_build => 1, index => 'analyzed' );
-has description => ( lazy_build => 1, index => 'analyzed' );
-has status => ( default => 'cpan' );
-has authorized => ( is => 'ro', isa => 'Bool', default => 1 );
-has maturity => ( default => 'released' );
-has directory => ( isa => 'Bool', default => 0 );
-has level => ( isa => 'Int', lazy_build => 1 );
-has indexed => ( is => 'rw', isa => 'Bool', default => 1 );
-has version => ( required => 0 );
-has version_numified => ( isa => 'Num', lazy_build => 1, required => 1 );
+ is => 'ro',
+ required => 1,
+ isa => 'ScalarRef',
+ lazy_build => 1,
+ index => 'analyzed',
+ not_analyzed => 0,
+ store => 'no',
+ term_vector => 'with_positions_offsets'
+);
+
+has mime => ( is => 'ro', required => 1, lazy_build => 1 );
+has abstract =>
+ ( is => 'ro', required => 1, lazy_build => 1, index => 'analyzed' );
+has description =>
+ ( is => 'ro', required => 1, lazy_build => 1, index => 'analyzed' );
+has status => ( is => 'ro', required => 1, default => 'cpan' );
+has authorized => ( required => 1, is => 'ro', isa => 'Bool', default => 1 );
+has maturity => ( is => 'ro', required => 1, default => 'released' );
+has directory => ( is => 'ro', required => 1, isa => 'Bool', default => 0 );
+has level => ( is => 'ro', required => 1, isa => 'Int', lazy_build => 1 );
+has indexed => ( required => 1, is => 'rw', isa => 'Bool', default => 1 );
+has version => ( is => 'ro', required => 0 );
+has version_numified =>
+ ( is => 'ro', isa => 'Num', lazy_build => 1, required => 1 );
sub _build_version_numified {
my $self = shift;
- return 0 unless($self->version);
+ return 0 unless ( $self->version );
return MetaCPAN::Util::numify_version( $self->version );
}
@@ -192,8 +220,21 @@ Callback, that returns the content of the as ScalarRef.
=cut
-has content => ( isa => 'ScalarRef', lazy_build => 1, property => 0, required => 0 );
-has content_cb => ( property => 0, required => 0, default => sub{sub{\''}} );
+has content => (
+ is => 'ro',
+ isa => 'ScalarRef',
+ lazy_build => 1,
+ property => 0,
+ required => 0
+);
+has content_cb => (
+ is => 'ro',
+ property => 0,
+ required => 0,
+ default => sub {
+ sub { \'' }
+ }
+);
=head1 METHODS
@@ -211,9 +252,9 @@ Retruns true if the file extension is C<pod>.
sub is_perl_file {
my $self = shift;
- return 0 if($self->directory);
- return 1 if($self->name =~ /\.(pl|pm|pod|t)$/i);
- return 1 if($self->mime eq "text/x-script.perl");
+ return 0 if ( $self->directory );
+ return 1 if ( $self->name =~ /\.(pl|pm|pod|t)$/i );
+ return 1 if ( $self->mime eq "text/x-script.perl" );
return 0;
}
@@ -224,61 +265,67 @@ sub is_pod_file {
sub _build_documentation {
my $self = shift;
$self->_build_abstract;
- my $documentation = $self->documentation if($self->has_documentation);
- return undef unless(${$self->pod});
- my @indexed = grep { $_->indexed } @{$self->module || []};
- if($documentation && $self->is_pod_file) {
+ my $documentation = $self->documentation if ( $self->has_documentation );
+ return undef unless ( ${ $self->pod } );
+ my @indexed = grep { $_->indexed } @{ $self->module || [] };
+ if ( $documentation && $self->is_pod_file ) {
return $documentation;
- } elsif($documentation && grep {$_->name eq $documentation} @indexed) {
+ }
+ elsif ( $documentation && grep { $_->name eq $documentation } @indexed ) {
return $documentation;
- } elsif(@indexed) {
+ }
+ elsif (@indexed) {
return $indexed[0]->name;
- } else {
+ }
+ else {
return undef;
}
}
sub _build_level {
my $self = shift;
- my @level = split(/\//, $self->path);
+ my @level = split( /\//, $self->path );
return @level - 1;
}
sub _build_content {
- my $self = shift;
- my @content = split("\n", ${$self->content_cb->()} || '');
+ my $self = shift;
+ my @content = split( "\n", ${ $self->content_cb->() } || '' );
my $content = "";
- my $in_data = 0; # skip DATA section
- while(@content) {
+ my $in_data = 0; # skip DATA section
+ while (@content) {
my $line = shift @content;
- if($line =~ /^\s*__END__\s*$/) {
+ if ( $line =~ /^\s*__END__\s*$/ ) {
$in_data = 0;
- } elsif($line =~ /^\s*__DATA__\s*$/) {
+ }
+ elsif ( $line =~ /^\s*__DATA__\s*$/ ) {
$in_data++;
- } elsif($in_data && $line =~ /^=head1/) {
+ }
+ elsif ( $in_data && $line =~ /^=head1/ ) {
$in_data = 0;
}
- next if($in_data);
+ next if ($in_data);
$content .= $line . "\n";
}
return \$content;
}
sub _build_mime {
my $self = shift;
- if(!$self->directory && $self->name !~ /\./) {
- my $content = ${$self->content};
- return "text/x-script.perl" if($content =~ /^#!.*?perl/);
- } else {
+ if ( !$self->directory && $self->name !~ /\./ ) {
+ my $content = ${ $self->content };
+ return "text/x-script.perl" if ( $content =~ /^#!.*?perl/ );
+ }
+ else {
return Plack::MIME->mime_type( $self->name ) || 'text/plain';
}
}
sub _build_description {
my $self = shift;
return undef unless ( $self->is_perl_file );
- my $section =
- MetaCPAN::Util::extract_section( ${ $self->content }, 'DESCRIPTION' );
+ my $section = MetaCPAN::Util::extract_section( ${ $self->content },
+ 'DESCRIPTION' );
return undef unless ($section);
my $parser = Pod::Text->new;
my $text = "";
@@ -290,38 +337,36 @@ sub _build_description {
return $text;
}
-
sub _build_abstract {
- my $self = shift;
- return undef unless ( $self->is_perl_file );
- my $text = ${$self->content};
- my ( $documentation, $abstract );
- my $section = MetaCPAN::Util::extract_section($text, 'NAME');
- return undef unless($section);
- $section =~ s/^=\w+.*$//mg;
- $section =~ s/X<.*?>//mg;
- if ( $section =~ /^\s*(\S+)((\h+-+\h+(.+))|(\r?\n\h*\r?\n\h*(.+)))?/ms ) {
- chomp( $abstract = $4 || $6 ) if($4 || $6);
- my $name = $1;
- $documentation = $name if ( $name =~ /^[\w\.:\-_']+$/ );
- }
-
- if ($abstract) {
- $abstract =~ s/^=\w+.*$//xms;
- $abstract =~ s{\r?\n\h*\r?\n\h*.*$}{}xms;
- $abstract =~ s{\n}{ }gxms;
- $abstract =~ s{\s+$}{}gxms;
- $abstract =~ s{(\s)+}{$1}gxms;
- $abstract = MetaCPAN::Util::strip_pod($abstract);
- }
-
- if ($documentation) {
- $self->documentation(MetaCPAN::Util::strip_pod($documentation));
- }
- return $abstract;
+ my $self = shift;
+ return undef unless ( $self->is_perl_file );
+ my $text = ${ $self->content };
+ my ( $documentation, $abstract );
+ my $section = MetaCPAN::Util::extract_section( $text, 'NAME' );
+ return undef unless ($section);
+ $section =~ s/^=\w+.*$//mg;
+ $section =~ s/X<.*?>//mg;
+ if ( $section =~ /^\s*(\S+)((\h+-+\h+(.+))|(\r?\n\h*\r?\n\h*(.+)))?/ms ) {
+ chomp( $abstract = $4 || $6 ) if ( $4 || $6 );
+ my $name = $1;
+ $documentation = $name if ( $name =~ /^[\w\.:\-_']+$/ );
+ }
-}
+ if ($abstract) {
+ $abstract =~ s/^=\w+.*$//xms;
+ $abstract =~ s{\r?\n\h*\r?\n\h*.*$}{}xms;
+ $abstract =~ s{\n}{ }gxms;
+ $abstract =~ s{\s+$}{}gxms;
+ $abstract =~ s{(\s)+}{$1}gxms;
+ $abstract = MetaCPAN::Util::strip_pod($abstract);
+ }
+ if ($documentation) {
+ $self->documentation( MetaCPAN::Util::strip_pod($documentation) );
+ }
+ return $abstract;
+
+}
sub _build_path {
my $self = shift;
@@ -331,8 +376,8 @@ sub _build_path {
sub _build_pod_lines {
my $self = shift;
return [] unless ( $self->is_perl_file );
- my ($lines, $slop) = MetaCPAN::Util::pod_lines(${$self->content});
- $self->slop($slop || 0);
+ my ( $lines, $slop ) = MetaCPAN::Util::pod_lines( ${ $self->content } );
+ $self->slop( $slop || 0 );
return $lines;
}
@@ -347,14 +392,16 @@ sub _build_slop {
sub _build_sloc {
my $self = shift;
return 0 unless ( $self->is_perl_file );
- my @content = split("\n", ${$self->content});
+ my @content = split( "\n", ${ $self->content } );
my $pods = 0;
- map { splice(@content, $_->[0], $_->[1], map { '' } 1 .. $_->[1]) } @{$self->pod_lines};
+ map {
+ splice( @content, $_->[0], $_->[1], map {''} 1 .. $_->[1] )
+ } @{ $self->pod_lines };
my $sloc = 0;
- while(@content) {
+ while (@content) {
my $line = shift @content;
- last if($line =~ /^\s*__END__/s);
- $sloc++ if( $line !~ /^\s*#/ && $line =~ /\S/ );
+ last if ( $line =~ /^\s*__END__/s );
+ $sloc++ if ( $line !~ /^\s*#/ && $line =~ /\S/ );
}
return $sloc;
}
@@ -378,32 +425,23 @@ use Moose;
extends 'ElasticSearchX::Model::Document::Set';
sub find {
- my ($self, $module) = @_;
- return $self->query({
- size => 1,
- query => {
- filtered => {
- query => { match_all => {} },
- filter => {
- and => [
- { term => { 'documentation' => $module } },
- { term => { 'file.indexed' => \1, } },
- { term => { status => 'latest', } },
- { not => {
- filter =>
- { term => { 'file.authorized' => \0 } }
- }
- },
- ]
- }
- }
- },
- sort => [
- { 'date' => { order => "desc" } },
+ my ( $self, $module ) = @_;
+ return $self->filter(
+ { and => [
+ { term => { 'documentation' => $module } },
+ { term => { 'file.indexed' => \1, } },
+ { term => { status => 'latest', } },
+ { not =>
+ { filter => { term => { 'file.authorized' => \0 } } }
+ },
+ ]
+ }
+ )->sort(
+ [ { 'date' => { order => "desc" } },
'mime',
{ 'stat.mtime' => { order => 'desc' } }
]
- })->first;
+ )->first;
}
-__PACKAGE__->meta->make_immutable;
+__PACKAGE__->meta->make_immutable;
View
16 lib/MetaCPAN/Document/Mirror.pm
@@ -5,12 +5,14 @@ use ElasticSearchX::Model::Document::Types qw(:all);
use MetaCPAN::Util;
-has name => ( id => 1 );
-has [qw(org city region country continent)] => ( index => 'analyzed', required => 0 );
-has [qw(tz src http rsync ftp freq note dnsrr ccode aka_name A_or_CNAME)]
- => ( required => 0 );
-has location => ( isa => Location, coerce => 1, required => 0 );
-has contact => ( isa => 'ArrayRef' );
-has [qw(inceptdate reitredate)] => ( isa => 'DateTime', required => 0, coerce => 1 );
+has name => ( is => 'ro', required => 1, id => 1 );
+has [qw(org city region country continent)] =>
+ ( is => 'ro', index => 'analyzed' );
+has [qw(tz src http rsync ftp freq note dnsrr ccode aka_name A_or_CNAME)] =>
+ ( is => 'ro' );
+has location => ( is => 'ro', isa => Location, coerce => 1 );
+has contact => ( is => 'ro', required => 1, isa => 'ArrayRef' );
+has [qw(inceptdate reitredate)] =>
+ ( is => 'ro', isa => 'DateTime', coerce => 1 );
__PACKAGE__->meta->make_immutable;
View
22 lib/MetaCPAN/Document/Module.pm
@@ -57,20 +57,26 @@ not declared in one line, the module is considered not-indexed.
=cut
-has name => ( index => 'analyzed', analyzer => [qw(standard camelcase)] );
-has version => ( required => 0 );
-has version_numified => ( isa => 'Num', lazy_build => 1, required => 1 );
-has indexed => ( is => 'rw', isa => 'Bool', default => 0 );
-has authorized => ( is => 'ro', isa => 'Bool', default => 1 );
+has name => (
+ is => 'ro',
+ required => 1,
+ index => 'analyzed',
+ analyzer => [qw(standard camelcase)]
+);
+has version => ( is => 'ro' );
+has version_numified =>
+ ( is => 'ro', isa => 'Num', lazy_build => 1, required => 1 );
+has indexed => ( is => 'rw', required => 1, isa => 'Bool', default => 0 );
+has authorized => ( is => 'ro', required => 1, isa => 'Bool', default => 1 );
sub _build_version_numified {
my $self = shift;
- return 0 unless($self->version);
+ return 0 unless ( $self->version );
return MetaCPAN::Util::numify_version( $self->version );
}
sub hide_from_pause {
- my ($self, $content) = @_;
+ my ( $self, $content ) = @_;
my $pkg = $self->name;
return $content =~ / # match a package declaration
^[\h\{;]* # intro chars on a line
@@ -84,4 +90,4 @@ sub hide_from_pause {
/mx ? 0 : 1;
}
-__PACKAGE__->meta->make_immutable;
+__PACKAGE__->meta->make_immutable;
View
23 lib/MetaCPAN/Document/Rating.pm
@@ -5,20 +5,23 @@ use ElasticSearchX::Model::Document::Types qw(:all);
use MooseX::Types::Structured qw(Dict Tuple Optional);
use MooseX::Types::Moose qw(Int Num Bool Str ArrayRef HashRef Undef);
-has user => ( required => 1, is => 'ro', isa => Str );
-has details =>
- ( required => 0, is => 'ro', isa => Dict [ documentation => Str ] );
+has details => ( is => 'ro', isa => Dict [ documentation => Str ] );
has rating =>
- ( required => 1, is => 'ro', isa => Num, builder => '_build_rating' );
-has distribution => ( required => 1, is => 'ro', isa => Str );
-has release => ( required => 1, is => 'ro', isa => Str );
-has author => ( required => 1, is => 'ro', isa => Str );
-has date =>
- ( required => 1, isa => 'DateTime', default => sub { DateTime->now } );
+ ( required => 1, is => 'ro', isa => Num, builder => '_build_rating' );
+has [qw(distribution release author user)] =>
+ ( required => 1, is => 'ro', isa => Str );
+has date => (
+ required => 1,
+ is => 'ro',
+ isa => 'DateTime',
+ default => sub { DateTime->now }
+);
has helpful => (
required => 1,
+ is => 'ro',
isa => ArrayRef [ Dict [ user => Str, value => Bool ] ],
- default => sub { [] } );
+ default => sub { [] }
+);
sub _build_rating {
my $self = shift;
View
77 lib/MetaCPAN/Document/Release.pm
@@ -88,23 +88,24 @@ and C<mtime>.
=cut
-has id => ( id => [qw(author name)] );
-has [qw(license version author archive)] => ();
-has date => ( isa => 'DateTime' );
-has download_url => ( lazy_build => 1 );
-has name => ( index => 'analyzed' );
-has version_numified => ( isa => 'Num', lazy_build => 1 );
-has resources =>
- ( isa => Resources, required => 0, coerce => 1, dynamic => 1 );
-has abstract => ( index => 'analyzed', required => 0 );
-has distribution => ( analyzer => [qw(standard camelcase)] );
+has id => ( is => 'ro', id => [qw(author name)] );
+has [qw(license version author archive)] => ( is => 'ro', required => 1 );
+has date => ( is => 'ro', required => 1, isa => 'DateTime' );
+has download_url => ( is => 'ro', required => 1, lazy_build => 1 );
+has name => ( is => 'ro', required => 1, index => 'analyzed' );
+has version_numified =>
+ ( is => 'ro', required => 1, isa => 'Num', lazy_build => 1 );
+has resources => ( is => 'ro', isa => Resources, coerce => 1, dynamic => 1 );
+has abstract => ( is => 'ro', index => 'analyzed' );
+has distribution =>
+ ( is => 'ro', required => 1, analyzer => [qw(standard camelcase)] );
has dependency =>
( required => 0, is => 'rw', isa => Dependency, coerce => 1 );
-has status => ( default => 'cpan' );
-has maturity => ( default => 'released' );
-has stat => ( isa => Stat, required => 0, dynamic => 1 );
-has tests => ( isa => Tests, required => 0 );
-has authorized => ( is => 'ro', isa => 'Bool', default => 1 );
+has status => ( is => 'ro', required => 1, default => 'cpan' );
+has maturity => ( is => 'ro', required => 1, default => 'released' );
+has stat => ( is => 'ro', isa => Stat, dynamic => 1 );
+has tests => ( is => 'ro', isa => Tests );
+has authorized => ( is => 'ro', required => 1, isa => 'Bool', default => 1 );
sub _build_version_numified {
return MetaCPAN::Util::numify_version( shift->version );
@@ -126,46 +127,24 @@ extends 'ElasticSearchX::Model::Document::Set';
sub find {
my ( $self, $name ) = @_;
- return $self->query(
- { query => {
- filtered => {
- query => { match_all => {} },
- filter => {
- and => [
- { term => { 'release.distribution' => $name } },
- { term => { status => 'latest' } }
- ]
- }
- }
- },
- sort => [ { date => 'desc' } ],
- size => 1
+ return $self->filter(
+ { and => [
+ { term => { 'release.distribution' => $name } },
+ { term => { status => 'latest' } }
+ ]
}
- )->first;
+ )->sort( [ { date => 'desc' } ] )->first;
}
sub predecessor {
my ( $self, $name ) = @_;
- return $self->query(
- { query => {
- filtered => {
- query => { match_all => {} },
- filter => {
- and => [
- { term => { 'release.distribution' => $name } },
- { not => {
- filter =>
- { term => { status => 'latest' } }
- }
- },
- ]
- }
- }
- },
- sort => [ { date => 'desc' } ],
- size => 1,
+ return $self->filter(
+ { and => [
+ { term => { 'release.distribution' => $name } },
+ { not => { filter => { term => { status => 'latest' } } } },
+ ]
}
- )->first;
+ )->sort( [ { date => 'desc' } ] )->first;
}
__PACKAGE__->meta->make_immutable;
View
46 lib/MetaCPAN/Model/User/Account.pm
@@ -10,32 +10,35 @@ use MetaCPAN::Types qw(:all);
has id => ( id => 1, required => 0, is => 'rw' );
has identity => (
- isa => Identity,
- coerce => 1,
- traits => ['Array'],
- handles => { add_identity => 'push' },
- default => sub { [] }
+ is => 'ro',
+ required => 1,
+ isa => Identity,
+ coerce => 1,
+ traits => ['Array'],
+ handles => { add_identity => 'push' },
+ default => sub { [] }
);
-has code => ( is => 'rw', clearer => 'clear_token', required => 0 );
+has code => ( is => 'rw', clearer => 'clear_token' );
has access_token => (
- is => 'ro',
- isa => ArrayRef[Dict[token => Str, client => Str]],
- default => sub { [] },
+ is => 'ro',
+ required => 1,
+ isa => ArrayRef [ Dict [ token => Str, client => Str ] ],
+ default => sub { [] },
dynamic => 1,
traits => ['Array'],
handles => { add_access_token => 'push' }
);
sub has_identity {
- my ($self, $identity) = @_;
- return scalar grep { $_->name eq $identity } @{$self->identity};
+ my ( $self, $identity ) = @_;
+ return scalar grep { $_->name eq $identity } @{ $self->identity };
}
sub get_identities {
- my ($self, $identity) = @_;
- return grep { $_->name eq $identity } @{$self->identity};
+ my ( $self, $identity ) = @_;
+ return grep { $_->name eq $identity } @{ $self->identity };
}
__PACKAGE__->meta->make_immutable;
@@ -47,14 +50,11 @@ extends 'ElasticSearchX::Model::Document::Set';
sub find {
my ( $self, $p ) = @_;
- return $self->query(
- { query => { match_all => {} },
- filter => {
- and => [
- { term => { 'account.identity.name' => $p->{name} } },
- { term => { 'account.identity.key' => $p->{key} } }
- ]
- },
+ return $self->filter(
+ { and => [
+ { term => { 'account.identity.name' => $p->{name} } },
+ { term => { 'account.identity.key' => $p->{key} } }
+ ]
}
)->first;
}
@@ -66,8 +66,8 @@ sub find_code {
sub find_token {
my ( $self, $token ) = @_;
- return $self->filter( { term => { 'account.access_token.token' => $token } } )->first;
+ return $self->filter(
+ { term => { 'account.access_token.token' => $token } } )->first;
}
-
__PACKAGE__->meta->make_immutable;
View
7 lib/MetaCPAN/Model/User/Identity.pm
@@ -2,11 +2,10 @@ package MetaCPAN::Model::User::Identity;
use Moose;
use ElasticSearchX::Model::Document;
-has name => ();
+has name => ( is => 'ro', required => 1 );
-has key => ( required => 0 );
+has key => ( is => 'ro' );
-has extra =>
- ( isa => 'HashRef', source_only => 1, dynamic => 1, required => 0 );
+has extra => ( is => 'ro', isa => 'HashRef', source_only => 1, dynamic => 1 );
__PACKAGE__->meta->make_immutable;
View
6 lib/MetaCPAN/Model/User/Session.pm
@@ -3,11 +3,11 @@ use Moose;
use ElasticSearchX::Model::Document;
use DateTime;
-has id => ( id => 1 );
+has id => ( is => 'ro', id => 1 );
has date =>
- ( required => 1, isa => 'DateTime', default => sub { DateTime->now } );
+ ( is => 'ro', required => 1, isa => 'DateTime', default => sub { DateTime->now } );
-has account => ( parent => 1, is => 'rw' );
+has account => ( parent => 1, is => 'rw', required => 1 );
__PACKAGE__->meta->make_immutable;
View
2 lib/MetaCPAN/Server/Controller/Module.pm
@@ -11,7 +11,7 @@ sub get : Chained('index') : PathPart('') : Args(1) {
my ( $self, $c, $module ) = @_;
eval {
$c->stash(
- $c->model('CPAN::File')->inflate(0)->find($module)->{_source} );
+ $c->model('CPAN::File')->raw->find($module)->{_source} );
} or $c->detach('/not_found');
}

0 comments on commit 11607a9

Please sign in to comment.
Something went wrong with that request. Please try again.