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 13:08:37
|
On Monday, August 11, 2003, at 01:21 pm, Michael G Schwern wrote:
> On Mon, Aug 11, 2003 at 11:02:29AM +0100, Steve Purkis wrote:
>> 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' );
>
> $self->module_name( 'Foo' );
> $self->install_base( '/home/foo' );
>
> It doesn't buy much.
Yeah, I just find it easier to read, especially when you get into the
habit of doing it by default. In spurkis-land, I imagine using M::B
like this:
my $m = Module::Build->new
->module_name( 'Foo' )
->install_base( 'bar' )
->...etc...
->create_build_script
->dispatch( 'config' );
And internally, something like this:
sub ACTION_code {
my $self = shift;
$self->create_blib_arch
->autosplit_blib
->process_PL_files
->compile_support_files
->process_pm_files
->process_xs_files
->process_pod_files
->process_script_files
->_call_action( 'docs' );
}
It's great - at a high level it's almost like writing a todo list. But
maybe I'm dreaming in agfa-colour ;).
> And it means you can't simultaneously set and get.
>
> do_this if $self->module_bleh( $foo );
True, but I'd try to avoid that by checking $foo first anyway. Or
maybe do:
$self->module_bleh( $foo ) and do_this if $foo;
But I didn't mean to turn this into a debate about style - I really am
easy either way. Having accessor methods is the important thing.
-Steve
|