Permalink
Browse files

Discourage use of Makefile for dist, manifest targets. Actually, it m…

…akes it impossible.
  • Loading branch information...
1 parent 2ba05b1 commit 0903319fe2d56274f917d6fea95ef73f2b26a4b7 @AndyA AndyA committed Jan 24, 2010
Showing with 53 additions and 0 deletions.
  1. +53 −0 Makefile.PL
View
53 Makefile.PL
@@ -40,3 +40,56 @@ sub test_via_harness {
return $self->SUPER::test_via_harness(
qq{$perl "-I\$(INST_LIB)" "-I\$(INST_ARCHLIB)"}, $tests );
}
+
+BEGIN {
+ my %deny = (
+ manifest => 'dist_basics',
+ dist => 'dist_core',
+ );
+ while ( my ( $verb, $override ) = each %deny ) {
+ my $super = "SUPER::$override";
+ no strict 'refs';
+ *{"MY::$override"} = sub {
+ my ( $self, @args ) = @_;
+ my $frag = $self->$super(@args);
+ my $chunk = split_makefile_chunk($frag);
+ replace_rule(
+ $chunk, $verb,
+ ":\n\t\$(NOECHO) \$(ECHO) "
+ . "\"Please use 'Build.PL $verb' instead of 'Makefile.PL $verb'\"\n\n"
+ );
+ return join_makefile_chunk($chunk);
+ };
+ }
+}
+
+# Returns a reference to a hash containing
+# targets a reference to an array of makefile section names
+# sections a reference to a hash mapping makefile section names to the
+# text of those sections.
+
+sub split_makefile_chunk {
+ my $chunk = shift;
+ my $target = ' prefix';
+ my @targets = ();
+ my %sections = ();
+ for my $ln ( split /\n/, $chunk ) {
+ if ( $ln =~ /^(\S+)/ ) {
+ $target = $1;
+ push @targets, $target;
+ }
+ $sections{$target} .= "$ln\n";
+ }
+ return { targets => \@targets, sections => \%sections };
+}
+
+sub join_makefile_chunk {
+ my $chunk = shift;
+ return join '', grep defined,
+ map { $chunk->{sections}{$_} } @{ $chunk->{targets} };
+}
+
+sub replace_rule {
+ my ( $chunk, $name, $body ) = @_;
+ $chunk->{sections}{$name} = "$name $body";
+}

0 comments on commit 0903319

Please sign in to comment.