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:
Any suggestion would greatly appreciated :-)
You probably already have perl installed. Type perl -v on a command line to find out which version. ActiveState Perl has binary distributions of Perl for many platforms.
You need to use instmodsh (interactive inventory for installed Perl modules) command to find out what modules already installed on my system. instmodsh command provides an interactive shell type interface to query details of locally installed Perl modules.
To find the version run perl -v command. Latest version of perl can get from ActiveState perl site. Have a look at App::perlbrew to compile and manage perl from source. From perl source code, you can find more information about current perl releases.
If the module is not installed, then: $ perl -e 'use dbi' Can't locate dbi.pm in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.14. 2 /usr/local/share/perl/5.14. 2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.14 /usr/share/perl/5.14 /usr/local/lib/site_perl .)
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)
Regarding checking Perl availability the easiest way to do it is to check the return code (exit code) of the command perl -v
,if this is not 0
, you do not have Perl.
Now regarding Perl requirements, you should deal with them from inside your Perl script:
#!/usr/bin/env perl
use 5.006_001;
use ModuleName 2.0;
The above Perl code will run only with perl 5.6.1 or newer and with modele "ModuleName" version 2.0 or newer. There is no need to manually check the Perl version from bash, it is better and easier to do it directly from the Perl script.
References:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With