Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
583 views
in Technique[技术] by (71.8m points)

bash - How to check availability of Perl, its version and presence of a required module?

I have written a Perl script, I just want to give it to every one, for that I planned to write a bash script which is used to test the environment of a user and find whether that environment is capable of running the Perl script.

I want to test the things like:

  1. Whether Perl has installed in that system
  2. Perl should have the version 5 or more
  3. Whether the module JSON::Any is available

Any suggestion would greatly appreciated :-)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

No, do not write a shell script. Perl already has a perfectly fine way of doing this. The correct way to do this is to build a CPAN-ready distribution using the normal toolchain. Some of this is explained in perlnewmod, perlmodstyle and perlmodinstall.

For a minimal working example, create a directory layout thus:

.
├── Build.PL
├── README
└── script
    └── abuscript.pl

In the Build.PL file, put:

use 5.000;
use Module::Build qw();
Module::Build->new(
    module_name        => 'abuscript',
    dist_version       => '1.000',
    dist_author        => 'abubacker <[email protected]>',
    dist_abstract      => 'describe what the script does in one sentence',
    configure_requires => {
        'perl' => '5.000',
    },
    requires           => {
        'JSON::Any' => 0,
    },
)->create_build_script;

Change the details to suite your purposes.

In the README file, put some installation instructions, for instance:

To install this module, run the following commands:

perl Build.PL
./Build install

Once you're done with all that, you run:

perl Build.PL
./Build manifest
./Build dist

This will result in a .tar.gz archive which you will distribute. Tell your users to install it like any other CPAN module, or if they don't know what that means, they should read the README.

If you have time, I recommend converting your script to a module. The program pl2pm (comes with Perl) and the CPAN module Module-Starter-PBP help you.

If license permits, it is possible to upload your code to CPAN to make it even more convenient for your users. Ask for help in any of the following places first: mailing list [email protected], web forum PerlMonks, IRC channel #toolchain on MagNET (irc://irc.perl.org/toolchain)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...