You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by Dan Manley <dm...@spotnikmobile.com> on 2004/06/22 19:57:42 UTC

namespaces for imported embperl sub's

Hi,

In a project I'm working on, I'd like to have some small and simple 
embperl subs located in a lib directory, in individual files (for the 
most part).  Consequently, I would like to be able to import all of 
these files in a single call, like with something like this:

Execute({ inputfile => $req->{embperl_common_lib} . "/all.epl", import 
=> 1, package => "SPOTNIK_COMMON" });

all.epl would have a bunch of epl's to import, like this:

[-
  my $req = shift;
  Execute( { inputfile => $req->{embperl_common_lib}.'/displaytime.epl', 
import => 1, package => "SPOTNIK_COMMON" } );
 -]


But when I try to call a sub defined in displaytime.epl with the 
namespace of SPOTNIK_COMMON:: it says the sub doesn't exist.

Am I doing this the right way?  Is there something I'm missing or 
something I should be doing differently?

Dan


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


Re: namespaces for imported embperl sub's

Posted by Gerald Richter <ri...@ecos.de>.
Hi,

>
> But when I try to call a sub defined in displaytime.epl with the
> namespace of SPOTNIK_COMMON:: it says the sub doesn't exist.
>

How are your sub inside the lib epl are defined and how do you try to call
them?


> Am I doing this the right way?  Is there something I'm missing or
> something I should be doing differently?
>

What you are should work (from what I see so far). I guess there is some
problem with the way you define or call the subs.

Of course there are many other possibilities as Luiz already wrote.

Gerald

---------------------------------------------------------------------------
Gerald Richter            ecos electronic communication services gmbh
IT-Securitylösungen * Webapplikationen mit Apache/Perl/mod_perl/Embperl

Post:       Tulpenstrasse 5          D-55276 Dienheim b. Mainz
E-Mail:     richter@ecos.de          Voice:   +49 6133 939-122
WWW:        http://www.ecos.de/      Fax:     +49 6133 939-333
---------------------------------------------------------------------------
ECOS BB-5000 Firewall- und IT-Security Appliance: www.bb-5000.info
---------------------------------------------------------------------------


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


Re: namespaces for imported embperl sub's

Posted by "Luiz Fernando B. Ribeiro" <lu...@engenhosolucoes.com.br>.
On Tue, 22 Jun 2004 13:57:42 -0400, Dan Manley <dm...@spotnikmobile.com>  
wrote:

> Hi,
>
> In a project I'm working on, I'd like to have some small and simple  
> embperl subs located in a lib directory, in individual files (for the  
> most part).  Consequently, I would like to be able to import all of  
> these files in a single call, like with something like this:
>
> Execute({ inputfile => $req->{embperl_common_lib} . "/all.epl", import  
> => 1, package => "SPOTNIK_COMMON" });
>
> all.epl would have a bunch of epl's to import, like this:
>
> [-
>   my $req = shift;
>   Execute( { inputfile => $req->{embperl_common_lib}.'/displaytime.epl',  
> import => 1, package => "SPOTNIK_COMMON" } );
>  -]
>
>
> But when I try to call a sub defined in displaytime.epl with the  
> namespace of SPOTNIK_COMMON:: it says the sub doesn't exist.
>
> Am I doing this the right way?  Is there something I'm missing or  
> something I should be doing differently?
>

Hi,

Defining your own namespace can lead to some problems. Another solution is  
to let Embperl handle de namespace and use the isa syntax in Execute, like:

Execute({isa => 'subs.epl'});

Your subs will be available as methods of the request_rec object passed as  
first param in @_ for all pages.

Another solution is to use the object:
my $object = Execute({object => 'component.epl'});

Your subs will be available as methods of the returned reference, like:
$object->function()

For loading your pages I suggest you to put the list of pages to be  
imported in a shared function but to execute the Execute statement inside  
each page, like:

Execute({isa => $_}) foreach modules();

where modules return a list of your epl pages to be loaded.

I encourage you to take a look at EmbperlObject since all of this would  
become easier.

-- 
Luiz Fernando B. Ribeiro
Engenho Soluções para a Internet
+55 11 4485-0136

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