run.pl
lib.conf
templates
common_js.html.ep
invtot.html.ep
libmap.html.ep
layouts
default.html.ep
public
index.html
some .js files
lib
Lib.pm
Invtot.pm
Invtot
Controller
Invtot.pm
####
use strict;
use warnings;
use lib 'lib';
use Mojolicious::Commands;
Mojolicious::Commands->start_app('Lib')
####
package Lib;
use Mojo::Base 'Mojolicious';
# This method will run once at server start
sub startup {
my $self = shift;
# Load configuration from hash returned by config file
my $config = $self->plugin('Config');
# Configure the application
$self->secrets($config->{secrets});
# Router
my $r = $self->routes;
# Normal route to controller
$r->get('/')->to(controller => 'index');
$r->get('/libmap');
$r->get('/invtot');
$r->post('/invtot')->to(controller => 'Invtot', action=> 'post');
}
1;
####
package Invtot;
use Mojo::Base 'Mojolicious';
sub startup {
my $app = shift;
my $config = $app->config;
$app->log->debug("connecting...");
$app->plugin(
'Database',
{ dsn => 'dbi:mysql:host=mysql.unifr.ch:dbname=dokpe_i01',
username => $config->{username},
password => $config->{password},
options => {
'pg_enable_utf8' => 1,
AutoCommit => 1,
PrintError => 0,
RaiseError => 1
},
helper => 'db',
}
);
}
1;
####
package Invtot::Controller::Invtot;
use Mojo::Base 'Mojolicious::Controller';
sub post {
my $c = shift;
my $p = $c->req->body_params->to_hash;
#gets the form values
my $for_abo = $p->{'ccabo'} // '' eq 'ABO' ? 1 : 0;
my $reqVal = $p->{'ZLField'};
....
#build the sql string
$sql{$key} = format_sql( $reqVal, $p->{ZLMode}, $for_abo );
#get the values from the db
my $stm = $c->db->prepare_cached( $sql{$key} )
$stm->execute($toFind) or die $stm->errstr;
$c->stash( stm => $stm, for_abo => $for_abo );
}
#build the page with the db values
$c->render('invtot');
}
...
1;
####
Class "Lib::Invtot" is not a controller
Template "invtot/post.html.ep" not found