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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.