Skip to content

Commit

Permalink
perltidy
Browse files Browse the repository at this point in the history
  • Loading branch information
abh committed Aug 1, 2011
1 parent c180916 commit 73059d8
Showing 1 changed file with 52 additions and 50 deletions.
102 changes: 52 additions & 50 deletions lib/CPANRatings/Control/Show.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,67 +5,69 @@ use CPANRatings::Model::SearchCPAN qw();
use Combust::Constant qw(OK NOT_FOUND);

sub render {
my $self = shift;
my $self = shift;

my ($mode, $id, $format) = ($self->request->path =~ m!^/([ad]|user|dist)/([^/]+?)(?:\.(html|rss))?$!);
return 404 unless $mode and $id;
my ( $mode, $id, $format ) =
( $self->request->path =~ m!^/([ad]|user|dist)/([^/]+?)(?:\.(html|rss))?$! );
return 404 unless $mode and $id;

$format = $self->req_param('format') || $format || 'html';
$format = 'html' unless $format eq "rss";
$format = $self->req_param('format') || $format || 'html';
$format = 'html' unless $format eq "rss";

if ($mode eq 'a') {
my $user = $self->schema->user->find($id) or return NOT_FOUND;
return $self->redirect("/user/" . $user->username . ($format ne "html" ? ".$format" : ''));
}
elsif ($mode eq 'd') {
return $self->redirect("/dist/$id" . ($format ne "html" ? ".$format" : ''));
}
if ( $mode eq 'a' ) {
my $user = $self->schema->user->find($id) or return NOT_FOUND;
return $self->redirect(
"/user/" . $user->username . ( $format ne "html" ? ".$format" : '' ) );
}
elsif ( $mode eq 'd' ) {
return $self->redirect( "/dist/$id" . ( $format ne "html" ? ".$format" : '' ) );
}

my $mode_element = $id;

my $user;
if ( $mode eq 'user' ) {
($user) = $self->schema->user->search( { username => $id } ) or return NOT_FOUND;
$id = $user->id;
$mode_element = $user->username;
}

my $mode_element = $id;
$self->tpl_param( 'this_url' => join( "/", "", $mode, $mode_element ) );

my $user;
if ($mode eq 'user') {
($user) = $self->schema->user->search({username => $id}) or return NOT_FOUND;
$id = $user->id;
$mode_element = $user->username;
}
$mode = "distribution" if $mode eq "dist";

$self->tpl_param('this_url' => join("/", "", $mode, $mode_element));
my $template = 'display/list.html';

$mode = "distribution" if $mode eq "dist";
$self->tpl_param( 'mode' => $mode );
$self->tpl_param( 'header' => "$id reviews" ) if $mode eq "distribution";

my $template = 'display/list.html';
if ( $mode eq "user" ) {
$self->tpl_param( 'header' => "Reviews by " . $user->name );
}
else {
unless ( CPANRatings::Model::SearchCPAN->valid_distribution($id) ) {
return NOT_FOUND;
}
my ($first_review) =
$self->schema->review->search( { distribution => $id }, { rows => 1 } );
$self->tpl_param( 'distribution' => $first_review->distribution ) if $first_review;
$self->tpl_param( 'distribution' => $id ) unless $first_review;
}

my $reviews =
$self->schema->review->search( { $mode => $id }, { order_by => { -desc => 'updated' } } );

$self->tpl_param('mode' => $mode);
$self->tpl_param('header' => "$id reviews" ) if $mode eq "distribution";
$self->tpl_param( 'reviews' => $reviews );

if ($mode eq "user") {
$self->tpl_param('header' => "Reviews by " . $user->name);
}
else {
unless (CPANRatings::Model::SearchCPAN->valid_distribution($id)) {
return NOT_FOUND;
if ( $format eq "html" ) {
return OK, $self->evaluate_template($template), 'text/html';
}
my ($first_review) = $self->schema->review->search({distribution => $id}, { rows => 1 });
$self->tpl_param('distribution' => $first_review->distribution) if $first_review;
$self->tpl_param('distribution' => $id) unless $first_review;
}

my $reviews = $self->schema->review->search({$mode => $id},
{order_by => {-desc => 'updated'}}
);

$self->tpl_param('reviews' => $reviews);

if ($format eq "html") {
return OK, $self->evaluate_template($template), 'text/html';
}
elsif ($format eq "rss") {
my $output = $self->as_rss($reviews, $mode, $mode_element);
return OK, $output, 'application/rss+xml';
}

return OK, 'huh? unknown output format', 'text/plain';
elsif ( $format eq "rss" ) {
my $output = $self->as_rss( $reviews, $mode, $mode_element );
return OK, $output, 'application/rss+xml';
}

return OK, 'huh? unknown output format', 'text/plain';
}

1;

0 comments on commit 73059d8

Please sign in to comment.