And is it good idea? I wrote a script and it uses some unpopular modules. Installing them takes much time, so I thought it would be better to distribute them with my application. How can I do that?
2 Answers
It is customary to ship dependencies in the inc
directory of your distribution. I have talked about this in how do I link PerlIO Perl package without "installing it" and automatically install missing modules from CPAN before.
The question is vague, so instead of code, just advice: I make the assumption you want no installation at all. Put the unpacked dependencies in into the inc
directory. Access it at runtime with use lib 'inc';
.
That's all.
Sure. Under the Apache license, you can redistribute the modules.
Are these object oriented modules that don't import any functions? Then, you don't have to do anything. Simply remove the use My::Module;
from the main program, then append My::Module
right to the end of your main program.
If you are not using object oriented code, and it's exporting functions via the @EXPORT
array, you'll have to take some additional measures:
Here, I had to add Local::Foo->import qw(foo)
to import the foo
function into the main program even though it's exported via @EXPORT
and not @EXPORT_OK
. I also had to use the BEGIN around my export declarations in my module. Otherwise, my main program would find nothing to import:
Original Programs:
Main Program:
#! /usr/bin/env perl
# test.pl
use warnings;
use strict;
use Local::Foo;
use feature qw(say);
my $bar = foo("bar");
say "Bar is '$bar'";
Module Local::Foo
#! /usr/bin/env perl
# Local/Foo.pm
#
package Local::Foo;
use Exporter qw(import);
our @EXPORT = qw(foo);
sub foo {
my $value = shift;
return "FOOOOOO $value";
}
1;
The Combined Program
#! /usr/bin/env perl
# test.pl
use warnings;
use strict;
# use Local::Foo;
# Force importation of `foo`
Local::Foo->import qw(foo);
use feature qw(say);
my $bar = foo("bar");
say "Bar is '$bar'";
#-----------------------------------------------------------------------
#! /usr/bin/env perl
# Local/Foo.pm
#
package Local::Foo;
# Add BEGIN clause to module
BEGIN {
use Exporter qw(import);
our @EXPORT = qw(foo);
}
sub foo {
my $value = shift;
return "FOOOOOO $value";
}
1;

- 105,218
- 39
- 216
- 337
-
1Who said anything about Apache? (The vast majority of Perl modules are GPL1/Artistic1 dual-licensed, a.k.a. "under the same terms as Perl itself".) - I am not happy with that manual combining, you should recommend fatpacker instead. – daxim May 08 '12 at 08:42
-
@daxim I don't know anything about _fatpacker_. I found App::Fatpacker. Is that it? There's not much in the way of documentation. Can you provide an answer that explains how to use fatpacker? I would be interested in that. – David W. May 08 '12 at 12:54