Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have a question regarding 'my' and 'bless' inside registry scripts. Would the follwing be safe to do inside a registry script:
my $self = {}; bless $self; $self->config; sub config { my $self = shift; }

Replies are listed 'Best First'.
Re: Registry scripts using bless
by John M. Dlugosz (Monsignor) on Nov 13, 2001 at 22:46 UTC
    What do you mean by a "registry script"?
      By Registry script I am refering to mod_perl (Apache::Registry)
Re: Registry scripts using bless
by perrin (Chancellor) on Nov 13, 2001 at 23:53 UTC
    It probably will work, at least it would work as well as any other subroutine does in a Registry script. However, it seems pretty strange to me, using an auto-generated package name and subs defined within other subs when doing OO. If you want to do OO, why don't you just use a PerlHandler? It's easy and saves you from questions likes this.
      These examples are from code written almost a year ago. Migrating from registry scripts to handlers is a "rainy-day" project (we have a very small team and LOT of work on our plate - all new development is done with PerlHandlers but we don't have time to rewrite old code). I was worried about the 'my' in particular because we all know the following is not good in mod_perl registry scripts:
      my $counter; &do_something; sub do_something { $counter++; }
       use vars '$counter' is needed to make this global... I was worried I would have to  use vars '$self' Since I'm using my $self = shift in the subroutines I figured things would be safe and wanted to double check with you folks. Thanks
        It should be okay. If you have problems, make sure you didn't miss any declarations of my $self in the subroutines.