From 94523eeba91d0a9b2ba283168eb5bc3657be4aa7 Mon Sep 17 00:00:00 2001 From: swag Date: Tue, 21 Dec 2021 23:57:48 -0500 Subject: [PATCH] Use heredoc for SQL queries --- lib/GuestbookNg/Model/Message.pm | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/GuestbookNg/Model/Message.pm b/lib/GuestbookNg/Model/Message.pm index cff8c0e..b9ccbc7 100644 --- a/lib/GuestbookNg/Model/Message.pm +++ b/lib/GuestbookNg/Model/Message.pm @@ -14,21 +14,24 @@ sub new($class, $pg, $pg_object) { } sub get_posts($self) { - $self->pg->db - ->query('SELECT to_char( - message_date, - \'Dy Mon DD HH:MI:SS AM TZ YYYY\' - ), - visitor_name, message - FROM messages - ORDER BY message_date DESC;')->arrays() + $self->pg->db->query(<<~'END_SQL')->arrays() + SELECT to_char(message_date, 'Dy Mon DD HH:MI:SS AM TZ YYYY'), + visitor_name, + message + FROM messages + ORDER BY message_date DESC; + END_SQL } sub create_post($self, $name, $message) { $self->pg->db->query( 'INSERT INTO messages (message_date, visitor_name, message) VALUES (NOW(), ?, ?);', $name, $message - ) + ); + $self->pg-db->query(<<~'END_SQL', $name, $message); + INSERT INTO messages (message_date, visitor_name, message) + VALUES (NOW(), ?, ?); + END_SQL } sub view_posts($self, $this_page, $last_page = undef, @posts) {