perl-embperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrew O'Brien" <andr...@oriel.com.au>
Subject RE: @param seems to be shared between Execute calls
Date Mon, 26 Jul 2010 00:47:32 GMT

Hi Michael,

> Thanks for the email.  I'm actually using @param to return 
> data (as well as the HTML) to the epl script which is calling 
> another one via Execute.  Perhaps there's a better way.

I think you may just be missing one piece of the puzzle: using
references with the param argument to the Execute function. To slightly
rewrite an example posted previously:

use Embperl;
use Data::Dumper;

my $data = {};

my $output1;
my $input = '[- $param[0]->{hello} = 42; -]';

Embperl::Execute({ inputfile => "blah",
                   input => \$input,
                   output => \$output1,
                   param => [ $data ],
                 });

print "Execute of file 1, data is currently set to:\n" . Dumper($data);

my $output2;
my $input2 = 'Hello! I was executed with the following arguments: [+ do
{ use Data::Dumper; Dumper(\@param); } +]';

Embperl::Execute({ inputfile => "blah",
                   input => \$input2,
                   output => \$output2,
                   param => [ $data ],
                 });

print "Execute of file 2, data is currently set to:\n" . Dumper($data);

print "Output of Execute() call:
$output2
";

This yields:

Execute of file 1, data is currently set to:
$VAR1 = {
          'hello' => 42
        };
Execute of file 2, data is currently set to:
$VAR1 = {
          'hello' => 42
        };
Output of Execute() call:
Hello! I was executed with the following arguments: $VAR1 = [
          {
            'hello' =&gt; 42
          }
        ];

> On Fri, Jul 23, 2010 at 4:38 AM, Ed Grimm 
> <ed_grimm@raytheon.com> wrote:
> 
> 
> 	If your Embperl pages are calling regular perl module 
> code that uses @param, couldn't you just pass it from your 
> Embperl page as a parameter, rather than using it as a global? 
> 	
> 	Alternatively, if you are talking about code within an 
> Embperl page, how do you process those without going through 
> Execute?  Note that the standard apache handler calls 
> Execute, last I checked.  I seem to recall there's a few 
> other methods to run Embperl pages - but ultimately, they all 
> call Execute.  Disclaimer: I haven't looked in a while, and 
> it's late, and I'm tired.
> 	
> 	-- 
> 	Ed Grimm
> 	Identity Services 
> 	
> 	
> 	
> From: 	Michael Smith <smithm@gmail.com> 	
> To: 	Gerald Richter - ECOS <gerald.richter@ecos.de> 
> Cc: 	embperl@perl.apache.org, Michael Stevens 
> <michael.stevens@dianomi.com>, 
> cabell.demarcellus@dianomi.com, Michael Smith 
> <michael.smith@dianomi.com> 	
> Date: 	07/22/2010 06:25 PM 	
> Subject: 	Re: @param seems to be shared between Execute calls	
> 
> ________________________________
> 
> 
> 
> 
> 	Thanks Gerald, 
> 	
> 	That's good to know for the future.  Is there a way to 
> know if the code has been called through Execute?  I am 
> actually using the same code both directly and via Execute. 
> 	
> 	Michael
> 	
> 	On Wed, Jul 21, 2010 at 10:19 AM, Gerald Richter - ECOS 
> <gerald.richter@ecos.de <mailto:gerald.richter@ecos.de> > wrote: 
> 	Hi Michael, 
> 
> 	  
> 
> 	@param is only intented to be used to pass parameters 
> to Execute. Setting it directly might work or might not... 
> 
> 	  
> 
> 	If you want to share data inside a request use 
> 
> 	  
> 
> 	 $epreq -> {test} = 1 ; 
> 
> 	  
> 
> 	The hash of $epreq is not used by Embperl itself, so 
> you are free to use it and it exists exactly for the live 
> time of one Apache request 
> 
> 	  
> 
> 	Gerald 
> 
> 	  
> 
> 	  
> 
> 	  
> 
> 	From: Michael Smith [mailto:smithm@gmail.com 
> <mailto:smithm@gmail.com> ] 
> 	Sent: Wednesday, July 21, 2010 11:05 AM 
> 
> 	
> 	To: embperl@perl.apache.org <mailto:embperl@perl.apache.org>  
> 	Cc: Michael Stevens; cabell.demarcellus@dianomi.com 
> <mailto:cabell.demarcellus@dianomi.com> ; Michael Smith
> 	Subject: Re: @param seems to be shared between Execute calls 
> 
> 	  
> 
> 	My problem is slightly different - though possibly a 
> manifestation of the same thing.  I find that param isn't 
> cleaned up between requests. 
> 
> 	  
> 
> 	I have two epl files: 
> 
> 	  
> 
> 	set.epl: 
> 
> 	[- $param[0]->{'test'} = 1 -] 
> 
> 	  
> 
> 	get.epl 
> 
> 	[+ Dumper(@param) +] 
> 
> 	  
> 
> 	I find that the data from set.epl turns up when I make 
> a subsequent request for get.epl (in practice it's a bit more 
> random than that if one is running multiple processes, so I 
> make a few requests for set.epl and then a few for get.epl) 
> 
> 	  
> 
> 	This only seems to be relevant if I reference param in 
> the epl file I am calling directly.  If I reference it in epl 
> files which are loaded in by Execute, then they do appear to 
> get cleaned up. 
> 
> 	  
> 
> 	Michael 
> 
> 	  
> 
> 	  
> 
> 	On Tue, Jul 20, 2010 at 10:20 PM, Ed Grimm 
> <ed_grimm@raytheon.com <mailto:ed_grimm@raytheon.com> > wrote: 
> 
> 	Note that, under Apache, the cleanup code happens at 
> the end of each request - each of which could have dozens of 
> Execute calls, between which it is very definitely NOT called. 
> 	
> 	I have not used Embperl much from within server 
> scripts, but in my limited use there, I've never seen the 
> cleanup code fire.  I suspect each script is considered 'a 
> request' for the purposes of the cleanup code (well, as far 
> as docs are concerned.  I don't know if the code actually 
> fires on END.)
> 	
> 	-- 
> 	Ed Grimm
> 	Identity Services 
> 	
> 
> 	
> 
> From: 	Michael Stevens <michael.stevens@dianomi.com 
> <mailto:michael.stevens@dianomi.com> > 	
> To: 	embperl@perl.apache.org <mailto:embperl@perl.apache.org>  	
> Cc: 	Michael Smith <michael.smith@dianomi.com 
> <mailto:michael.smith@dianomi.com> >, 
> cabell.demarcellus@dianomi.com 
> <mailto:cabell.demarcellus@dianomi.com>  	
> Date: 	07/20/2010 10:12 AM 	
> Subject: 	@param seems to be shared between Execute calls	
> 
> 	  
> 
> 	
> 
> ________________________________
> 
> 	
> 
> 	
> 	
> 	
> 	Hi.
> 	
> 	We're seeing an odd bug where @param seems to be shared 
> between Execute 
> 	calls in the same process. The following code is a test 
> case for this:
> 	
> 	#!/usr/bin/perl -w
> 	
> 	use strict;
> 	use Embperl;
> 	
> 	my $output1;
> 	
> 	my $input = '[- $param[0]->{hello} = 42; -]';
> 	
> 	Embperl::Execute({
> 	                inputfile => "blah",
> 	                input => \$input,
> 	                output => \$output1,
> 	                });
> 	
> 	my $output2;
> 	my $input2 = '[- use Data::Dumper; print Dumper(\@param); -]';
> 	
> 	Embperl::Execute({
> 	                                 inputfile => "blah",
> 	                                 input => \$input2,
> 	                                 output => \$output2
> 	                });
> 	
> 	Which on my machine outputs:
> 	
> 	$VAR1 = [
> 	          {
> 	            'hello' => 42
> 	          }
> 	        ];
> 	
> 	Surely this shouldn't happen?
> 	
> 	-- 
> 	Michael Stevens
> 	Dianomi Ltd
> 	18 Buckingham Gate
> 	London SW1E 6LB
> 	
> 	Tel: 020 7802 5530
> 	Fax: 020 7630 7356
> 	www.dianomi.com <http://www.dianomi.com/> 
> 	
> 	The information in this message and any attachment is 
> intended for the 
> 	addressee and is confidential and may be subject to 
> legal privilege. 
> 	Dianomi Ltd, Registered Office: One America Square, 
> Crosswall, London. 
> 	EC3N 2SG. Registered in England and Wales with Company 
> Registration 
> 	Number 4513809. VAT registration number: 809754988
> 	
> 	
> ---------------------------------------------------------------------
> 	To unsubscribe, e-mail: 
> embperl-unsubscribe@perl.apache.org 
> <mailto:embperl-unsubscribe@perl.apache.org> 
> 	For additional commands, e-mail: 
> embperl-help@perl.apache.org <mailto:embperl-help@perl.apache.org> 
> 	
> 
> 	  
> 
> 	
> 
> 	
> 
> 	
> 
> 	
> 
> 	
> 
> 	
> 
> 	
> 
> 	
> 
> 	
> 
> 	
> 
> 	
> 
> 	
> 
> 	
> 
> 	
> 
> 	
> 
> 	
> 
> 	
> 
> 	
> 
> 	
> 
> 	
> 
> 	
> 
> 	
> 
> 	
> 
> 	
> 
> 	
> 
> 	
> 
> 	
> 
> 	
> 
> 	
> 
> 	
> 
> 	
> 
> 	
> 
> 	
> 
> 	
> 
> 	
> 
> 	
> 
> 	
> 
> 	
> 
> 	
> 
> 	
> 
> 	
> 
> 	
> 
> 
> 

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


Mime
View raw message