Use subroutine for attribute rather than blessed hash reference value

This commit is contained in:
swagg boi 2022-11-03 14:03:48 -04:00
parent 912d38615c
commit 1e4ff30ff0
3 changed files with 11 additions and 12 deletions

View file

@ -32,7 +32,6 @@ Run the tests locally (against development environment):
## TODOs
1. Fix the `x_per_page` attributes (should use `has`)
1. s/Authen::Passphrase::BlowfishCrypt/Crypt::Passphrase/g
1. Need to pass `config` to the Moderator model for bcrypt cost
1. Re-write bcrypt command to use Authen::Passphrase::BlowfishCrypt

View file

@ -4,9 +4,11 @@ use Mojo::Base -base, -signatures;
has 'pg';
has per_page => sub { 5 };
sub by_page_for($self, $thread_id, $this_page = 1) {
my $date_format = $self->{'date_format'};
my $row_count = $self->{'remarks_per_page'};
my $row_count = $self->per_page;
my $offset = ($this_page - 1) * $row_count;
my @data = ($date_format, $thread_id, $row_count, $offset);
@ -24,7 +26,7 @@ sub by_page_for($self, $thread_id, $this_page = 1) {
}
sub per_page($self, $value = undef) {
$self->{'remarks_per_page'} = $value // $self->{'remarks_per_page'}
$self->per_page = $value // $self->per_page
}
sub create($self, $thread_id, $author, $body, $hidden = 0, $flagged = 0) {
@ -53,10 +55,10 @@ sub count_for($self, $thread_id) {
sub last_page_for($self, $thread_id) {
my $remark_count = $self->count_for($thread_id);
my $last_page = int($remark_count / $self->{'remarks_per_page'});
my $last_page = int($remark_count / $self->per_page);
# Add a page for 'remainder' posts
$last_page++ if $remark_count % $self->{'remarks_per_page'};
$last_page++ if $remark_count % $self->per_page;
return $last_page;
}

View file

@ -4,6 +4,8 @@ use Mojo::Base -base, -signatures;
has 'pg';
has per_page => sub { 5 };
sub create($self, $author, $title, $body, $hidden = 0, $flagged = 0) {
my @data = ($author, $title, $body, $hidden, $flagged);
@ -22,7 +24,7 @@ sub create($self, $author, $title, $body, $hidden = 0, $flagged = 0) {
sub by_page($self, $this_page = 1) {
my $date_format = $self->{'date_format'};
my $row_count = $self->{'threads_per_page'};
my $row_count = $self->per_page;
my $offset = ($this_page - 1) * $row_count;
$self->pg->db
@ -44,16 +46,12 @@ sub by_page($self, $this_page = 1) {
END_SQL
}
sub per_page($self, $value = undef) {
$self->{'threads_per_page'} = $value // $self->{'threads_per_page'}
}
sub last_page($self) {
my $thread_count = $self->count;
my $last_page = int($thread_count / $self->{'threads_per_page'});
my $last_page = int($thread_count / $self->per_page);
# Add a page for 'remainder' posts
$last_page++ if $thread_count % $self->{'threads_per_page'};
$last_page++ if $thread_count % $self->per_page;
$last_page;
}