package MyLib; use Mojo::Base 'Mojolicious'; use Mojo::mysql; #my %connections; # This method will run once at server start sub startup { my $self = shift; # Router my $r = $self->routes; # Normal route to controller $r->get('/')->to( template => 'index' ); $r->get('/libmap'); #->to(controller => 'libmap'); $r->get('/invtot')->to( controller => 'invtot', title => 'Paper journals from the library', cb => sub { $self->connect_invtot() } ); if ( exists $ENV{PAR_TEMP} && $^O eq "MSWin32" ) { system qw(start http://localhost:3000/invtot); } $r->post('/invtot')->to( controller => 'Invtot', action => 'post' ); } sub connect_invtot { my $self = shift; #return if $connections{db1}; # Load configuration from hash returned by config file my $file; if ( $ENV{PAR_TEMP} ) { print $ENV{PAR_TEMP}, "\n"; $file = $ENV{PAR_TEMP} . "/inc/script/my_lib.conf"; } else { $file = 'my_lib.conf'; } my $config = $self->plugin( 'Config', { file => $file } ); # Configure the application $self->secrets( $config->{secrets} ); $self->log->debug("connecting..."); $self->helper(db1 => sub {state $db1 = Mojo::mysql->strict_mode('mysql://'. $config->{username} . ':'. $config->{password} . '@my.../dokpe_i01' )}); $self->db1->options({ 'pg_enable_utf8' => 1, AutoCommit => 1, PrintError => 0, RaiseError => 1 }); } 1;