I've been pondering the use of lock_keys() in object constructors, to
make the objects a bit more strict; giving the same sort of advantages
on hash keys for an object as "use strict" does for variables.

I can so far think up two reasons why one might not want to do this:

 a) Only works on >= 5.8.0; so 5.6.x fails

 b) Makes it harder to subclass.

I can think of a number of workarounds for subclassing, but none of them
seem overly neat offhand. Mostly they'd involve something like:

 sub new
 {
    my $class = shift;

    my $self = bless { }, $class;
    $self->_init( @_ );

    lock_keys( %$self );

    return $self;
 }

Then actually do all of the object initialisation in a subclass chain of
sub _init { ... } methods.

Anyone have anything better?

-- 
Paul "LeoNerd" Evans

[EMAIL PROTECTED]
ICQ# 4135350       |  Registered Linux# 179460
http://www.leonerd.org.uk/

Attachment: signature.asc
Description: Digital signature

Reply via email to