Kamis, 25 Februari 2010

The shorter path to deployment heaven

Now that there is cpanminus, I've modified the handy little module CPAN::AutoINC to prefer cpanminus over CPAN.

So now when users download and run my programs/scripts for the first time, instead of failing with the dreaded message:
Can't locate Foo/Bar.pm in @INC (@INC contains: [a dozen or more of paths....]).
BEGIN failed--compilation aborted at /some/path line 123

which users or even Perl novices have no clue on how to fix, the program will instead automatically download every necessary CPAN modules into the user's home directory and runs out-of-the-box on the first try!
$ download-bca
Fetching http://search.cpan.org/CPAN/authors/id/A/AD/ADAMK/File-HomeDir-0.89.tar.gz
Building File-HomeDir-0.89 for File::HomeDir...
File::HomeDir installed successfully.
Fetching http://search.cpan.org/CPAN/authors/id/D/DR/DROLSKY/File-Slurp-9999.13.tar.gz
Building File-Slurp-9999.13 for File::Slurp...
File::Slurp installed successfully.
Fetching http://search.cpan.org/CPAN/authors/id/S/SH/SHARYANTO/Finance-Bank-ID-BCA-0.07.tar.gz
==> Found dependencies: Pod::Coverage, DateTime, Test::Pod::Coverage, Log::Any, Any::Moose, Mouse
Fetching http://search.cpan.org/CPAN/authors/id/R/RC/RCLAMP/Pod-Coverage-0.20.tar.gz
==> Found dependencies: Devel::Symdump
Fetching http://search.cpan.org/CPAN/authors/id/A/AN/ANDK/Devel-Symdump-2.08.tar.gz
Building Devel-Symdump-2.08 for Devel::Symdump...
Devel::Symdump installed successfully.
Building Pod-Coverage-0.20 for Pod::Coverage...
Pod::Coverage installed successfully.
...
...
...
Fetching http://search.cpan.org/CPAN/authors/id/S/SP/SPADKINS/App-Options-1.07.tar.gz
Building App-Options-1.07 for App::Options...
App::Options installed successfully.
...
(the program finally runs)

As the developer, you only need to put "use CPAN::AutoINC" at the top of your main script. How's that for deployment heaven? Zero installation, zero configuration (thanks to cpanminus), zero dependency outside of Perl core modules.

But there's a catch. The user (or the user's sysadmin) still needs to install CPAN::AutoINC and needs to install and bootstrap local::lib first. So it's not really an out-of-the-box experience yet.

miyagawa++ is already planning to automatically bootstrap local::lib from cpanminus, and the logic behind CPAN::AutoINC is just a couple of dozen lines that can be embedded easily into the script (this process can be made automatic with distribution building tools like Dist::Zilla plugin).

Since cpanminus has zero dependencies, we can simply include it too in our application.

And maybe in the future there can be GUI interfaces for cpanm, so it can display a nice dialog to ask confirmation via the desktop.

Be prepared to be able to provide a much nicer experience for your users.

4 komentar:

  1. But doesn't that also impose a significant risk of accidentally breaking someone's perl install?

    ie, they have scripts that relied on the old configuration of libraries which your script now changes.

    Seems this would be a not-so-nice experience for a user if it breaks other stuff on their box that they don't know how to fix. (ie, like Windows .dll hell)

    BalasHapus
  2. I agree with Jon -- the developers shouldn't put CPAN::AutoINC (fanstastic idea by the way! :)). Users will put the module in the command line, like perl -MCPAN::AutoINC stuff.pl so the auto install/upgrade will begin.

    Or if you're too lazy and know how to shoot your foot, you can put PERL5OPT=-MCPAN::AutoINC in your shell rc file :)

    BalasHapus
  3. @miyagawa: Hm, how about developers putting something like CPAN::AutoINC but one that prompts user first before starting download?

    @Jon: Breaking other scripts can be solved with "use local::lib '~/myapp'" or even "use local::lib '~/myapp-ver'".

    BalasHapus
  4. Steven: yeah that might sound saner. Or, you ship 2 version of scripts, which one is a wrapper on the other one + use CPAN::AutoInc in the head so users can chose which to install.

    BalasHapus

Catatan: Hanya anggota dari blog ini yang dapat mengirim komentar.