Skip to content

Commit

Permalink
use #!perl for installation and recommend it for installable scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
jberger committed Nov 24, 2014
1 parent 058c294 commit 2ccaefe
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 30 deletions.
3 changes: 1 addition & 2 deletions lib/Mojolicious/Command/generate/app.pm
Expand Up @@ -114,8 +114,7 @@ __DATA__
use strict;
use warnings;
use FindBin;
BEGIN { unshift @INC, "$FindBin::Bin/../lib" }
use lib 'lib';
# Start command line interface for application
require Mojolicious::Commands;
Expand Down
24 changes: 24 additions & 0 deletions lib/Mojolicious/Guides/Cookbook.pod
Expand Up @@ -1430,6 +1430,30 @@ get automatically installed with the modules.

1;

Finally C<myapp.pl> can be replaced with an installable L<Mojolicious> script.

$ rm myapp.pl
$ mkdir script
$ touch script/myapp
$ chmod 744 script/myapp

Only a few small details change. We change the shebang to the recommended
C<#!perl>, which the toolchain rewrites to the proper shebang during
installation. We also use C<FindBin> rather than L<lib> since installable
scripts can't use L<lib> without breaking updated dual-life modules.

#!perl

use strict;
use warnings;

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

# Start command line interface for application
require Mojolicious::Commands;
Mojolicious::Commands->start_app('MyApp');

That's really everything, now you can package your application like any other
CPAN module.

Expand Down
26 changes: 1 addition & 25 deletions lib/Mojolicious/Guides/Growing.pod
Expand Up @@ -612,9 +612,9 @@ allow running tests again.
use warnings;

use lib 'lib';
use Mojolicious::Commands;

# Start command line interface for application
require Mojolicious::Commands;
Mojolicious::Commands->start_app('MyApp');

And the directory structure of our hybrid application should be looking like
Expand Down Expand Up @@ -719,30 +719,6 @@ moved into the appropriate directories.
$ mv templates/index.html.ep templates/login/index.html.ep
$ mv templates/protected.html.ep templates/login/protected.html.ep

=head2 Script

Finally C<myapp.pl> can be replaced with a proper L<Mojolicious> script.

$ rm myapp.pl
$ mkdir script
$ touch script/myapp
$ chmod 744 script/myapp

Only a few small details change, since installable scripts can't use L<lib>
without breaking updated dual-life modules.

#!/usr/bin/env perl

use strict;
use warnings;

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

# Start command line interface for application
require Mojolicious::Commands;
Mojolicious::Commands->start_app('MyApp');

=head2 Simplified tests

Full L<Mojolicious> applications are a little easier to test, so C<t/login.t>
Expand Down
2 changes: 1 addition & 1 deletion script/hypnotoad
@@ -1,4 +1,4 @@
#!/usr/bin/env perl
#!perl

use strict;
use warnings;
Expand Down
2 changes: 1 addition & 1 deletion script/mojo
@@ -1,4 +1,4 @@
#!/usr/bin/env perl
#!perl

use strict;
use warnings;
Expand Down
2 changes: 1 addition & 1 deletion script/morbo
@@ -1,4 +1,4 @@
#!/usr/bin/env perl
#!perl

use strict;
use warnings;
Expand Down

0 comments on commit 2ccaefe

Please sign in to comment.