Skip to content

Commit 6b3ab97

Browse files
committed
add ESModel Catalyst model class
Replaces the CPAN and User model classes. Removes magic namespace creation. Just returns the model object. Everything is trivially accessible from there.
1 parent ec333af commit 6b3ab97

File tree

23 files changed

+85
-95
lines changed

23 files changed

+85
-95
lines changed

lib/MetaCPAN/Server/Controller.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ sub apply_request_filter {
4141

4242
sub model {
4343
my ( $self, $c ) = @_;
44-
my $model = $c->model('CPAN')->type( $self->type );
44+
my $model = $c->model('ESModel')->doc( $self->type );
4545
$model = $model->fields( [ map { split(/,/) } $c->req->param('fields') ] )
4646
if $c->req->param('fields');
4747
if ( my ($size) = $c->req->param('size') ) {
@@ -55,7 +55,7 @@ sub model {
5555

5656
sub mapping : Path('_mapping') Args(0) {
5757
my ( $self, $c ) = @_;
58-
$c->stash( $c->model('CPAN')
58+
$c->stash( $c->model('ESModel')
5959
->es->indices->get_mapping( es_doc_path( $self->type ) ) );
6060
}
6161

lib/MetaCPAN/Server/Controller/Activity.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ sub get : Path('') : Args(0) {
1313
my ( $self, $c ) = @_;
1414

1515
$c->stash_or_detach(
16-
$c->model('CPAN::Release')->activity( $c->req->params ) );
16+
$c->model('ESModel')->doc('release')->activity( $c->req->params ) );
1717
}
1818

1919
__PACKAGE__->meta->make_immutable;

lib/MetaCPAN/Server/Controller/Author.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ sub get : Path('') : Args(1) {
1616
$c->cdn_max_age('1y');
1717
my $file = $self->model($c)->raw->get($id);
1818
$c->stash_or_detach(
19-
$c->model('CPAN::Release')->author_status( $id, $file ) );
19+
$c->model('ESModel')->doc('release')->author_status( $id, $file ) );
2020
}
2121

2222
# /author/search?q=QUERY

lib/MetaCPAN/Server/Controller/Changes.pm

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ sub get : Chained('index') : PathPart('') : Args(2) {
2525
$c->cdn_max_age('1y');
2626

2727
my $file
28-
= $c->model('CPAN::File')->find_changes_files( $author, $release );
28+
= $c->model('ESModel')->doc('file')
29+
->find_changes_files( $author, $release );
2930
$file or $c->detach( '/not_found', [] );
3031

3132
my $source = $c->model('Source')->path( @$file{qw(author release path)} )
@@ -52,7 +53,7 @@ sub get : Chained('index') : PathPart('') : Args(2) {
5253

5354
sub find : Chained('index') : PathPart('') : Args(1) {
5455
my ( $self, $c, $name ) = @_;
55-
my $release = eval { $c->model('CPAN::Release')->find($name); }
56+
my $release = eval { $c->model('ESModel')->doc('release')->find($name); }
5657
or $c->detach( '/not_found', [] );
5758

5859
$c->forward( 'get', [ @$release{qw( author name )} ] );
@@ -76,7 +77,8 @@ sub by_releases : Path('by_releases') : Args(0) {
7677
return;
7778
}
7879

79-
my $ret = $c->model('CPAN::Release')->by_author_and_names( \@releases );
80+
my $ret = $c->model('ESModel')->doc('release')
81+
->by_author_and_names( \@releases );
8082

8183
my @changes;
8284
for my $release ( @{ $ret->{releases} } ) {

lib/MetaCPAN/Server/Controller/Diff.pm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ sub release : Chained('index') : PathPart('release') : Args(1) {
3333

3434
my ( $latest, $previous );
3535
try {
36-
$latest = $c->model('CPAN::Release')->find($name);
37-
$previous = $c->model('CPAN::Release')->predecessor($name);
36+
$latest = $c->model('ESModel')->doc('release')->find($name);
37+
$previous = $c->model('ESModel')->doc('release')->predecessor($name);
3838
}
3939
catch {
4040
$c->detach('/not_found');
@@ -55,7 +55,7 @@ sub file : Chained('index') : PathPart('file') : Args(2) {
5555
= map { [ @$_{qw(author release path)} ] }
5656
map {
5757
my $file = $_;
58-
try { $c->model('CPAN::File')->raw->get($file)->{_source}; }
58+
try { $c->model('ESModel')->doc('file')->raw->get($file)->{_source}; }
5959
or $c->detach('/not_found');
6060
} ( $source, $target );
6161

lib/MetaCPAN/Server/Controller/Login.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ sub index : Path Args(0) {
3737

3838
sub update_user {
3939
my ( $self, $c, $type, $id, $data ) = @_;
40-
my $model = $c->model('User::Account');
40+
my $model = $c->model('ESModel')->doc('account');
4141
my $user = $model->find( { name => $type, key => $id } );
4242
unless ($user) {
4343
$user = $model->get( $c->user->id )

lib/MetaCPAN/Server/Controller/Login/PAUSE.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ sub index : Path Args(0) {
3737
elsif ( ( $id = $c->req->parameters->{id} )
3838
&& $c->req->parameters->{id} =~ /[a-zA-Z]+/ )
3939
{
40-
my $author = $c->model('CPAN::Author')->get( uc($id) );
40+
my $author = $c->model('ESModel')->doc('author')->get( uc($id) );
4141
$c->controller('OAuth2')->redirect( $c, error => "author_not_found" )
4242
unless ($author);
4343

lib/MetaCPAN/Server/Controller/OAuth2.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ sub access_token : Local {
7878
$self->bad_request( $c,
7979
invalid_request => 'code query parameter is required' )
8080
unless ($code);
81-
my $user = $c->model('User::Account')->find_code($code);
81+
my $user = $c->model('ESModel')->doc('account')->find_code($code);
8282
$self->bad_request( $c, access_denied => 'the code is invalid' )
8383
unless ($user);
8484

lib/MetaCPAN/Server/Controller/Package.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ with 'MetaCPAN::Server::Role::JSONP';
1111
sub modules : Path('modules') : Args(1) {
1212
my ( $self, $c, $dist ) = @_;
1313

14-
my $last = $c->model('CPAN::Release')->find($dist);
14+
my $last = $c->model('ESModel')->doc('release')->find($dist);
1515
$c->detach( '/not_found', ["Cannot find last release for $dist"] )
1616
unless $last;
1717
$c->stash_or_detach(

lib/MetaCPAN/Server/Controller/Pod.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ sub find : Path('') {
3636

3737
sub get : Path('') : Args(1) {
3838
my ( $self, $c, $module ) = @_;
39-
$module = $c->model('CPAN::File')->find_pod($module)
39+
$module = $c->model('ESModel')->doc('file')->find_pod($module)
4040
or $c->detach( '/not_found', [] );
4141
$c->forward( 'find', [ map { $module->$_ } qw(author release path) ] );
4242
}
4343

4444
sub find_dist_links {
4545
my ( $self, $c, $author, $release, $permalinks ) = @_;
46-
my @modules = $c->model('CPAN::File')
46+
my @modules = $c->model('ESModel')->doc('file')
4747
->documented_modules( { name => $release, author => $author } );
4848

4949
my $links = {};

0 commit comments

Comments
 (0)