[DCPM] Inside-out object accessor

Darke, Clive Clive.darke at qa.com
Tue Apr 4 03:44:33 PDT 2006


Anyone using inside-out objects?  Arguments for or against the following
generic accessor would be very welcome!   Aside from the usual eval/evil
argument, that is.  It just seems too simple to be true.
 
$self is the reference
$attr is the name of the attribute, and the name of the attribute hash
$value is the value to be set 
  
sub set { 
   my ($self, $attr, $value) = @_; 
   my $key = refaddr $self; 
   my $hashref; 
   eval "\$hashref = \\\%$attr"; 
   
   if ( !defined $hashref ) { 
      carp 'Invalid attribute name'; 
   } 
   else { 
      $hashref->{$key} = $value; 
   } 
} 
 
A 'get' accessor could be similar.
Clive
 
 


________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/devoncornwall-pm/attachments/20060404/d578ec32/attachment.html


More information about the Devoncornwall-pm mailing list