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

后端 未结 3 2080
遥遥无期
遥遥无期 2020-12-03 16:07

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 whethe

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-03 16:45

    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 ',
        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 module-authors@perl.org, web forum PerlMonks, IRC channel #toolchain on MagNET (irc://irc.perl.org/toolchain)

提交回复
热议问题