Mailing List Archive

How does [! sub() !] work ?
Hello,

I want to define a few subs used everywhere on my site. So I wrote :

lib/subs.epl:

[.!
$req = shift;

sub test {
print OUT "test";
}
!]

test.html:
[-
$subs = Execute({object => "$ENV{DOCUMENT_ROOT}/lib/subs.epl"});
$subs->test;
-]


This works fine but I can't get the values in $req from subs.epl and
I need my $req->{dbh}...

Any clue ? Thanks for your help,

--
Jean-Christophe Boggio -o)
embperl@thefreecat.org /\\
Independant Consultant and Developer _\_V

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
RE: How does [! sub() !] work ? [ In reply to ]
Hi,

just use $epreq, it's a global and works everywhere

Gerald


> -----Original Message-----
> From: Jean-Christophe Boggio [mailto:embperl@thefreecat.org]
> Sent: Thursday, May 06, 2010 3:41 AM
> To: embperl@perl.apache.org
> Subject: How does [! sub() !] work ?
>
> Hello,
>
> I want to define a few subs used everywhere on my site. So I wrote :
>
> lib/subs.epl:
>
> [.!
> $req = shift;
>
> sub test {
> print OUT "test";
> }
> !]
>
> test.html:
> [.-
> $subs = Execute({object => "$ENV{DOCUMENT_ROOT}/lib/subs.epl"});
> $subs->test;
> -]
>
>
> This works fine but I can't get the values in $req from subs.epl and
> I need my $req->{dbh}...
>
> Any clue ? Thanks for your help,
>
> --
> Jean-Christophe Boggio -o)
> embperl@thefreecat.org /\\
> Independant Consultant and Developer _\_V
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
> For additional commands, e-mail: embperl-help@perl.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
Re: How does [! sub() !] work ? [ In reply to ]
Gerald Richter - ECOS a écrit :
> just use $epreq, it's a global and works everywhere

That's perfect, thanks Gerald.

--
Jean-Christophe Boggio -o)
embperl@thefreecat.org /\\
Independant Consultant and Developer _\_V

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
Re: How does [! sub() !] work ? [ In reply to ]
Hi Ed,

Ed Grimm a écrit :
> While Gerald's suggestion is the best one for your specific example,

Yes it is !

> there could be other issues you're having that could benefit from
> further enlightenment.

Thanks for taking this time, I highly appreciate.

> [! !] blocks do not declare a lexical scope.

I thought they did because if I declare this :

[- use feature "switch"; -]
[! given(...) { } !]

I have a syntax error : the "use feature 'switch'" *must* be between the [! ... !]

> You're running into at least two issues:
>
> 1. At the end of page processing, all the private namespace variables
> are cleaned up, so $req isn't even around for routines in subs.epl after
> the initial load.

I thought $req was supposed to address this (share data between pages).

> As such, I find it convinent to put all of my global
> constants in their own namespace.

That is, storing things in $mysite::req (and adding this to %CLEANUP) ?

> One can disable this cleanup, but
> that opens you up to data bleeds and semi-controlled memory bloat.

I know the risks, I won't go that way.

> 2. These blocks are only processed on the initial load, so $req would be
> invalid on the subsequent requests anyway.

By "initial load", you mean "the first time apache sees the code" ? Or the
first time this code is "executed" in the Execute() chain ?


Thanks again for your help.

--
Jean-Christophe Boggio -o)
embperl@thefreecat.org /\\
Independant Consultant and Developer _\_V

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