View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Hasanuddin Tamir > BaseLib > BaseLib



Annotate this POD

View/Report Bugs
Module Version: 0.05   Source  


BaseLib - manipulate @INC dynamically for independent installation path


  use BaseLib qw(BASEDIR LIBDIR);

or just,

  use BaseLib;


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/, so you need to change the use statement all over the scripts to:

   use lib '/vhost/';

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');


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/, 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.


This module is written by Hasanuddin Tamir <>.

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.


lib, FindBin

syntax highlighting: