It sounds like you're looking for some #DEFINE functionality or
something.  I'd advise against this, since it can get pretty baroque
pretty fast.

The best way to do this is to create a subroutine and call the
subroutine.  The subroutine may or may not be in some other package
(namespace), and it may or may not be in some other file (module).

In addition, you should avoid calling exit() under mod_perl, because the
process is persistent.  So I'd do something like this if I were you:

sub check_session {
  use vars qw(%session);
  eval { tie %session, 'Apache::Session::File', $authid, 
         { Directory => '/tmp/sessions' } 
       };
  if ($@) {
    print redirect("LOGIN.pl?CAUSE=FailedSessionTie")
  } elsif (time() > $session{expire_time}) {
    print redirect("LOGIN.pl?CAUSE=TIMED_OUT")
  } else {
    $session{expire_time} = time() + SURVEYDESIGN::survey_expire();
    return 1;
  }
  return;
}




[EMAIL PROTECTED] (Daniel Hutchison) wrote:
>Basically I'm a bit stumped by how perl lets us reuse code snippets.  I
>can't seem to bend modules to what I need to do exactly:
>
>I'm using Apache and mod_perl.  Each perl script will produce a dynamic web
>page.  Now, with each script I need to recover the session variables I'm
>saving (using Apache:Session:File) and also verify account name and
>password:
>
>############################################################################
>#####
>use vars qw(%session);
>eval { tie %session, 'Apache::Session::File', $authid, { Directory =>
>'/tmp/sessions' } };
>if ($@) { print redirect("LOGIN.pl?CAUSE=FailedSessionTie"); exit; }
>if (time() > $session{expire_time}) { print
>redirect("LOGIN.pl?CAUSE=TIMED_OUT"); exit; }
>$session{expire_time} = time() + SURVEYDESIGN::survey_expire();
>############################################################################
>#####
>
>Basically this chuck of code that I want to replicate across scripts is
>going to grow/shrink/change rapidly in the coming weeks as I toy with the
>project.
>
>My problem seems to be that I can not include/inherit a chunk of text, but
>rather need to place code in a separate package for reuse.  But I don't see
>how that allows me to recover sessions and setup variables in the main
>package.
>
>Any input (or a redirection to a good FAQ) would be very welcome!  Thanks.
>
>Daniel Hutchison
>Target Analysis Group
>mailto:[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> 
>617.583.8411
>

  -------------------                            -------------------
  Ken Williams                             Last Bastion of Euclidity
  [EMAIL PROTECTED]                            The Math Forum


Reply via email to