[Module-build-general] Re: [PATCH] Better Makefile.PLs. Property methods.
Status: Beta
Brought to you by:
kwilliams
|
From: Ken W. <ke...@ma...> - 2003-08-12 16:36:26
|
On Sunday, August 10, 2003, at 10:49 PM, Michael G Schwern wrote:
> Instead of DISTNAME, the NAME of the module is taken from module_name.
> MakeMaker needs the NAME of the module more than it needs the DISTNAME.
> It can figure out the DISTNAME from the NAME but its pretty bad about
> going the other way around.
This is kind of tricky - the problem is that there may not be a
'module_name' property, as in the case of LWP or the like.
I don't actually understand the precise semantics of NAME & DISTNAME in
MakeMaker - the docs say that DISTNAME defaults to NAME, but it's
actually adapted with at least s/::/-/ translation. It also says that
NAME will default to "the directory name", but doesn't say which
directory.
> That's part one. 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.
Looks good, applied - though it should be testing $self->{properties},
not $self:
@@ -250,6 +250,17 @@
);
sub valid_property { exists $valid_properties{$_[1]} }
+
+ # Create an accessor for each property that doesn't already have one
+ foreach my $property (keys %valid_properties) {
+ next if __PACKAGE__->can($property);
+ no strict 'refs';
+ *{$property} = sub {
+ my $self = shift;
+ $self->{properties}{$property} = shift if @_;
+ return $self->{properties}{$property};
+ };
+ }
}
-Ken
|