Implement Test model

This commit is contained in:
swag 2021-12-04 02:26:25 -05:00
parent 6fdbe8511c
commit 2f067bfabf
4 changed files with 43 additions and 1 deletions

View File

@ -4,9 +4,20 @@
# Daniel Bowling <swaggboi@slackware.uk>
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();

17
lib/GuestbookNg/Model/Test.pm Executable file
View File

@ -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;

View File

@ -1,3 +1,4 @@
% layout 'default';
% title 'Welcome';
<h1>Welcome to the Mojolicious real-time web framework!</h1>
<p>Test my <%= link_to(Model => 'test') %></p>

13
templates/test.html.ep Normal file
View File

@ -0,0 +1,13 @@
% layout 'default';
% title 'test';
<h1>test page</h1>
<% if ($method eq 'POST') { %>
<p><%= $string %></p>
<% } else { %>
<form action="/test" method="post">
<label>Give me string:<br>
<input type="text" name="string"></label><br>
<br>
<input type="submit" value="Submit">
</form>
<% } %>