Module::CPANTS::Site::Controller::Author - Catalyst component


Module-CPANTS-Site documentation Contained in the Module-CPANTS-Site distribution.

Index


Code Index:

NAME

Top

Module::CPANTS::Site::Controller::Author - Catalyst component

SYNOPSIS

Top

See Module::CPANTS::Site

DESCRIPTION

Top

Catalyst component.

METHODS

Top

AUTHOR

Top

Thomas Klausner, <domm@cpan.org>

LICENSE

Top

This library is free software . You can redistribute it and/or modify it under the same terms as perl itself.


Module-CPANTS-Site documentation Contained in the Module-CPANTS-Site distribution.

package Module::CPANTS::Site::Controller::Author;

use strict;
use warnings;

use base qw( Catalyst::Controller::BindLex );

sub search : Local {
    my ( $self, $c, $search ) = @_;
    my $term : Stashed = $search || $c->req->param( 'pauseid' );
 
    return unless $term;
    $term=~s/\s//g;

    $c->log->debug( "search author for $term" ) if $c->debug;
    
    my $list : Stashed = $c->model( 'DBIC::Author' )->search_like(
        {
            pauseid => uc( $term ) . '%',
        },
        {
            order_by => 'pauseid ASC',
            page     => $c->request->param( 'page' ) || 1,
            rows     => 20,
        }
    );

    if ($list == 1) {
        $c->res->redirect($c->uri_for('/author',$list->first->pauseid));
    }

}

sub view : Path {
    my ( $self, $c, $author ) = @_;

    unless( $author ) {
        $c->stash->{ template } = 'author/search';
        return;
    }

    my $item = $c->model( 'DBIC::Author' )->search(
        { pauseid => $author }
    )->first;

    if ( !$item ) {
        $c->stash->{ template } = 'author/search';
        $c->detach( 'search', [ $author ] );
    }

    $c->stash->{ item } = $item;
}

1;

__END__