Perl-Toolchain-Gang / ExtUtils-MakeMaker

Perl module to make Makefiles and build modules (what backs Makefile.PL)
https://metacpan.org/release/ExtUtils-MakeMaker
64 stars 77 forks source link

Cannot override pm_to_blib in Makefile.PL #422

Closed sidney closed 2 years ago

sidney commented 2 years ago

I have not been able to override the pm_to_blib method after reducing to the following simplified test case.

I created a small test module by running

h2xs -ACPX -n Hello::World -v 1.0

I then edited the generated Makefile.pl to add the following at the end, which overrides both c_o and pm_to_blib based on the perldoc example for overriding c_o.

use Carp;
package MY;

sub c_o {
  my $self = shift;
  my $inherited = $self->SUPER::c_o(@_);
  $inherited = "# This was modified\n$inherited";
  Carp::cluck  "MY::c_o was called";
  $inherited;
}

sub pm_to_blib {
  my $self = shift;
  my $inherited = $self->SUPER::pm_to_blib(@_);
  $inherited = "# This was modified\n$inherited";
  Carp::cluck  "MY::pm_to_blib was called";
  $inherited;
}

When I run perl Makefile.PL the output shows that MY::c_o was called as expected, but not MY::pm_to_blib

The cluck output in MY::c_o showed that it was called with $self being a package named PACK001. When I change sub pm_to_lib to sub PACK001::pm_to_lib then it does get called, although of course that is not a proper workaround.

I tried this both on macOS with perl 5.34.0 ExtUtils::MakeMaker version 7.62 and on Ubuntu with perl 5.36.0 ExtUtils::MakeMaker 7.64 with no change in results.

Looking in the source code and adding debugging logging, I see that both c_o and pm_to_blib are defined in MM_UNIX.pm the same way, and they are both called by the same lines of code that are in a loop in MakeMaker.pm with the same PACK001 package object in $self, so I can't see why they should act different.

haarg commented 2 years ago

There is a fixed set of methods that are overridable via MY. pm_to_blib is not included in that list. The code (https://github.com/Perl-Toolchain-Gang/ExtUtils-MakeMaker/blob/master/lib/ExtUtils/MakeMaker.pm#L380-L384) makes it look like it is intentionally excluded, but it's not at all obvious why.

sidney commented 2 years ago

Ah, I missed how pm_to_blib and self_document are in the middle there being left out of @Overridable when everything else is being put in it. I guess I'll close this as intended behavior for some reason. Thanks.