perl-embperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alan <a...@ufies.org>
Subject importing subroutines with Execute()
Date Thu, 23 Jan 2003 21:58:04 GMT
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.

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 <alan@ufies.org> - http://arcterex.net
---------------------------------------------------------------------
"The only thing that experience teaches us is that experience teaches 
us nothing.	        -- Andre Maurois (Emile Herzog)

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Mime
View raw message