App::MyPerl - Your very own set of perl defaults, on a global or per project basis
# .myperl/modules v5.14 strictures autodie=:all $ myperl bin/some-script
Runs some-script with the following already loaded
use v5.14; use strictures; use autodie qw(:all);
and through the magic of lib::with::preamble, lib/ and t/lib/ are already in @INC but files loaded from there will behave as if they had those lines in them, too.
lib/
t/lib/
@INC
It is possible to add global defaults, to all scripts and all myperl projects with ~/.myperl/defaults/modules and ~/.myperl/always/modules
myperl
~/.myperl/defaults/modules
~/.myperl/always/modules
A .pm or .pl file usually requires some preamble to get some defaults right.
.pm or .pl
# important ones use strict; use warnings; # good use autodie qw(:all); # better exceptions use Try::Tiny; use Carp;
On top of that you might find Scalar::Util, List::Util useful all over your code.
myperl allows you define this boilerplate once and for all, while maintaining compatiability with existing code.
If there is no export MYPERL_HOME="~/.perl_defaults", ~/.myperl is by default read for global defaults.
export MYPERL_HOME="~/.perl_defaults"
~/.myperl
# ~/.myperl/always/modules strictures autodie=:all # ~/.myperl/defaults/modules v5.14 # ~/some_scripts/script.pl say "Hello World"
The syntax for the modules file is,
comment -- # comment
comment
empty space
Foo=bar,qux,baz -- This translates to use Foo qw(bar, qux, baz)
Foo=bar,qux,baz
use Foo qw(bar, qux, baz)
-Foo=bar,qux,baz -- This translates to no Foo qw(bar, qux, baz)
-Foo=bar,qux,baz
no Foo qw(bar, qux, baz)
Now,
$ myperl ~/some_scripts/script.pl
will print Hello World.
Hello World
Let's say you are working on a typical Perl module like,
.myperl/ lib/ t/ bin/ README LICENSE Makefile.PL ...
$ cd $project_dir; myperl bin/app.pl
will configure perl in such a way that lib/** and t/lib/**, will all have the preamble defined in .myperl/modules and ~/.myperl/always/modules thanks to the import hooks in lib::with::preamble.
lib/**
t/lib/**
.myperl/modules
If you don't have a .myperl/modules, myperl will use ~/.myperl/defaults/modules in place of it.
You can configure the directory $project_dir/.myperl with export MYPERL_CONFIG.
$project_dir/.myperl
export MYPERL_CONFIG
Running tests,
$ myprove t/foo.t
And in your Makefile.PL -
Makefile.PL
sub MY::postamble { q{distdir: myperl_rewrite myperl_rewrite: create_distdir myperl-rewrite $(DISTVNAME) }; }
(warning: this is make - so the indent for the myperl-rewrite line needs to be a hard tab)
myperl-rewrite
to have the defaults added to the top of .pm, .t and bin/* files in your dist when it's built for CPAN.
.pm, .t and bin/*
Sometimes though, you want a module to be used during development, but not written into the final dist. A good case for this is indirect.
indirect
For this, add -indirect in $project_dir/.myperl/dev-modules.
-indirect
$project_dir/.myperl/dev-modules
To specify modules loaded only into the top level script, prepend script- to the file name - so $project_dir/.myperl/script-modules specifies modules only used for the top level script, and script-dev-modules the same but not rewritten onto scripts when myperl-rewrite is invoked.
script-
$project_dir/.myperl/script-modules
script-dev-modules
And lastly, you can add if::minus_e=Some::Module in $MYPERL_HOME/defaults/script-dev-modules for having Some::Module conveniently preloaded for <myperl -e '...'> oneliners - see if::minus_e for how this behaves in detail.
if::minus_e=Some::Module
$MYPERL_HOME/defaults/script-dev-modules
Some::Module
mst - Matt S. Trout (cpan:MSTROUT) <mst@shadowcat.co.uk>
mucker - (cpan:MUCKER) <mukcer@gmx.com>
Copyright (c) 2013 the App::MyPerl "AUTHOR" and "CONTRIBUTORS" as listed above.
This library is free software and may be distributed under the same terms as perl itself.
To install App::MyPerl, copy and paste the appropriate command in to your terminal.
cpanm
cpanm App::MyPerl
CPAN shell
perl -MCPAN -e shell install App::MyPerl
For more information on module installation, please visit the detailed CPAN module installation guide.