> Anyway, what you should do is create a constructor:
> 
> sub new {
>   my $class = shift;
>   my $self {@_};
>   bless $self, $class;
>   return $self;
> }

You mean like this code segment that I included in my original post
just below the handler code :)

sub init {
  my $invocant = shift;
  my $class = ref ($invocant) || $invocant;
  my $self = {};
  bless ($self, $class);

  $self->{config}    = $self->init_config;
  $self->{dispatch}  = $self->init_dispatch_table;
  $self->{templates} = $self->init_templates;
  $self->{_child_started_up} = 0;
  
  return $self;
}

 ... straight out of "Programming Perl" ...

> 
> Then rewrite the above snippet of your code to:
> 
> sub handler ($$) {
>   my ($class, $q) = @_;
>   my $r = Apache::Request->new($q);
>   my $self = $class->new(request=>$r);
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    Hunh?!?

Wait a second.  I have a startup.pl, and inside that I have the lines:

use Exchange::Account::My;
my $account_interface = Exchange::Account::My->init;

Won't that do what I need it to do?  When the root process forks off
children, won't a complete copy of $account_interface go with it, with
everything all set and ready to go?

>   $self->child_init unless $self->{_child_started_up};
>   # The rest of the code...
> 
> Then you should be good to go (instance variables and all!).  Hope that
> helps,
> 
> Chris

Except for calling the contructor with every call of the handler, 
I think I've done everything right.  Isn't the part of idea behind 
mod_perl handlers that one _doesn't_ have to call the contructor 
_every_ time the handler gets called?  Otherwise invites massive 
overhead.

Obviously, what I'm doing doesn't work.  But could someone show me 
how to call the constructor just once in in a childs lifetime?  
Please?

  --Christopher

Reply via email to