commit a9dcb41ea356d0bc065500a0d262e865441941f5 Author: Catalin Constantin Mititiuc Date: Mon Jul 27 23:35:17 2026 -0700 Initial commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..9cbe1fb --- /dev/null +++ b/README.md @@ -0,0 +1,34 @@ +## create a mojolicious app + +### start a perl docker container + + $ docker run --rm --init -it -v $PWD:/opt/app -p 3000:3000 -e USER_NAME=$(whoami) perl:threaded-trixie bash + +### install mojolicious + + # curl -L https://cpanmin.us | perl - -M https://cpan.metacpan.org -n Mojolicious + +### create a user + + # useradd -ms /bin/bash $USER_NAME + +### switch to that user + + # su - $USER_NAME + +### switch to work dir + + $ cd /opt/app/ + +### generate app + + $ mojo generate app MojoApp + +### start app + + $ cd mojo_app/ + $ morbo ./scripts/mojo_app prefork + +### view page + +Visit localhost:3000 in browser diff --git a/lib/MojoApp.pm b/lib/MojoApp.pm new file mode 100644 index 0000000..3f38a44 --- /dev/null +++ b/lib/MojoApp.pm @@ -0,0 +1,20 @@ +package MojoApp; +use Mojo::Base 'Mojolicious', -signatures; + +# This method will run once at server start +sub startup ($self) { + + # Load configuration from config file + my $config = $self->plugin('NotYAMLConfig'); + + # Configure the application + $self->secrets($config->{secrets}); + + # Router + my $r = $self->routes; + + # Normal route to controller + $r->get('/')->to('Example#welcome'); +} + +1; diff --git a/lib/MojoApp/Controller/Example.pm b/lib/MojoApp/Controller/Example.pm new file mode 100644 index 0000000..b0ec283 --- /dev/null +++ b/lib/MojoApp/Controller/Example.pm @@ -0,0 +1,11 @@ +package MojoApp::Controller::Example; +use Mojo::Base 'Mojolicious::Controller', -signatures; + +# This action will render a template +sub welcome ($self) { + + # Render template "example/welcome.html.ep" with message + $self->render(msg => 'Welcome to the Mojolicious real-time web framework!'); +} + +1; diff --git a/mojo_app.yml b/mojo_app.yml new file mode 100644 index 0000000..cd59a6c --- /dev/null +++ b/mojo_app.yml @@ -0,0 +1,3 @@ +--- +secrets: + - usoPUHyzOvwMXLY3Gz-7NiLrqJ8uiyl-uBtIAlMaFc4UcIF7yzgf8y_mB6PXsPte69mO93R9n757Mt84MC3zhQL2AvQS71BPobLQ1FeGS_L8IBOCJ5aatrCInibVvrSAydRTEZzLSEYTFJUv87limhyfEY8OMDcnBRPb4C0Hb2A diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..e74bb5f --- /dev/null +++ b/public/index.html @@ -0,0 +1,11 @@ + + + + Welcome to the Mojolicious real-time web framework! + + +

Welcome to the Mojolicious real-time web framework!

+ This is the static document "public/index.html", + click here to get back to the start. + + diff --git a/script/mojo_app b/script/mojo_app new file mode 100755 index 0000000..b097e09 --- /dev/null +++ b/script/mojo_app @@ -0,0 +1,11 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +use Mojo::File qw(curfile); +use lib curfile->dirname->sibling('lib')->to_string; +use Mojolicious::Commands; + +# Start command line interface for application +Mojolicious::Commands->start_app('MojoApp'); diff --git a/t/basic.t b/t/basic.t new file mode 100644 index 0000000..c180e43 --- /dev/null +++ b/t/basic.t @@ -0,0 +1,9 @@ +use Mojo::Base -strict; + +use Test::More; +use Test::Mojo; + +my $t = Test::Mojo->new('MojoApp'); +$t->get_ok('/')->status_is(200)->content_like(qr/Mojolicious/i); + +done_testing(); diff --git a/templates/example/welcome.html.ep b/templates/example/welcome.html.ep new file mode 100644 index 0000000..0a67219 --- /dev/null +++ b/templates/example/welcome.html.ep @@ -0,0 +1,9 @@ +% layout 'default'; +% title 'Welcome'; +

<%= $msg %>

+

+ This page was generated from the template "templates/example/welcome.html.ep" + and the layout "templates/layouts/default.html.ep", + <%= link_to 'click here' => url_for %> to reload the page or + <%= link_to 'here' => '/index.html' %> to move forward to a static page. +

diff --git a/templates/layouts/default.html.ep b/templates/layouts/default.html.ep new file mode 100644 index 0000000..599c556 --- /dev/null +++ b/templates/layouts/default.html.ep @@ -0,0 +1,5 @@ + + + <%= title %> + <%= content %> +