I am looking for a way to include the module Clone from CPAN with my script so that users need not install the module themselves.

They should just extract the zip file and there would be a subdir Modules in the distribution which contains Clone and works out-of-the-box. Ideally, the solution should be independent from the user's architecture. My own system is Mac OS X.

Read on for what I tried so far...

I followed this guide to install the Module locally to ~/clone. But as I want the module in a subdir of my distribution, I did not leave it there and copied the files Clone.pm, auto/Clone/autosplit.ix, auto/Clone/Clone.bs and auto/Clone/Clone.bundle to the distribution's Modules directory and added ./Modules to @INC. So far, this works on various machines with Mac OS X and devtools installed.

Contents of the disto directory:

test.pl
Modules
   Clone.pm
   auto
      autosplit.ix
      Clone.bs
      Clone.bundle

Contents of test.pl:

use lib qw(./Modules); use Clone qw(clone); use Data::Dumper 'Dumper'; my $struct = { a => 1, b => [2, 2.5] }; print "The original structure:\n"; print Dumper $struct; my $clonedstruct = clone($struct); print "\n\nThe cloned structure:\n"; print Dumper $clonedstruct;

This works on several OS X machines I tested (v5.8.1-RC3 built for darwin-thread-multi-2level). But on Linux (v5.8.0 built for i586-linux-thread-multi), it gives me an error: Can't locate loadable object for module Clone in @INC. I then did the same procedure again for Linux (installing Clone locally and moving files into Modules dir) when I noticed that the file Clone.bundle appears to be called Clone.so here. I then copied both Clone.bundle and Clone.so into Modules/auto and now it appears to work on both OS X and Linux.

So I assume that this solution (if it may be called so), while it seems to work on OS X and Linux, is some dirty hack which will break as soon as I turn my back. Plus, it probably doesn't work on Win32, which bugs me.

Now, is there a right way to do this? And is this kind of architecture independence which I want even achievable?

--anjoschu

P.S.: I am aware of the fact that I must ensure that the module's license permits bundling it with my distro.

Update: Added cross-platform to the title for search-friendliness.


In reply to Bundling a module with a distribution (cross-platform) by anjoschu

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.