From 2f067bfabf27ee22f7ab94718157953951538b0b Mon Sep 17 00:00:00 2001 From: swag Date: Sat, 4 Dec 2021 02:26:25 -0500 Subject: [PATCH] Implement Test model --- guestbook-ng.pl | 13 ++++++++++++- lib/GuestbookNg/Model/Test.pm | 17 +++++++++++++++++ templates/index.html.ep | 1 + templates/test.html.ep | 13 +++++++++++++ 4 files changed, 43 insertions(+), 1 deletion(-) create mode 100755 lib/GuestbookNg/Model/Test.pm create mode 100644 templates/test.html.ep diff --git a/guestbook-ng.pl b/guestbook-ng.pl index a814223..427331f 100755 --- a/guestbook-ng.pl +++ b/guestbook-ng.pl @@ -4,9 +4,20 @@ # Daniel Bowling use Mojolicious::Lite -signatures; +use lib 'lib'; +use GuestbookNg::Model::Test; + +my $tm = GuestbookNg::Model::Test->new(); get '/' => sub ($c) { - $c->render(template => 'index'); + $c->render() +} => 'index'; + +any '/test' => sub ($c) { + my $method = $c->req->method; + my $string = $tm->test_model($c->param('string')); + + $c->render(method => $method, string => $string); }; app->start(); diff --git a/lib/GuestbookNg/Model/Test.pm b/lib/GuestbookNg/Model/Test.pm new file mode 100755 index 0000000..035745a --- /dev/null +++ b/lib/GuestbookNg/Model/Test.pm @@ -0,0 +1,17 @@ +#!/usr/bin/env perl + +package GuestbookNg::Model::Test; + +use strict; +use warnings; +use experimental qw{signatures}; + +sub new($class) { + bless {}, $class +} + +sub test_model($self, $string) { + "you've supplied: $string" +} + +1; diff --git a/templates/index.html.ep b/templates/index.html.ep index 01d2e39..435d350 100644 --- a/templates/index.html.ep +++ b/templates/index.html.ep @@ -1,3 +1,4 @@ % layout 'default'; % title 'Welcome';

Welcome to the Mojolicious real-time web framework!

+

Test my <%= link_to(Model => 'test') %>

diff --git a/templates/test.html.ep b/templates/test.html.ep new file mode 100644 index 0000000..55ebc72 --- /dev/null +++ b/templates/test.html.ep @@ -0,0 +1,13 @@ +% layout 'default'; +% title 'test'; +

test page

+<% if ($method eq 'POST') { %> +

<%= $string %>

+<% } else { %> +
+
+
+ +
+<% } %>