Re: [Module-build-general] [PATCH] Better Makefile.PLs. Property methods.
Status: Beta
Brought to you by:
kwilliams
|
From: Steve P. <sp...@qu...> - 2003-08-11 10:16:24
|
On Monday, August 11, 2003, at 09:35 am, Michael G Schwern wrote:
> [snip]
> Part two stems from when I tried to replace
> $build->dist_name with $build->module_name I got an error, no such
> method.
> Since it seems rather arbitrary whether or not one accesses a property
> as a method or as a hash element, I threw in a little bit of code to
> automaticly generate simple accessor methods for all the properties
> which
> don't already have one. So $build->module_name DWIM now.
Excellent idea - I've been wondering why there's so much direct access
of instance variables in a module that's designed to be sub-classed.
If there's no reason, maybe the next step is to replace all instances
of $self->{<valid property>} ?
Can I also suggest a slight variation on the accessor methods to return
$self in 'set' context, ie:
*{$property} = sub {
my $self = shift;
if (@_) { $self->{$property} = $_[0]; return $self; }
else { return $self->{$property}; }
};
# means I can do this:
$self->module_name( 'Foo' )
->install_base( '/home/foo' );
-Steve
|