You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by "Marcus R. Popetz" <mp...@netility.com> on 2001/02/28 02:18:20 UTC

Stop processing script upon die

Hello all.

I have been trying to get Embperl to stop further processing of my scripts 
when I detect an error.
Anyone had any luck getting this to work?

I've tried to:
die "random error message here";
but Embperl just saves up the error messages to be delivered at a later date.

What I'm trying to accomplish:

Someone posts some data.
I detect they are not logged in.
I stop processing (because they might not have privs to do what they are 
posting)
I redirect to a login page.

Any help would be great.
-mp


Re: Stop processing script upon die

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

> 
> Would it be worth considering an [$ exit $] command in Embperl that
> would stop all processing at that point, even if the command is in a
> file which is executed from another?

Yes, something like this would make sense. I add it to the TODO list

> Currently, if you call the Perl
> exit() function then it only seems to exit from the current file, but
> the parent will continue.

yes

> It seems like a common pattern to want to
> cease all processing, even if you are in a child file or subroutine. 

yes

> Or,
> is there a cleaner way to do it (using the existing version) than the
> one I suggested below?
> 

no

Gerald




Re: Stop processing script upon die

Posted by Neil Gunton <ne...@nilspace.com>.
Gerald,

Would it be worth considering an [$ exit $] command in Embperl that
would stop all processing at that point, even if the command is in a
file which is executed from another? Currently, if you call the Perl
exit() function then it only seems to exit from the current file, but
the parent will continue. It seems like a common pattern to want to
cease all processing, even if you are in a child file or subroutine. Or,
is there a cleaner way to do it (using the existing version) than the
one I suggested below?

TIA

-Neil

"Marcus R. Popetz" wrote:
> 
> Yep.  That does it.  Thanks.
> 
> -mp
> 
> ps.  If the powers-that-be have a slightly less verbose way to stop
> processing from within a child script, if you could let the list know, that
> would be cool.
> 
> At 10:25 AM 2/28/01, Neil Gunton wrote:
> > > My login testing occurs from within an .epl page that is invoked by Execute
> > > from within another .epl file.
> > >
> > > main.epl
> > >          Execute( logintest.epl)
> > >          <code>
> > >          Execute(sidenav.epl)
> > >          <code>
> > >
> > > When I call exit(), the logintest.epl exits but main.epl and the rest of
> > > it's children .epl files continue to function.
> > > Does that sound like an expected behavior?
> >
> >I think I experienced the same thing, though I now seem to be able to
> >exit from executed pages properly. I am not sure what the official
> >behavior is sposed to be. However, in terms of just getting it all to
> >work,  what you could try is setting a flag in the $req variable which
> >gets passed to every page, and then test that variable in main.epl. For
> >example:
> >
> >logintest.epl
> >
> >         # Get the req
> >         $req = shift;
> >
> >         # Do tests, we decide to exit
> >         $req->{exit} = 1;
> >
> >main.epl
> >         Execute ('logintest.epl');
> >         $req = shift;
> >         if ($req->{exit})
> >         {
> >                 $http_headers_out{'Location'} = "/login/";
> >                 exit();
> >         }
> >         Execute ('sidenav.epl');
> >
> >If you are calling exit() from the main page, it should work.
> >
> >Hope this helps
> >
> >-Neil
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
> For additional commands, e-mail: embperl-help@perl.apache.org

Re: Stop processing script upon die

Posted by "Marcus R. Popetz" <mp...@netility.com>.
Yep.  That does it.  Thanks.

-mp

ps.  If the powers-that-be have a slightly less verbose way to stop 
processing from within a child script, if you could let the list know, that 
would be cool.


At 10:25 AM 2/28/01, Neil Gunton wrote:
> > My login testing occurs from within an .epl page that is invoked by Execute
> > from within another .epl file.
> >
> > main.epl
> >          Execute( logintest.epl)
> >          <code>
> >          Execute(sidenav.epl)
> >          <code>
> >
> > When I call exit(), the logintest.epl exits but main.epl and the rest of
> > it's children .epl files continue to function.
> > Does that sound like an expected behavior?
>
>I think I experienced the same thing, though I now seem to be able to
>exit from executed pages properly. I am not sure what the official
>behavior is sposed to be. However, in terms of just getting it all to
>work,  what you could try is setting a flag in the $req variable which
>gets passed to every page, and then test that variable in main.epl. For
>example:
>
>logintest.epl
>
>         # Get the req
>         $req = shift;
>
>         # Do tests, we decide to exit
>         $req->{exit} = 1;
>
>main.epl
>         Execute ('logintest.epl');
>         $req = shift;
>         if ($req->{exit})
>         {
>                 $http_headers_out{'Location'} = "/login/";
>                 exit();
>         }
>         Execute ('sidenav.epl');
>
>If you are calling exit() from the main page, it should work.
>
>Hope this helps
>
>-Neil


Re: Stop processing script upon die

Posted by Neil Gunton <ne...@nilspace.com>.
> My login testing occurs from within an .epl page that is invoked by Execute
> from within another .epl file.
> 
> main.epl
>          Execute( logintest.epl)
>          <code>
>          Execute(sidenav.epl)
>          <code>
> 
> When I call exit(), the logintest.epl exits but main.epl and the rest of
> it's children .epl files continue to function.
> Does that sound like an expected behavior?

I think I experienced the same thing, though I now seem to be able to
exit from executed pages properly. I am not sure what the official
behavior is sposed to be. However, in terms of just getting it all to
work,  what you could try is setting a flag in the $req variable which
gets passed to every page, and then test that variable in main.epl. For
example:

logintest.epl

	# Get the req
	$req = shift;

	# Do tests, we decide to exit
	$req->{exit} = 1;

main.epl
	Execute ('logintest.epl');
	$req = shift;
	if ($req->{exit})
	{
		$http_headers_out{'Location'} = "/login/";
		exit();
	}
	Execute ('sidenav.epl');

If you are calling exit() from the main page, it should work.

Hope this helps

-Neil

Re: Stop processing script upon die

Posted by "Marcus R. Popetz" <mp...@netility.com>.
As an additional comment:
I poked around in the source and exit appears to be using structures from 
mod_perl, I'm unable to run under mod_perl due to memory constraints.

     /* from mod_perl's perl_util.c */
     struct ufuncs umg;

-mp

At 10:01 AM 2/28/01, Marcus R. Popetz wrote:
>I originally responded to Neil saying that I was having buffering IO 
>problems when trying this method but I must be working too much...because 
>that was wrong.  I wasn't seeing any output from Embperl which led me to 
>believe that when I was exiting, the contents of http_headers_out were not 
>getting printed.  Something else must have been confusing the matter.
>
>When I went back and retried it this morning, here's what I'm actually seeing:
>
>My login testing occurs from within an .epl page that is invoked by 
>Execute from within another .epl file.
>
>main.epl
>         Execute( logintest.epl)
>         <code>
>         Execute(sidenav.epl)
>         <code>
>
>When I call exit(), the logintest.epl exits but main.epl and the rest of 
>it's children .epl files continue to function.
>Does that sound like an expected behavior?
>
>-mp
>
>At 06:22 PM 2/27/01, Neil Gunton wrote:
>> > What I'm trying to accomplish:
>> >
>> > Someone posts some data.
>> > I detect they are not logged in.
>> > I stop processing (because they might not have privs to do what they are
>> > posting)
>> > I redirect to a login page.
>>
>>What I do here is something like this:
>>
>>         $http_headers_out{'Location'} = "/login/";
>>         exit();
>>
>>HTH
>>
>>-Neil
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
>For additional commands, e-mail: embperl-help@perl.apache.org


Re: Stop processing script upon die

Posted by "Marcus R. Popetz" <mp...@netility.com>.
I originally responded to Neil saying that I was having buffering IO 
problems when trying this method but I must be working too much...because 
that was wrong.  I wasn't seeing any output from Embperl which led me to 
believe that when I was exiting, the contents of http_headers_out were not 
getting printed.  Something else must have been confusing the matter.

When I went back and retried it this morning, here's what I'm actually seeing:

My login testing occurs from within an .epl page that is invoked by Execute 
from within another .epl file.

main.epl
         Execute( logintest.epl)
         <code>
         Execute(sidenav.epl)
         <code>

When I call exit(), the logintest.epl exits but main.epl and the rest of 
it's children .epl files continue to function.
Does that sound like an expected behavior?

-mp

At 06:22 PM 2/27/01, Neil Gunton wrote:
> > What I'm trying to accomplish:
> >
> > Someone posts some data.
> > I detect they are not logged in.
> > I stop processing (because they might not have privs to do what they are
> > posting)
> > I redirect to a login page.
>
>What I do here is something like this:
>
>         $http_headers_out{'Location'} = "/login/";
>         exit();
>
>HTH
>
>-Neil


Re: Stop processing script upon die

Posted by Neil Gunton <ne...@nilspace.com>.
> What I'm trying to accomplish:
> 
> Someone posts some data.
> I detect they are not logged in.
> I stop processing (because they might not have privs to do what they are
> posting)
> I redirect to a login page.

What I do here is something like this:

	$http_headers_out{'Location'} = "/login/";
	exit();

HTH

-Neil

Re: Stop processing script upon die

Posted by Neil Gunton <ne...@nilspace.com>.
"Marcus R. Popetz" wrote:
> 
> At 06:22 PM 2/27/01, you wrote:
> >What I do here is something like this:
> >
> >         $http_headers_out{'Location'} = "/login/";
> >         exit();
> >
> >HTH
> 
> I was having problems with buffered IO in that case.  Did you have to setup
> some option to make Embperl spit out what it had gleaned so far on exit()?

No, I have had no problems with this issue. But it surely shouldn't
matter in this particular case, since you want to immediately stop
processing and effectively go to a completely different page, right? So
why would it matter if existing buffers were flushed (or not)? The
client's browser will be making a new request to the new page anyway...
or am I misunderstanding some aspect of what you're doing here?

-Neil