Specifically the problem is that the default boilerplate

use lib 'lib';


tells Perl to include the 'lib' directory to your search path, which means
that 'lib' is relative to whatever directory you're in.  The script works
well if you're in the generated app's root.

The alternate method

use FindBin;
BEGIN { unshift @INC, "$FindBin::Bin/../lib" }


tells Perl to include the full path to the 'lib' dir, where lib is located
one directory above where the script lives.  A script using this method
works well no matter which directory you're in.

Sebastian,

I hope I'm not too far misplaced in my explanation.  Anyway, what is the
design decision for this?  Would it be bad to update the boilerplate to use
the FindBin method?

On Mon, Jan 11, 2016 at 2:40 PM, Marlik <[email protected]> wrote:

> How i did it:
>
> cd /var/www
> mojo generate app MyApp
>
> I get this script:
>
>
> #!/usr/bin/env perluse strict;use warnings;use lib 'lib';# Start command line 
> interface for applicationrequire 
> Mojolicious::Commands;Mojolicious::Commands->start_app('myapp');
>
> but it not work:
>
> hypnotoad /var/www/myapp/script/myapp
>
> Can't load application from file "/var/www/myapp/script/myapp":
> Can't find application class "MyApp" in @INC. etc....
>
> it working if i changed the code:
>
> #!/usr/bin/env perluse strict;use warnings;use FindBin;BEGIN { unshift @INC, 
> "$FindBin::Bin/../lib" }# Start command line interface for applicationrequire 
> Mojolicious::Commands;Mojolicious::Commands->start_app('MyApp');
>
> Why did it so?
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Mojolicious" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/mojolicious.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Reply via email to