It's fine as long as you're exiting right after the redirect. Otherwise the rest of your program will execute. Observe:
#!/usr/bin/perl -w use strict; use CGI "redirect"; print redirect("login.cgi"); print "Here's some stuff that you shouldn't be able to see";
And then we open up telnet and look at what it gives us.
# telnet localhost 80 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. GET /redirect_test.pl HTTP/1.1 Host: localhost HTTP/1.1 302 Moved Date: Wed, 22 Oct 2003 02:23:34 GMT Server: Apache/1.3.26 (Unix) Location: login.cgi Transfer-Encoding: chunked Content-Type: text/plain Here's some stuff that you shouldn't be able to see
It's just something to watch out for.
Note on a matter of style: Since this is a class that is quite possibly being designed for reuse later down the line, I'd highly suggest having the object return undef to signify that authentication failed. Sometimes you may wish for the script to redirect to another page. Other times you may just want it to serve a different page. If you aren't going for reuse and are just looking to personalize the coding style of your scripts to something you like, then this is fine. Just be aware that if someone else later needs to maintain your code, they may attempt to track you down and upon finding you threaten you with a rubber mallet.
Hope this helps.
antirice
The first rule of Perl club is - use Perl
The ith rule of Perl club is - follow rule i - 1 for i > 1
In reply to Re: OO: Leaving a constructor midway?
by antirice
in thread OO: Leaving a constructor midway?
by jest
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |