You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by Filin <fi...@bk.ru> on 2004/07/05 10:19:03 UTC

Trouble with catching output of prcodures

I have a trouble with using of output of embperl procedures. E.g. there is following declaration in some file:
[$ sub somesub $]Some text[$ endsub $]

If I want to catch output of somesub, I can:
	Execute({inputfile=>"file", import=>0});
	Execute({inputfile=>"file", sub=>'somesub', output=>\$str});

But what if I need to use something like:
	$file=Execute({object=>"file"});
	$file->somesub();

How can I catch output in this case?
It is possible of course just to replace [$ sub somesub ... $] with [! sub somesub {...} !], 
but I would be VERY glad to hear that it isn't the only decision.

Please help me.

(I use Embperl 1.3.6)

---
Owl


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


Re: Re[2]: Trouble with catching output of prcodures

Posted by Gerald Richter <ri...@ecos.de>.
Sherwin wrote:
> On Thu, Jul 08, 2004 at 02:16:53PM +0200, Gerald Richter wrote:
>> In 1.3.6 "die" only ends the current block, not the file. If you
>> want to end processing of the file, you have to use exit, but exit
>> only ends the proessing of the current file, the caller will still
>> continue. You have to catch it somehow there.
>
> Gerald,
>
> By exit, do you mean CORE::exit? Can the poster use Apache::exit to
> achieve what he wants in 1.3.6?
>

Embperl overloads exit, so when you do call just exit Embperl will handle it
for you (the same will happen if you call Apache::exit).

If you call CORE::exit the process (Apache child) will exit imediately. You
normaly don't want this

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: Re[2]: Trouble with catching output of prcodures

Posted by Sherwin <sh...@saturn.emc.com.ph>.
On Thu, Jul 08, 2004 at 02:16:53PM +0200, Gerald Richter wrote:
> In 1.3.6 "die" only ends the current block, not the file. If you want to end
> processing of the file, you have to use exit, but exit only ends the
> proessing of the current file, the caller will still continue. You have to
> catch it somehow there.

Gerald,

By exit, do you mean CORE::exit? Can the poster use Apache::exit to
achieve what he wants in 1.3.6?


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


Re: Re[2]: Trouble with catching output of prcodures

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

>
> title.epl
> [- die "Die in title.epl, " -]
> Test
>

In 1.3.6 "die" only ends the current block, not the file. If you want to end
processing of the file, you have to use exit, but exit only ends the
proessing of the current file, the caller will still continue. You have to
catch it somehow there.

Embperl 2 has a better die and exit handling (see README.v2)

Gerald


---------------------------------------------------------------------------
Gerald Richter            ecos electronic communication services gmbh
IT-Securitylosungen * 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[2]: Trouble with catching output of prcodures

Posted by Filin <fi...@bk.ru>.
Thank you, Gerald. Your recipe is perfectly good for me, but I have new 
questions about catching output (Embperl 1.3.6).

Let us assume that we have next three files:

some.epl
	Some text (Content does not matter)

title.epl
	[- die "Die in title.epl, " -]
	Test

test.epl
	<H1>[- Execute('title.epl'); # should die there -]</H1>
	[-
		Execute({
			inputfile=>"some.html", 
			output=>\$res,
		});
	
		#print OUT $res;
	-]
	<hr>
	I am alive. Why!?!


I thought that execution of test.html should die in the title.epl. 
However, it doesn't. 

Well, it will die, but _only_ if we comment the "output=>\$res" in the test.epl.

Moreover, the most strange for me: if we uncomment "#print OUT $res", we'll 
discover that there are lost error messages in the $res. Why it is so, if we 
didn't try to catch output of "Execute('title.epl')"?

I dont understand what's happening. :(
Could some kind person explain it for me?

Thanks.
---
Filin




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


Re: Trouble with catching output of prcodures

Posted by Gerald Richter <ri...@ecos.de>.
Filin wrote:
> I have a trouble with using of output of embperl procedures. E.g.
> there is following declaration in some file: [$ sub somesub $]Some
> text[$ endsub $]
>
> If I want to catch output of somesub, I can:
> Execute({inputfile=>"file", import=>0});
> Execute({inputfile=>"file", sub=>'somesub', output=>\$str});
>
> But what if I need to use something like:
> $file=Execute({object=>"file"});
> $file->somesub();
>
> How can I catch output in this case?
> It is possible of course just to replace [$ sub somesub ... $] with
> [! sub somesub {...} !],
> but I would be VERY glad to hear that it isn't the only decision.
>

You cannot directly catch the output of a method, but you can create a
wrapper:

[!
sub wrapper
    {
    $param[0]->$param[1]() ;
    }
!]

call it via

Execute({inputfile=>"file", sub=>'wrapper', output=>\$str, param => [$file,
'somesub']});

Gerald



---------------------------------------------------------------------------
Gerald Richter            ecos electronic communication services gmbh
IT-Securitylosungen * 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