From 957885a38ebb8433ce37fda6df3e7b4566f173cb Mon Sep 17 00:00:00 2001 From: swag Date: Mon, 29 May 2023 00:35:33 -0400 Subject: [PATCH] Cleanup thread->by_page --- lib/PostText/Controller/Thread.pm | 27 +++++++++------------------ templates/thread/by_page.html.ep | 2 +- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/lib/PostText/Controller/Thread.pm b/lib/PostText/Controller/Thread.pm index aa87afd..f7ac201 100644 --- a/lib/PostText/Controller/Thread.pm +++ b/lib/PostText/Controller/Thread.pm @@ -76,24 +76,15 @@ sub by_page($self) { my $last_page = $self->thread->last_page; my $threads = $self->thread->by_page($this_page); - if (my $first_thread = $threads->[0]) { - $self->stash( - threads => $threads, - this_page => $this_page, - last_page => $last_page, - base_path => $base_path - ) - } - else { - $self->stash( - threads => [], - this_page => undef, - last_page => undef, - base_path => undef, - status => 404, - error => 'Page not found 🕵️' - ) - } + $self->stash( + threads => $threads, + this_page => $this_page, + last_page => $last_page, + base_path => $base_path + ); + + $self->stash(status => 404, error => 'Page not found 🕵️') + unless scalar @{$threads}; $self->render; } diff --git a/templates/thread/by_page.html.ep b/templates/thread/by_page.html.ep index 1d60e20..4e43fbe 100644 --- a/templates/thread/by_page.html.ep +++ b/templates/thread/by_page.html.ep @@ -1,7 +1,7 @@ % layout 'default'; % title 'Threads List';

<%= title %>

-<% if (my $first_thread = $threads->[0]) { =%> +<% if (scalar @{$threads}) { =%>
<% for my $thread (@{$threads}) { =%>