Hi folks.
I recently started working on a web project utilizing embperl2 and
apache2, and what I thought would be the simple task of having subs
available from a module seems to be not as simple after all. Or at
least, not for me :)
I have a file (utils.pm say) with some perl style subs that look
something like this:
utils.pm
--------
sub test
{
return 1 if($fdat{field1} == 42 );
return 0;
}
....
(Note that it assumes that %fdat (and %udat) are available)
--------
If I throw this file into something in the default @INC
(/usr/lib/perl/.../utils.pm) I can call code with:
index.html
----------
[-
require "utils.pm";
$val = test( "test123" );
-]
<html>
blah [+ $val +]
</html>
----------
This works, but is (IMHO) ugly, and means that the file with the subs
has to be either in the @INC path, or imported in with a use lib(...).
The way that the CVS tree is structured, I'd like to just put the subs
in a file in the base of the html tree, maybe have it loaded in via
Embperl::Object in my base.epl or something.
Anyway, what I thought I could do is something like:
index.html
----------
[-
Execute("../utils.pm");
$val = test( "test123" );
-]
<html>
blah [+ $val +]
</html>
----------
This doesn't seem to work. I can change the code to this it works:
index.html
----------
[-
$obj = Execute ({object => 'utils.pm', syntax => 'Perl'}) ;
$val = $obj->test( "test123" );
-]
<html>
blah [+ $val +]
</html>
----------
However, this would mean changing a lot of code to use the $obj syntax,
as well as the library code to put a "$self = shift;" in them. After a
bit of looking it seems that I can import with the package =>
__PACKAGE__ if I only import once, which seems to mostly work.
Also, is there a way to make sure that the subs imported with the
Execute() are kept up to date if the utils.pm file is changed?
Currently I have to HUP my webserver to get changes recognized, and one
of the advantages in embperl is that you don't have to do that :)
If you're not hopelessly confused by now, is there a way to do what I'm
looking for (ie: import via relative path, or automagically via
embperl::object, so that minimul code changes are needed?
Regards,
Alan
--
Alan <[EMAIL PROTECTED]> - http://arcterex.net
---------------------------------------------------------------------
"The only thing that experience teaches us is that experience teaches
us nothing. -- Andre Maurois (Emile Herzog)
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]