>Let me start with a confession that I'm a newbie to perl and 
>modules although I've got truckloads of experience on Windows
>ASP side. Anyway, I need a bit of wizdom on how to use 
>packages with Apache::ASP. Please read on.
>
>In my httpd.conf I have 
>
>PerlSetVar UseStrict 1

Definitely keep UseStrict turned on. When I was learning Perl I didn't quite get why 
its useful - now I understand and its definitely a good 
thing to have turned on! 

>then I have a script - called "Login.pl" - that goes like this:
>
><html>
><%
>$Response->Include($Server->MapPath("/pls/Common/consts.pl"),"");
>$Response->Write(blabla()."<BR>");
>$Response->Write("A_VARIABLE=".$A_VARIABLE."<BR>");
>%>
></html>
>
>The contents of /pls/Common/consts.pl is
>
><%
>our $A_VARIABLE = "whatever";
>sub blabla {
>    "blabla";
>}
>%>

What you're after is something like:

        use MyPackageToBeWritten;

or 

        require '/pls/Common/consts.pl';


However with Apache::ASP there is an easier way - and due to some of the quirks of 
mod_perl (I'm _not_ an expert on mod_perl...) a much 
more reliable way:  Put your reusable variables/subs in your global.asa file.


In your instance it'd be something like:

<< global.asa >>

use vars qw( $A_VARIABLE );

sub doSomething
{
        return "blahblah";
}

<< >>


Further to that, if you're looking at doing a login system, I have just recently done 
one that works really nicely - and requires _zero_ code to 
your actual .asp files to ensure that the user is logged in. It may not suit your 
needs, but this is what I added to my global.asa:

<< global.asa >>

sub Script_OnStart
{
    unless ( $Request->ServerVariables( 'SCRIPT_NAME') eq '/login.asp')
    {
        unless ( validateLogin( ))
        {
            my %param = ( 'u'=>$Request->ServerVariables('REQUEST_URI'));
            $Response->Redirect( $Server->URL('/login.asp', \%param ));
        }
    }
}

sub validateLogin
{
    return defined( $Session->{User} );
}

sub doLogin
{
    # This can be called by login.asp when the user presses a "login" button with user 
id/password.

    # Depending how you validate, check the user/password, and store something in 
$Session->{User}
}

<< >>

Your login.asp file is exempt from the check, but every other .asp file will redirect 
to the login script.

Note also that the redirection saves the current request URI - after a successful 
login I redirect back to the users original request.


>Should I really make a separate Perl package out of consts.pl
>and then import the variables from package consts into Login.pl?
>This seems a little absurd because per "PerlSetVar UniquePackages 
>0" in httpd.conf, both Login.pl and consts.pl are in the same 
>package, and there should be a simple way for any script in 
>the package to use variables declared in other scripts of the 
>package. Or am I wrong? Please let me know.
>

Not wrong, just leverage global.asa better and it should make your problems go away. 
If you have extensive modules you can factor them 
out into separate packages but that can be done later.

The ASP gurus on this list may have better suggestions; I'm a bit of a newbie

Ellers



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to