> Subject: Help: Can't use string ("Exchange::Account::My") as
> a HASH ref
> while "strict refs" in use trying to use instance variables in my
> handler
[snip]
> sub handler ($$) {
> my ($self, $q) = @_;
>
> my $r = Apache::Request->new($q);
>
> $self->child_init unless $self->{_child_started_up}; # <==== dies
> here!
[snip]
I think that you really need to have a legitimate constructor, not one that
is called conditionally. $self is not a blessed reference - just a string
containing the class name. The call to $self->child_init works, even with
strict refs, because there is a child_init subroutine defined in your
package's namespace. With $self->{_child_started_up}, you're just calling
"Exchange::Account::My"->{_child_started_up}, which will cause the error
since the string "Exchange::Account::My" is not a reference to a hash, it's
just a string.
Anyway, what you should do is create a constructor:
sub new {
my $class = shift;
my $self {@_};
bless $self, $class;
return $self;
}
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);
$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