简体   繁体   中英

What is the recommended way to package perl scripts for CPAN (and CorporatePAN)?

Recently I looked at a module on CPAN that comes with a script to be installed which made me wonder. What is the recommended way to include a script in a package that should end up on the public CPAN and if there is any different recommendation for packages that would be released on an in-house CPAN server?

The script starts like this:

#!/usr/bin/perl

eval 'exec /usr/bin/perl  -S $0 ${1+"$@"}'
  if 0; # not running under some shell

Two questions

Do I understand correctly the eval part is unnecessary? That will be embedded by the CPAN client during installation and it will be very different when installing on Windows.

What is the recommended sh-bang line? Would that be

#!/usr/bin/env perl

instead of the above?

Just use

#!/usr/bin/perl

(Or, optionally, whatever the path to perl is on your development machine.)

When Module::Build or MakeMaker installs your script, it will change the #! line to match the perl that is installing the module. It will also add the "eval exec" lines, except under Windows, where it will create a .bat file instead. (The CPAN client has nothing to do with this.)

If you use

#!/usr/bin/env perl

then the installers won't realize that's a Perl script, and will not modify the #! line.

When the distribution is being installed, it is being installed for some particular perl , and should explicitly set the #! to use that perl (as given in $Config{startperl} ). As far as I know all the module installers do this for you. (Update: as noted by cjm, only if the #! as distributed runs perl, not env.)

The eval stuff is traditionally included to automatically use perl even if a script is invoked with sh scriptname . It's harmless.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM