Skip to content

Commit

Permalink
Merge pull request #453 from CPAN-API/mickey/es2_types_cleanup
Browse files Browse the repository at this point in the history
WIP: cleaning up types usage
  • Loading branch information
mickeyn committed Apr 21, 2016
2 parents 51327c6 + 8a913f3 commit 1a7e606
Show file tree
Hide file tree
Showing 27 changed files with 126 additions and 122 deletions.
10 changes: 8 additions & 2 deletions cpanfile.snapshot
Expand Up @@ -23,7 +23,7 @@ DISTRIBUTIONS
requirements:
Carp 0
ExtUtils::MakeMaker 0
Mouse 0.40
Moose 0
perl 5.006_002
strict 0
warnings 0
Expand Down Expand Up @@ -571,6 +571,13 @@ DISTRIBUTIONS
perl 5.006
strict 0
warnings 0
Carp-Always-0.13
pathname: F/FE/FERREIRA/Carp-Always-0.13.tar.gz
provides:
Carp::Always 0.13
requirements:
Carp 0
ExtUtils::MakeMaker 0
Carp-Assert-0.21
pathname: N/NE/NEILB/Carp-Assert-0.21.tar.gz
provides:
Expand Down Expand Up @@ -2647,7 +2654,6 @@ DISTRIBUTIONS
requirements:
ExtUtils::MakeMaker 0
Mail::Address 0
Net::DNS 0
Scalar::Util 0
Test::More 0
perl 5.006
Expand Down
2 changes: 1 addition & 1 deletion lib/Catalyst/Plugin/OAuth2/Provider.pm
Expand Up @@ -64,7 +64,7 @@ sub authorize : Local {
my $uri = URI->new($redirect_uri);
my $code = $self->_build_code;
$uri->query_form( { code => $code, $state ? ( state => $state ) : () } );
$c->user->code($code);
$c->user->_set_code($code);
$c->user->put( { refresh => 1 } );
$c->res->redirect($uri);
}
Expand Down
8 changes: 4 additions & 4 deletions lib/Catalyst/Plugin/Session/Store/ElasticSearch.pm
Expand Up @@ -9,19 +9,19 @@ use MooseX::Types::ElasticSearch qw(:all);

has _session_es => (
required => 1,
is => 'rw',
is => 'ro',
coerce => 1,
isa => ES,
default => sub { shift->_session_plugin_config->{servers} || ':9200' }
);
has _session_es_index => (
required => 1,
is => 'rw',
is => 'ro',
default => sub { shift->_session_plugin_config->{index} || 'user' }
);
has _session_es_type => (
required => 1,
is => 'rw',
is => 'ro',
default => sub { shift->_session_plugin_config->{type} || 'session' }
);

Expand Down Expand Up @@ -85,7 +85,7 @@ sub delete_expired_sessions { }
Session
Session::Store::ElasticSearch
);
# defaults
MyApp->config(
'Plugin::Session' => {
Expand Down
20 changes: 7 additions & 13 deletions lib/MetaCPAN/Document/Author.pm
Expand Up @@ -11,10 +11,8 @@ use ElasticSearchX::Model::Document;
# load order not important
use Gravatar::URL ();
use MetaCPAN::Types qw(:all);
use MetaCPAN::Util;
use MooseX::Types::Common::String qw(NonEmptySimpleStr);
use MooseX::Types::Moose qw( Int Num Str ArrayRef HashRef Undef);
use MooseX::Types::Structured qw(Dict Tuple Optional);
use MetaCPAN::Util;

has name => (
is => 'ro',
Expand All @@ -28,7 +26,6 @@ has asciiname => (
required => 1,
index => 'analyzed',
isa => NonEmptySimpleStr,
required => 0,
);

has [qw(website email)] =>
Expand All @@ -40,7 +37,10 @@ has pauseid => (
id => 1,
);

has user => ( is => 'rw' );
has user => (
is => 'ro',
writer => '_set_user',
);

has gravatar_url => (
is => 'ro',
Expand All @@ -54,50 +54,44 @@ has profile => (
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 => (
is => 'ro',
isa => ArrayRef [ Dict [ name => NonEmptySimpleStr, id => Str ] ],
required => 0,
dynamic => 1,
);

has [qw(city region country)] =>
( is => 'ro', required => 0, isa => NonEmptySimpleStr );
( is => 'ro', isa => NonEmptySimpleStr );

has location => ( is => 'ro', isa => Location, coerce => 1, required => 0 );
has location => ( is => 'ro', isa => Location, coerce => 1 );

has extra => (
is => 'ro',
isa => HashRef,
source_only => 1,
dynamic => 1,
required => 0,
);

has updated => (
is => 'ro',
isa => 'DateTime',
required => 0,
);

sub _build_gravatar_url {
Expand Down
9 changes: 4 additions & 5 deletions lib/MetaCPAN/Document/Distribution.pm
Expand Up @@ -7,8 +7,7 @@ use namespace::autoclean;
use Moose;
use ElasticSearchX::Model::Document;

use MetaCPAN::Types qw(BugSummary);
use MooseX::Types::Moose qw(ArrayRef);
use MetaCPAN::Types qw( ArrayRef BugSummary );

has name => (
is => 'ro',
Expand All @@ -17,7 +16,7 @@ has name => (
);

has bugs => (
is => 'rw',
is => 'ro',
isa => BugSummary,
dynamic => 1,
);
Expand All @@ -34,7 +33,7 @@ sub set_first_release {
my $release = $self->releases->sort( ["date"] )->first;
return unless $release;
return $release if $release->first;
$release->first(1);
$release->_set_first(1);
$release->put;
return $release;
}
Expand All @@ -45,7 +44,7 @@ sub unset_first_release {
= $self->releases->filter( { term => { "release.first" => \1 }, } )
->size(200)->scroll;
while ( my $release = $releases->next ) {
$release->first(0);
$release->_set_first(0);
$release->update;
}
$self->index->refresh if $releases->total;
Expand Down
38 changes: 18 additions & 20 deletions lib/MetaCPAN/Document/File.pm
Expand Up @@ -12,7 +12,6 @@ use List::AllUtils qw( any );
use MetaCPAN::Document::Module;
use MetaCPAN::Types qw(:all);
use MetaCPAN::Util;
use MooseX::Types::Moose qw(ArrayRef);
use Plack::MIME;
use Pod::Text;
use Try::Tiny;
Expand Down Expand Up @@ -74,7 +73,7 @@ sub _build_abstract {
$abstract = MetaCPAN::Util::strip_pod($abstract);
}
if ($documentation) {
$self->documentation( MetaCPAN::Util::strip_pod($documentation) );
$self->_set_documentation( MetaCPAN::Util::strip_pod($documentation) );
}
return $abstract;
}
Expand All @@ -101,13 +100,13 @@ modules defined in that class (i.e. package declarations).
=cut

has module => (
required => 0,
is => 'rw',
is => 'ro',
isa => Module,
type => 'nested',
include_in_root => 1,
coerce => 1,
clearer => 'clear_module',
writer => '_set_module',
lazy => 1,
default => sub { [] },
);
Expand Down Expand Up @@ -222,9 +221,10 @@ See L</set_authorized>.

has authorized => (
required => 1,
is => 'rw',
is => 'ro',
isa => Bool,
default => 1,
writer => '_set_authorized',
);

=head2 maturity
Expand Down Expand Up @@ -267,13 +267,14 @@ set to C<undef>.
=cut

has documentation => (
is => 'rw',
is => 'ro',
lazy => 1,
builder => '_build_documentation',
index => 'analyzed',
predicate => 'has_documentation',
analyzer => [qw(standard camelcase lowercase edge edge_camelcase)],
clearer => 'clear_documentation',
writer => '_set_documentation',
);

sub _build_documentation {
Expand Down Expand Up @@ -311,7 +312,7 @@ not. See L</set_indexed> for a more verbose explanation.

has indexed => (
required => 1,
is => 'rw',
is => 'ro',
isa => Bool,
lazy => 1,
default => sub {
Expand All @@ -320,6 +321,7 @@ has indexed => (
return 0 if !$self->metadata->should_index_file( $self->path );
return 1;
},
writer => '_set_indexed',
);

=head2 level
Expand Down Expand Up @@ -513,7 +515,6 @@ C<gid>, C<size> and C<mtime>.
has stat => (
is => 'ro',
isa => Stat,
required => 0,
dynamic => 1,
);

Expand All @@ -524,8 +525,7 @@ Contains the raw version string.
=cut

has version => (
is => 'ro',
required => 0,
is => 'ro',
);

=head2 version_numified
Expand Down Expand Up @@ -622,7 +622,6 @@ has content => (
lazy => 1,
builder => '_build_content',
property => 0,
required => 0,
);

sub _build_content {
Expand All @@ -642,7 +641,6 @@ Callback that returns the content of the file as a ScalarRef.
has content_cb => (
is => 'ro',
property => 0,
required => 0,
default => sub {
sub { \'' }
},
Expand Down Expand Up @@ -718,7 +716,7 @@ sub add_module {
my ( $self, @modules ) = @_;
$_ = MetaCPAN::Document::Module->new($_)
for ( grep { ref $_ eq 'HASH' } @modules );
$self->module( [ @{ $self->module }, @modules ] );
$self->_set_module( [ @{ $self->module }, @modules ] );
}

=head2 is_in_other_files
Expand Down Expand Up @@ -797,26 +795,26 @@ sub set_indexed {
#files listed under 'other files' are not shown in a search
if ( $self->is_in_other_files() ) {
foreach my $mod ( @{ $self->module } ) {
$mod->indexed(0);
$mod->_set_indexed(0);
}
$self->indexed(0);
$self->_set_indexed(0);
return;
}

foreach my $mod ( @{ $self->module } ) {
if ( $mod->name !~ /^[A-Za-z]/ ) {
$mod->indexed(0);
$mod->_set_indexed(0);
next;
}
$mod->indexed(
$mod->_set_indexed(
$meta->should_index_package( $mod->name )
? $mod->hide_from_pause( ${ $self->content }, $self->name )
? 0
: 1
: 0
) unless ( $mod->indexed );
}
$self->indexed(
$self->_set_indexed(

# .pm file with no package declaration but pod should be indexed
!@{ $self->module } ||
Expand Down Expand Up @@ -856,11 +854,11 @@ sub set_authorized {
# only authorized perl distributions make it into the CPAN
return () if ( $self->distribution eq 'perl' );
foreach my $module ( @{ $self->module } ) {
$module->authorized(0)
$module->_set_authorized(0)
if ( $perms->{ $module->name } && !grep { $_ eq $self->author }
@{ $perms->{ $module->name } } );
}
$self->authorized(0)
$self->_set_authorized(0)
if ( $self->authorized
&& $self->documentation
&& $perms->{ $self->documentation }
Expand Down

0 comments on commit 1a7e606

Please sign in to comment.