Re: Coding Style Question - Using exit

2003-08-19 Thread Thomas Klausner
Hi!

On Mon, Aug 18, 2003 at 08:07:30 -0400, Chris Faust wrote:

 Example To Help Explain:
 
 sub handler {
  $r = shift;
 
 init_global_vals();
 
 $back_url = determine_proper_action();
 
 my $back_url = ;
 $r-headers_out-set(Location = $back_url);

 return Apache::REDIRECT;
 }

Why not let determine_proper_action() return undef (or OK, or whatever) if
you do not want to redirect? And in your handler do:

  my $rv=determine_proper_action();
  if ($rv) {  # or ($rv == Apache::Constants::OK)
 # redirect
  } else 
# done
  }

One problem I can see is if you're exiting somewhere deep in a nested sub
and you cannot propagate the return value back to the handler (easily).


-- 
#!/usr/bin/perl   http://domm.zsi.at
for(ref bless{},just'another'perl'hacker){s-:+-$-gprint$_.$/}


-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html



Re: Coding Style Question - Using exit

2003-08-19 Thread Chris Faust
Thanks for the reply Thomas,

 Why not let determine_proper_action() return undef (or OK, or whatever) if
 you do not want to redirect? And in your handler do:

   my $rv=determine_proper_action();
   if ($rv) {  # or ($rv == Apache::Constants::OK)
  # redirect
   } else
 # done
   }

 One problem I can see is if you're exiting somewhere deep in a nested sub
 and you cannot propagate the return value back to the handler (easily).



That seems to be working well, I've changed that part of the handler to:

**
 ($request_type,$back_url) = determine_proper_action();

 # Properly Exit the Handler from all subs within Determine Proper Action
 if ($request_type eq 'Apache::REDIRECT') {
  $r-headers_out-set(Location = $back_url);
return Apache::REDIRECT;
 } else {
  return Apache::OK;
 }
*
Then in every sub within determine_proper_action I'm returning either
Apache::OK or Apache::REDIRECT.

Still got a lot of testing to do, but so far I've been able to get rid of
all exits from my script!

Thanks
-Chris




-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html



Coding Style Question - Using exit

2003-08-18 Thread Chris Faust



Folks,

In the continuing effort to make my code better, 
I'm trying to get rid"exit" in my scripts and clean up some things that 
just don't sit well (but they work).

Almost 95% of my pages are served up via a template 
system (H::T) and the rest are a redirects.
Currently I use a subroutine that all my other subs 
pass content to, to display my templates- at the end of this sub I call 
"exit" so I do not go any further.
In the case where I want to redirect to a URL, I 
then "return" to the handler with the URL.

Although it works, it doesn't seem right to 
me..

Example To Help Explain:

sub handler {$r = shift;
init_global_vals();

$back_url = determine_proper_action();

my $back_url = 
"";$r-headers_out-set(Location = 
$back_url);return Apache::REDIRECT;
}

"Determine proper action" is a dispatch list of all 
the subroutines that make up the script, including the sub where I display the 
templates and exit.
So for almost 95% of my requests, I'm "exiting" 
within determine_proper_action().

Does that make sense? Is it a bad 
thing?

Thanks
-Chris