Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #710 from kraih/installable
use #!perl for installation and recommend it for installable scripts
  • Loading branch information
jberger committed Nov 24, 2014
2 parents 058c294 + 2e19c43 commit 0339047
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 26 deletions.
1 change: 1 addition & 0 deletions Changes
@@ -1,5 +1,6 @@

5.65 2014-11-23
- Use #!perl for installable scripts (jberger)

5.64 2014-11-22
- Fixed bug in Mojolicious::Commands where the global Getopt::Long
Expand Down
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
18 changes: 18 additions & 0 deletions lib/Mojolicious/Guides/Cookbook.pod
Expand Up @@ -1430,6 +1430,24 @@ get automatically installed with the modules.

1;

Finally a few small changes should be made to the application script. The
shebang becomes the recommended C<#!perl>, which the toolchain rewrites to the
proper shebang during installation. Also use L<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
27 changes: 6 additions & 21 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 @@ -721,27 +721,12 @@ moved into the appropriate directories.

=head2 Script

Finally C<myapp.pl> can be replaced with a proper L<Mojolicious> script.
Finally C<myapp.pl> can be moved into a C<script> directory and renamed to
C<my_app> to follow the CPAN standard.

$ 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');
$ mv myapp.pl script/my_app
$ chmod 744 script/my_app

=head2 Simplified tests

Expand Down Expand Up @@ -777,7 +762,7 @@ And our final directory structure should be looking like this.

myapp
|- script
| +- myapp
| +- my_app
|- lib
| |- MyApp.pm
| +- MyApp
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 0339047

Please sign in to comment.