Mounting Mojolicious::Lite apps under Mount plugin?

82 views
Skip to first unread message

Charlie Brady

unread,
Dec 2, 2016, 7:03:52 PM12/2/16
to mojol...@googlegroups.com

From some short testing it is not possible. I'd like some confirmation of
that.

I have a significant collection of M::L programs, which are running under
apache as CGI scripts. I'd much prefer to combine them to into a single
app using Mojolicious::Plugin::Mount, but it looks each would need to be
converted to a full Mojolicious app for that to be possible. Is that
correct? Has anybody given any thought to what would need to be done to
the Mount plugin to support M::L apps?

Thanks

Stefan Adams

unread,
Dec 2, 2016, 8:40:22 PM12/2/16
to mojolicious
I mount M::L apps all the time! Only difference is my apps were never CGI. Not sure if that makes a difference?

Charlie Brady

unread,
Dec 5, 2016, 11:43:58 AM12/5/16
to mojolicious

On Fri, 2 Dec 2016, Stefan Adams wrote:

> I mount M::L apps all the time!

Thanks, that's encouraging!

> Only difference is my apps were never CGI. Not sure if that makes a
> difference?

It shouldn't. And I have problems in daemon mode anyway.

I have a M::L app which runs fine by itself:

root@10:/etc/e-smith/web/functions# ./syslog daemon
Server available at http://127.0.0.1:3000
^Croot@10:/etc/e-smith/web/functions#

If I try to embed it within a top-level index application, like so:

...
use Mojolicious::Plugin::Mount;

plugin Mount => {'/server-manager/cgi-bin/syslog' => './syslog'};
plugin Mount => {'/server-manager/cgi-bin/systeminformation' => './systeminformation'};
...

Then I get scoping and syntax errors when I try to run it - but not with a
test compile - the line numbers suggest problems with helper declarations:

root@10:/etc/e-smith/web/functions# perl -cw index.mount
index.mount syntax OK
root@10:/etc/e-smith/web/functions# ./index.mount daemon
"my" variable $prop masks earlier declaration in same statement at
/etc/e-smith/web/functions/syslog line 29.
"my" variable $prop masks earlier declaration in same scope at
/etc/e-smith/web/functions/syslog line 33.
"my" variable $prop masks earlier declaration in same statement at
/etc/e-smith/web/functions/syslog line 34.
"my" variable $prop masks earlier declaration in same scope at
/etc/e-smith/web/functions/syslog line 38.
"my" variable $prop masks earlier declaration in same statement at
/etc/e-smith/web/functions/syslog line 39.
"my" variable $prop masks earlier declaration in same scope at
/etc/e-smith/web/functions/syslog line 43.
"my" variable $prop masks earlier declaration in same statement at
/etc/e-smith/web/functions/syslog line 44.
String found where operator expected at /etc/e-smith/web/functions/syslog
line 47, near "get '/'"
(Do you need to predeclare get?)
"my" variable $self masks earlier declaration in same statement at
/etc/e-smith/web/functions/syslog line 50.
String found where operator expected at /etc/e-smith/web/functions/syslog
line 53, near "post '/'"
(Do you need to predeclare post?)
"my" variable $self masks earlier declaration in same scope at
/etc/e-smith/web/functions/syslog line 55.
String found where operator expected at /etc/e-smith/web/functions/syslog
line 94, near "get '/createdest'"
(Do you need to predeclare get?)
"my" variable $self masks earlier declaration in same scope at
/etc/e-smith/web/functions/syslog line 96.
"my" variable $self masks earlier declaration in same statement at
/etc/e-smith/web/functions/syslog line 97.
"my" variable $self masks earlier declaration in same statement at
/etc/e-smith/web/functions/syslog line 97.
"my" variable $self masks earlier declaration in same scope at
/etc/e-smith/web/functions/syslog line 98.
"my" variable $self masks earlier declaration in same statement at
/etc/e-smith/web/functions/syslog line 98.
"my" variable $self masks earlier declaration in same scope at
/etc/e-smith/web/functions/syslog line 99.
"my" variable $self masks earlier declaration in same statement at
/etc/e-smith/web/functions/syslog line 99.
"my" variable $self masks earlier declaration in same scope at
/etc/e-smith/web/functions/syslog line 100.
String found where operator expected at /etc/e-smith/web/functions/syslog
line 103, near "post '/createdest'"
(Do you need to predeclare post?)
"my" variable $self masks earlier declaration in same scope at
/etc/e-smith/web/functions/syslog line 105.
"my" variable $self masks earlier declaration in same statement at
/etc/e-smith/web/functions/syslog line 106.
"my" variable $self masks earlier declaration in same statement at
/etc/e-smith/web/functions/syslog line 106.
"my" variable $prop masks earlier declaration in same scope at
/etc/e-smith/web/functions/syslog line 142.
"my" variable $syslogdb masks earlier declaration in same scope at
/etc/e-smith/web/functions/syslog line 143.
String found where operator expected at /etc/e-smith/web/functions/syslog
line 174, near "get '/remove/:facility/:protocol'"
(Do you need to predeclare get?)
"my" variable $self masks earlier declaration in same scope at
/etc/e-smith/web/functions/syslog line 176.
"my" variable $facility masks earlier declaration in same scope at
/etc/e-smith/web/functions/syslog line 177.
"my" variable $protocol masks earlier declaration in same scope at
/etc/e-smith/web/functions/syslog line 178.
"my" variable $syslogdb masks earlier declaration in same scope at
/etc/e-smith/web/functions/syslog line 180.
"my" variable $destination_host masks earlier declaration in same scope at
/etc/e-smith/web/functions/syslog line 181.
Can't load application from file "/etc/e-smith/web/functions/syslog":
syntax error at /etc/e-smith/web/functions/syslog line 20, near "helper
db"
syntax error at /etc/e-smith/web/functions/syslog line 30, near "}"
syntax error at /etc/e-smith/web/functions/syslog line 35, near "}"
syntax error at /etc/e-smith/web/functions/syslog line 40, near "}"
syntax error at /etc/e-smith/web/functions/syslog line 45, near "}"
syntax error at /etc/e-smith/web/functions/syslog line 51, near "}"
syntax error at /etc/e-smith/web/functions/syslog line 92, near "}"
syntax error at /etc/e-smith/web/functions/syslog line 101, near "}"
syntax error at /etc/e-smith/web/functions/syslog line 172, near "}"
syntax error at /etc/e-smith/web/functions/syslog line 192, near "}"
/etc/e-smith/web/functions/syslog has too many errors.
Compilation failed in require at (eval 78) line 1.
root@10:/etc/e-smith/web/functions#

Charlie Brady

unread,
Dec 5, 2016, 11:47:55 AM12/5/16
to mojolicious

On Mon, 5 Dec 2016, Charlie Brady wrote:

> If I try to embed it within a top-level index application, like so:
>
> ...
> use Mojolicious::Plugin::Mount;
>
> plugin Mount => {'/server-manager/cgi-bin/syslog' => './syslog'};
> plugin Mount => {'/server-manager/cgi-bin/systeminformation' => './systeminformation'};
> ...
>
> Then I get scoping and syntax errors when I try to run it - but not with a
> test compile - the line numbers suggest problems with helper declarations:

In case it is relevant:

root@10:/etc/e-smith/web/functions# mojo version
CORE
Perl (v5.22.0, linux)
Mojolicious (7.10, Doughnut)

OPTIONAL
EV 4.0+ (n/a)
IO::Socket::Socks 0.64+ (n/a)
IO::Socket::SSL 1.94+ (1.997)
Net::DNS::Native 0.15+ (0.15)

You might want to update your Mojolicious to 7.11!
root@10:/etc/e-smith/web/functions#

Stefan Adams

unread,
Dec 5, 2016, 12:04:08 PM12/5/16
to mojolicious

On Mon, Dec 5, 2016 at 10:43 AM, Charlie Brady <charli...@budge.apana.org.au> wrote:
use Mojolicious::Plugin::Mount;

You shouldn't need this.
 
plugin Mount => {'/server-manager/cgi-bin/syslog' => './syslog'};
plugin Mount => {'/server-manager/cgi-bin/systeminformation' => './systeminformation'};

It looks like all of the "syntax errors" are in syslog.  What if you comment that one out and let it just mount systeminformation?

It sure is weird that syslog runs fine by itself but causes syntax errors when mounted.  I can't imagine how that could be!  "my variable masks earlier declaration"...  Is it getting mounted more than once?  It has syntax errors with the Mojolicious methods get and post and helper...

Surely there's just something tiny that's being overlooked!  :O

Charlie Brady

unread,
Dec 5, 2016, 2:33:17 PM12/5/16
to mojolicious


On Mon, 5 Dec 2016, Stefan Adams wrote:

> On Mon, Dec 5, 2016 at 10:43 AM, Charlie Brady <
> charli...@budge.apana.org.au> wrote:

> > plugin Mount => {'/server-manager/cgi-bin/syslog' => './syslog'};
> > plugin Mount => {'/server-manager/cgi-bin/systeminformation' =>
> > './systeminformation'};
> >
>
> It looks like all of the "syntax errors" are in syslog. What if you
> comment that one out and let it just mount systeminformation?

I get a similar looking error:

root@10:/etc/e-smith/web/functions# ./index.mount daemon
String found where operator expected at
/etc/e-smith/web/functions/systeminformation line 145, near "get '/'"
(Do you need to predeclare get?)
Can't load application from file
"/etc/e-smith/web/functions/systeminformation": syntax error at
/etc/e-smith/web/functions/systeminformation line 145, near "get '/'"
syntax error at /etc/e-smith/web/functions/systeminformation line 264,
near "}"
Compilation failed in require at (eval 79) line 1.
root@10:/etc/e-smith/web/functions#

> It sure is weird that syslog runs fine by itself but causes syntax errors
> when mounted. I can't imagine how that could be!

I'm in the same boat, which is why I asked for help.

> "my variable masks earlier declaration"... Is it getting mounted more
> than once?

Not as far as I know. However there might be re-declaration of the same
helpers.

> It has syntax errors with the Mojolicious methods get and
> post and helper...

Which is why I suspected it was M::L related.

> Surely there's just something tiny that's being overlooked! :O

I'm hopeful that is the case.

Warren Humphreys

unread,
Dec 5, 2016, 2:59:44 PM12/5/16
to mojol...@googlegroups.com
Is Jan Henning Thorsen’s Toadfarm an option instead?


Described as Mojolicious::Plugin::Mount on steroids.

Charlie Brady

unread,
Dec 5, 2016, 4:29:53 PM12/5/16
to mojol...@googlegroups.com


On Mon, 5 Dec 2016, Warren Humphreys wrote:

> Is Jan Henning Thorsen's Toadfarm an option instead?

Thanks for the suggestion. Doesn't seem to make any difference to the
compile errors.

sri

unread,
Dec 5, 2016, 4:55:53 PM12/5/16
to Mojolicious, charli...@budge.apana.org.au
Make a minimal test case demonstrating the problem.

--
sebastian

Charlie Brady

unread,
Dec 5, 2016, 5:05:33 PM12/5/16
to sri, Mojolicious

On Mon, 5 Dec 2016, sri wrote:

> Make a minimal test case demonstrating the problem.

I'll do my best.

Charlie Brady

unread,
Dec 5, 2016, 6:25:24 PM12/5/16
to mojolicious

On Mon, 5 Dec 2016, Stefan Adams wrote:

> Surely there's just something tiny that's being overlooked! :O

Looks to be related to the class name which specializes M::L.

root@10:/etc/e-smith/web/functions# cat My/ML.pm
use Mojolicious::Lite;

1;
root@10:/etc/e-smith/web/functions# diff -u test.mount test2.mount
--- test.mount 2016-12-05 23:17:58.485718918 +0000
+++ test2.mount 2016-12-05 23:18:17.425916545 +0000
@@ -1,6 +1,6 @@
#!/usr/bin/perl

-use My::ML;
+use Mitel::MSL::Mojolicious::ServerManagerX;

app->defaults(expires => 1);
push @{app->static->paths}, '/etc/e-smith/web/common';
root@10:/etc/e-smith/web/functions# diff -u My/ML.pm
/usr/lib/perl/vendor_perl/5.22.0/Mitel/MSL/Mojolicious/ServerManagerX.pm
root@10:/etc/e-smith/web/functions# diff -u test.mount test2.mount---
test.mount 2016-12-05 23:17:58.485718918 +0000
+++ test2.mount 2016-12-05 23:18:17.425916545 +0000
@@ -1,6 +1,6 @@
#!/usr/bin/perl

-use My::ML;
+use Mitel::MSL::Mojolicious::ServerManagerX;

app->defaults(expires => 1);
push @{app->static->paths}, '/etc/e-smith/web/common';
root@10:/etc/e-smith/web/functions# perl -I. test.mount > /dev/null[Mon
Dec 5 23:19:37 2016] [debug] Your secret passphrase needs to be changed
root@10:/etc/e-smith/web/functions# perl -I. test2.mount >/dev/nullString
found where operator expected at /etc/e-smith/web/functions/mini.syslog
line 11, near "get '/'"
(Do you need to predeclare get?)
Can't load application from file "/etc/e-smith/web/functions/mini.syslog":
syntax error at /etc/e-smith/web/functions/mini.syslog line 6, near
"helper syslog_enabled"
syntax error at /etc/e-smith/web/functions/mini.syslog line 9, near "}"
syntax error at /etc/e-smith/web/functions/mini.syslog line 15, near "}"
Compilation failed in require at (eval 75) line 1.
root@10:/etc/e-smith/web/functions#

Charlie Brady

unread,
Dec 6, 2016, 12:04:00 PM12/6/16
to sri, Mojolicious

On Mon, 5 Dec 2016, sri wrote:

> Make a minimal test case demonstrating the problem.

Problem occurs when I 'use' a module, which 'use's M::L, without declaring
a namespace.

[root@dsfdsfd functions]# cat test.mount
#!/usr/bin/perl

use Mojolicious::Lite;

plugin Mount => {'/one' => './one'};
plugin Mount => {'/two' => './two'};

app->start;

[root@dsfdsfd functions]# cat My/ML.pm
use Mojolicious::Lite;
1;
[root@dsfdsfd functions]# cat one
#!/usr/bin/perl

use My::ML;

get '/' => sub { shift->render(text => 'one') };

app->start;
[root@dsfdsfd functions]# cat two
#!/usr/bin/perl

use My::ML;

get '/' => sub { shift->render(text => 'two') };

app->start;
[root@dsfdsfd functions]#
[root@dsfdsfd functions]# perl -I. test.mount
[Tue Dec 6 11:33:34 2016] [debug] Your secret passphrase needs to be
changed
String found where operator expected at /etc/e-smith/web/functions/two
line 5, near "get '/'"
(Do you need to predeclare get?)
Can't load application from file "/etc/e-smith/web/functions/two": syntax
error at /etc/e-smith/web/functions/two line 5, near "get '/'"
Compilation failed in require at (eval 81) line 1.
[root@dsfdsfd functions]#

The reason for not using a namespace is that I want to use 'app' to set
some defaults. For instance, I want to do these:

app->defaults(layout => 'server_manager');
app->log->level('warn');
push @{app->renderer->paths}, '/etc/e-smith/web/panels/manager/templates';

in My::ML. I tried these, with none of them working:

Mojolicious::Lite->app
Mojolicious::Lite:app
caller->app

Perhaps I should be defining a 'ServerManager' plugin, and setting the
common defaults inside the register() method there.

Charlie Brady

unread,
Dec 6, 2016, 12:19:39 PM12/6/16
to Mojolicious, sri

On Tue, 6 Dec 2016, Charlie Brady wrote:

> The reason for not using a namespace is that I want to use 'app' to set
> some defaults. For instance, I want to do these:
>
> app->defaults(layout => 'server_manager');
> app->log->level('warn');
> push @{app->renderer->paths}, '/etc/e-smith/web/panels/manager/templates';
...
> Perhaps I should be defining a 'ServerManager' plugin, and setting the
> common defaults inside the register() method there.

That doesn't seem to work either:

[root@dsfdsfd functions]# cat My/ML.pm
package My::ML;
use Mojolicious::Lite;

plugin 'AppDefault';

1;
[root@dsfdsfd functions]# cat Mojolicious/Plugin/AppDefault.pm
package Mojolicious::Plugin::AppDefault;
use Mojo::Base 'Mojolicious::Plugin';

sub register {
my ($self, $app, $conf) = @_;
$app->log->level('warn');
push @{$app->renderer->paths},
'/etc/e-smith/web/panels/manager/templates';
}
1;
[root@dsfdsfd functions]# perl -I. test.mount
String found where operator expected at /etc/e-smith/web/functions/one
line 9, near "get '/'"
(Do you need to predeclare get?)
Can't load application from file "/etc/e-smith/web/functions/one": syntax
error at /etc/e-smith/web/functions/one line 9, near "get '/'"
Compilation failed in require at (eval 79) line 1.
[root@dsfdsfd functions]#

Charlie Brady

unread,
Dec 6, 2016, 12:23:06 PM12/6/16
to Mojolicious, sri

On Tue, 6 Dec 2016, Charlie Brady wrote:

> [root@dsfdsfd functions]# cat My/ML.pm
> package My::ML;
> use Mojolicious::Lite;
>
> plugin 'AppDefault';
>
> 1;

Changing the callers to use the same code in-line works:

[root@dsfdsfd functions]# cat one
#!/usr/bin/perl

use Mojolicious::Lite;
plugin 'AppDefault';

get '/' => sub { shift->render(text => "one\n") };

Stefan Adams

unread,
Dec 6, 2016, 12:29:28 PM12/6/16
to mojolicious
I wouldn't mind playing around with this problem. Can you dump your testing code into a gist of multiple files or something?

I'm not likely to solve this problem before you, but I'd be willing to give it a try!
Reply all
Reply to author
Forward
0 new messages