I can make the files be FromCode files and add them in the FileGatherer
phase, but they still cannot be munged by PkgVersion (or anything)
because they are FromCode files. I'm not sure if that's any better than
before.
From 64199bea318d4add5e4eff1e2cdbdad31bc481e2 Mon Sep 17 00:00:00 2001
From: Mike Doherty <doherty@cs.dal.ca>
Date: Sat, 14 Jul 2012 01:09:03 -0300
Subject: [PATCH] Generate FromCode files during FileGatherer phase
Previously, this plugin didn't play nicely with PkgVersion, for
example, because the files were injected too late. Now, we create
FromCode files and inject them early (in the FileGatherer phase).
Resolves RT #76496: [Conflicts] does not cooperate with [Test::Version] and [PkgVersion]
---
Changes | 3 +
lib/Dist/Zilla/Plugin/Conflicts.pm | 128 +++++++++++++++++-------------------
2 files changed, 63 insertions(+), 68 deletions(-)
diff --git a/Changes b/Changes
index 5f44490..010e307 100644
--- a/Changes
+++ b/Changes
@@ -1,5 +1,8 @@
{{$NEXT}}
+- RT #76496: Build the injected files as FromCode files during the
+ FileGatherer phase (Mike Doherty)
+
0.08 2011-07-22
- Add Dist::CheckConflicts to both configures and runtime dependency lists for
diff --git a/lib/Dist/Zilla/Plugin/Conflicts.pm b/lib/Dist/Zilla/Plugin/Conflicts.pm
index bb241b5..07c0c24 100644
--- a/lib/Dist/Zilla/Plugin/Conflicts.pm
+++ b/lib/Dist/Zilla/Plugin/Conflicts.pm
@@ -5,7 +5,7 @@ use warnings;
use Dist::CheckConflicts 0.01 ();
use Moose::Autobox 0.09;
-
+use Dist::Zilla::File::FromCode;
use Moose;
with qw(
@@ -13,6 +13,7 @@ with qw(
Dist::Zilla::Role::MetaProvider
Dist::Zilla::Role::PrereqSource
Dist::Zilla::Role::TextTemplate
+ Dist::Zilla::Role::FileGatherer
);
has _conflicts => (
@@ -89,20 +90,6 @@ sub register_prereqs {
);
}
-# This should be done in the file gatherer stage, but that happens _before_
-# prereqs are registered, and we can't generate our conflict module until
-# after we know all the prereqs.
-after register_prereqs => sub {
- my $self = shift;
-
- $self->add_file( $self->_build_conflicts_file() );
-
- $self->add_file( $self->_build_script() )
- if $self->_has_script();
-
- return;
-};
-
my $conflicts_module_template = <<'EOF';
package # hide from PAUSE
{{ $module_name }};
@@ -121,42 +108,7 @@ use Dist::CheckConflicts
1;
EOF
-sub _build_conflicts_file {
- my $self = shift;
-
- my $conflicts = $self->_conflicts();
-
- my $conflicts_dump = join ",\n ",
- map {qq['$_' => '$conflicts->{$_}']} sort keys %{$conflicts};
-
- my $also_dump = join "\n ",
- sort grep { $_ ne 'perl' }
- map { $_->required_modules() }
- $self->zilla()->prereqs()->requirements_for(qw(runtime requires));
-
- $also_dump
- = ' -also => [ qw(' . "\n"
- . ' '
- . $also_dump . "\n"
- . ' ) ],' . "\n"
- if length $also_dump;
-
- ( my $dist_name = $self->zilla()->name() ) =~ s/-/::/g;
-
- my $content = $self->fill_in_string(
- $conflicts_module_template, {
- dist_name => \$dist_name,
- module_name => \( $self->_conflicts_module_name() ),
- conflicts_dump => \$conflicts_dump,
- also_dump => \$also_dump,
- },
- );
- return Dist::Zilla::File::InMemory->new(
- name => $self->_conflicts_module_path(),
- content => $content,
- );
-}
# If dzil sees this string PODXXXX anywhere in this code it uses that as the
# name for the module.
@@ -185,23 +137,6 @@ else {
EOF
$script_template = sprintf( $script_template, $podname_hack );
-sub _build_script {
- my $self = shift;
-
- ( my $filename = $self->_script() ) =~ s+^.*/++;
- my $content = $self->fill_in_string(
- $script_template, {
- filename => \$filename,
- module_name => \( $self->_conflicts_module_name() ),
- },
- );
-
- return Dist::Zilla::File::InMemory->new(
- name => $self->_script(),
- content => $content,
- );
-}
-
# XXX - this should really be a separate phase that runs after InstallTool
sub setup_installer {
my $self = shift;
@@ -216,7 +151,64 @@ sub setup_installer {
}
return;
-};
+}
+
+sub gather_files {
+ my $self = shift;
+ my $zilla = $self->zilla;
+
+ my $module = Dist::Zilla::File::FromCode->new({
+ name => $self->_conflicts_module_path,
+ code => sub {
+ my $conflicts = $self->_conflicts();
+
+ my $conflicts_dump = join ",\n ",
+ map {qq['$_' => '$conflicts->{$_}']} sort keys %{$conflicts};
+
+ my $also_dump = join "\n ",
+ sort grep { $_ ne 'perl' }
+ map { $_->required_modules() }
+ $self->zilla()->prereqs()->requirements_for(qw(runtime requires));
+
+ $also_dump
+ = ' -also => [ qw(' . "\n"
+ . ' '
+ . $also_dump . "\n"
+ . ' ) ],' . "\n"
+ if length $also_dump;
+
+ ( my $dist_name = $self->zilla()->name() ) =~ s/-/::/g;
+
+ return $self->fill_in_string(
+ $conflicts_module_template, {
+ dist_name => \$dist_name,
+ module_name => \( $self->_conflicts_module_name() ),
+ conflicts_dump => \$conflicts_dump,
+ also_dump => \$also_dump,
+ },
+ );
+ }, # end sub
+ });
+ $self->add_file($module);
+ warn "added module: $module at @{[ $self->_conflicts_module_path ]}";
+
+ if ($self->_has_script) {
+ my $script = Dist::Zilla::File::FromCode->new({
+ name => $self->_script(),
+ code => sub {
+ ( my $filename = $self->_script() ) =~ s+^.*/++;
+ return $self->fill_in_string(
+ $script_template, {
+ filename => \$filename,
+ module_name => \( $self->_conflicts_module_name() ),
+ },
+ );
+ }, # end sub
+ });
+ $self->add_file($script);
+ warn "added script: $script";
+ }
+}
sub _munge_makefile_pl {
my $self = shift;
--
1.7.9.5