Subject: FVWM: Modules, Perl, and Perl Modules

From: Nick Fortune <[email-masked]>
Date: Mon, 9 May 2005 10:52:08 +0100

Greetings, All.

I'd like to ask the advice of this list's readers. I'm writing a module in 
Perl. More to the point, I'm writing a HowTo about writing modules in Perl,
and I'd like my doc to reflect something approaching best practice. 

The thing is that the code is approaching that level of complexity when I
would usually split a perl script into modules. Just to be clear, that's
perl modules as in files ending in '.pm. and included using the "use"
pragma, as opposed to scripts executed by FVWM that just happen to be
written in Perl.

So the question is, where would be the best place to keep these? If they were
part of the distribution, they could find a home in the directory pointed at by 'fvwm-perllib dir'. But they're not.

I don't mind explaining about PERL5LIB and how to set up local lib directory, 
I was just wondering what would satisfy the principle of least surprise for
long time FVWM users.

I'm tending towards saying "create a directory $FVWM_USERDIR/perl and put the .pm files in there" and then pointing the script at the modules with a "use lib" directive. The trouble is that's fragile. If I hardcode the location and they can't use it, or don't want to use it, then the module breaks.

So I'm back to explaining about PERL5LIB which seems a bit of an overhead for a module that should just load and go. I suppose I could jam all the packages into one file. Bad perl practice there, but it'd solve the problem.

So: any thoughts or ideas? Anyone solved this already? Is there an orthodox FVWM way to approach this problem?

Thanks for your time,

Nick Fortune

--
Visit the official FVWM web page at <URL: http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm" in the body of a
message to [email-masked].
To report problems, send mail to [email-masked].

---

From: Mikhael Goikhman <[email-masked]>
Date: Mon, 9 May 2005 09:54:53 +0000

On 09 May 2005 10:52:08 +0100, Nick Fortune wrote:
> 
> I'm tending towards saying "create a directory $FVWM_USERDIR/perl and
> put the .pm files in there" and then pointing the script at the modules
> with a "use lib" directive. The trouble is that's fragile. If I
> hardcode the location and they can't use it, or don't want to use it,
> then the module breaks.

This is the way to go. Personally I would use $FVWM_USERDIR/perllib name
to match FVWM_DATADIR/perllib, since it is for classes, not for scripts.

If you want to handle the situation, you may do it in your module.

BEGIN {
	my $user_perllib_dir = "$ENV{FVWM_USERDIR}/perllib";
	die "Please create $user_perllib_dir with .pm files from http://url\n"
		unless -d $user_perllib_dir;

	use lib $user_perllib_dir;
	use MyModule1;
	use MyModule2;
}

This will show all possible errors on STDERR. If you also want to
show them in some X message box, you may use this solution instead:

BEGIN {
	my $user_perllib_dir = "$ENV{FVWM_USERDIR}/perllib";
	use FVWM::Module::Toolkit;

	FVWM::Module::Toolkit->showError("Please create ...", "My Error")
		unless -d $user_perllib_dir;

	use lib $user_perllib_dir;
	use FVWM::Module::Toolkit qw(MyModule1 MyModule2);
}

If there will be ever a practical problem (and not just theoretical,
there are no many perl module writters) I will add the built-in support,
and it will be just "use FVWM::Module::Toolkit qw(~ MyModule1 MyModule2)".

P.S. About the terminology, please use "perl classes", not "perl modules"
to avoid the confusion with "fvwm modules".

Regards,
Mikhael.