diff --git a/lib/Pooru/API/V0/Model/Tags.pm b/lib/Pooru/API/V0/Model/Tags.pm index fcd720a..73e7ec9 100644 --- a/lib/Pooru/API/V0/Model/Tags.pm +++ b/lib/Pooru/API/V0/Model/Tags.pm @@ -1,6 +1,8 @@ package Pooru::API::V0::Model::Tags; use v5.40; +use Carp; + use Pooru::API::V0::Model::PagedResults; @@ -29,26 +31,18 @@ sub random_id ($self) sub get ($self, %search) { - my $key = exists($search{id}) ? - "id" : exists($search{display}) ? - "display" : "name"; - my $where_clause = where_in($key, $search{$key}->@*); - my @bind_values = $search{$key}->@*; + croak "Exactly one of 'id' or 'display' must be defined" if + !(defined($search{id}) ^^ defined($search{display})); - if (exists($search{kind_id})) { - $where_clause .= " AND kind_id = ?"; - push(@bind_values, $search{kind_id}); - } + my $key = defined($search{id}) ? "id" : "display"; + my $where_clause = where_in($key, $search{$key}->@*); my $sth = $self->{_dbh}->prepare(qq{ - SELECT * - FROM tag - WHERE $where_clause - LIMIT ? + SELECT * FROM tag WHERE $where_clause LIMIT ? }); return Pooru::API::V0::Model::Results->new($sth, $slice, - (@bind_values, $self->ROWS)); + ($search{$key}->@*, $self->ROWS)); } sub _ranked ($self, $stmt, @bind_values)