]> ruin.nu Git - ndwebbie.git/blob - lib/NDWeb/Controller/Quotes.pm
Interface for searching for quotes
[ndwebbie.git] / lib / NDWeb / Controller / Quotes.pm
1 package NDWeb::Controller::Quotes;
2
3 use strict;
4 use warnings;
5 use parent 'Catalyst::Controller';
6
7 =head1 NAME
8
9 NDWeb::Controller::Quotes - Catalyst Controller
10
11 =head1 DESCRIPTION
12
13 Catalyst Controller.
14
15 =head1 METHODS
16
17 =cut
18
19
20 =head2 index
21
22 =cut
23
24 sub index :Path :Args(0) {
25         my ( $self, $c ) = @_;
26
27         $c->assert_user_roles(qw//);
28
29         my $search = $c->req->param('search');
30         $search =~  s/^\s+|\s+$//g if $search;
31         if ($search) {
32                 $c->stash(search => $search);
33                 my $dbh = $c->model;
34                 my $query = $dbh->prepare(q{
35 SELECT qid,quote FROM quotes
36 WHERE quote ILIKE '%' || $1 || '%' ORDER BY qid ASC
37                         });
38
39                 $query->execute($search);
40
41                 $c->stash(quotes => $query->fetchall_arrayref({}));
42         }
43 }
44
45 =head1 AUTHOR
46
47 Michael Andreen (harv@ruin.nu)
48
49 =head1 LICENSE
50
51 GPL 2.0, or later
52
53 =cut
54
55 1;