The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

BaseLib - manipulate @INC dynamically for independent installation path

SYNOPSIS

  use BaseLib qw(BASEDIR LIBDIR);

or just,

  use BaseLib;

DESCRIPTION

If you have a set of application with certain file structure under a base directory, e.g. pim, and it has a private modules directory called lib-perl, and it's intalled under /usr/local. For the application to work, the scripts may need to say:

   use lib '/usr/local/pim/lib-perl';

Someday, you need to move the application to, say, /vhost/www.host.com, so you need to change the use statement all over the scripts to:

   use lib '/vhost/www.some.host.com/pim/lib-perl';

If you do this a lot and get tired of changing the line for every different installation path in every script, or, you don't want to bother people using your application to change the line to meet their conditions, then you might need this module.

Now your scripts can say:

   use BaseLib qw(pim lib-perl);

where pim and lib-perl are the BASEDIR and LIBDIR arguments, respectively.

So there's no need to worry about different installation layout, wherever the pim base directory is put under. The BASEDIR argument is mandatory while LIBDIR is optional (defaults to lib/perl).

As addition, you can use BaseLib's global package variable, $BaseDir to refer to the full path to pim. For example, assuming the application is installed under /usr/local, then

   print "Data dir: $BaseLib::BaseDir/data\n";

will print,

   Data dir: /usr/local/pim/data

You have to use the fully qualified package name since it's not exportable.

You can use your own global variable by supplying the third argument in the use statement. For example,

   use BaseLib qw(pim lib-perl MyOwnBaseDir);

So saying,

   print "Data dir: $MyOwnBaseDir/data\n";

will result the same thing. If you use 'use strict;', which is a good thing, you need to explicitly declare it as global variable. Either,

   use vars '$MyOwnBaseDir';

or, if you use version 5.6 or later,

   our $MyOwnBaseDir;

If you want to use the default LIBDIR (lib/perl), you can indicate so by using dash ("-").

   use BaseLib qw(pim - MyOwnBaseDir);

Or, just give an empty string,

   use BaseLib ('pim', '', 'MyOwnBaseDir');

NOTES

I rewrote the implementation to make this module more reusable in different environment. No path resolving is hardcoded. Unfortunately, I have no any chance to test it.

BaseLib will find the last occurence of BASEDIR string. If you mean the base directory as /usr/local/myapp, while the script uses the module locates in /usr/local/myapp/bin/sample/myapp/test/script.pl, then the full path to the application base directory ends in /usr/local/myapp/bin/sample/myapp.

Any improvements/suggestions for wider support are welcome. A simple comment on this module will do as well.

AUTHOR

This module is written by Hasanuddin Tamir <hasant@trabas.com>.

Copyright (C) 2000 Trabas. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO

lib, FindBin