[Module-build-general] [PATCH] Better Makefile.PLs. Property methods.
Status: Beta
Brought to you by:
kwilliams
|
From: Michael G S. <sc...@po...> - 2003-08-11 09:23:24
|
The following patch does two things. First, the primary purpose, is to make the Makefile.PLs generated by Module::Build::Compat a bit cleaner. 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. The odd indentation was removed, might look good inside Compat.pm but it looks odd in the resulting Makefile.PL and that's what really matters. The unnecessary quotes around the key names has been removed for purely aesthetic reasons. Hash values are lined up for easier reading. Added a comment about this being generated by Module::Build::Compat so people don't go patching the Makefile.PL and sending it off to the author like I was about to do. 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. -- Michael G Schwern sc...@po... http://www.pobox.com/~schwern/ I can't give you any knowledge, but who wants candy?? -- http://www.angryflower.com/drawin.gif --- ./lib/Module/Build/Base.pm 2003/08/11 03:40:24 1.1 +++ ./lib/Module/Build/Base.pm 2003/08/11 03:41:24 @@ -235,6 +235,17 @@ ); sub valid_property { exists $valid_properties{$_[1]} } + + # Create an accessor for each property that doesn't already have one + no strict 'refs'; + foreach my $property (keys %valid_properties) { + next if __PACKAGE__->can($property); + *{$property} = sub { + my $self = shift; + $self->{$property} = $_[0] if @_; + return $self->{$property}; + }; + } } # XXX Problem - if Module::Build is loaded from a different directory, @@ -1298,7 +1309,7 @@ } return $self->{properties}{script_files}; } -*scripts = \&script_files; +BEGIN { *scripts = \&script_files; } sub valid_licenses { return { map {$_, 1} qw(perl gpl artistic lgpl bsd open_source unrestricted restrictive unknown) }; --- ./lib/Module/Build/Compat.pm 2003/08/11 03:30:57 1.1 +++ ./lib/Module/Build/Compat.pm 2003/08/11 03:46:20 @@ -68,16 +68,20 @@ delete $prereq{perl}; my $prereq = join '', map "\t\t\t'$_' => '$prereq{$_}',\n", keys %prereq; - printf {$fh} <<'EOF', $build->dist_name, $build->dist_version, $prereq; - use ExtUtils::MakeMaker; - WriteMakefile - ('DISTNAME' => '%s', - 'VERSION' => '%s', - 'PL_FILES' => {}, - 'PREREQ_PM' => { + printf {$fh} <<'EOF', $build->module_name, $build->dist_version, $prereq; +# Generated by Module::Build::Compat->create_makefile_pl + +use ExtUtils::MakeMaker; + +WriteMakefile + ( + NAME => '%s', + VERSION => '%s', + PL_FILES => {}, + PREREQ_PM => { %s }, - ); + ); EOF } } |