Skip to content

Commit

Permalink
Use intermediate files to store META.* and *.ppd files
Browse files Browse the repository at this point in the history
  • Loading branch information
bingos authored and mohawk2 committed Dec 30, 2014
1 parent 14cbc57 commit b6a9eba
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ MYMETA.*
ExtUtils-MakeMaker-*
inc/
.*.swp
/_eumm
15 changes: 12 additions & 3 deletions lib/ExtUtils/MM_Any.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use File::Basename;
BEGIN { our @ISA = qw(File::Spec); }

# We need $Verbose
use ExtUtils::MakeMaker qw($Verbose);
use ExtUtils::MakeMaker qw($Verbose write_file_via_tmp);

use ExtUtils::MakeMaker::Config;

Expand All @@ -22,6 +22,7 @@ my $Updir = __PACKAGE__->updir;

my $METASPEC_URL = 'https://metacpan.org/pod/CPAN::Meta::Spec';
my $METASPEC_V = 2;
my $STASHDIR = '_eumm';

=head1 NAME
Expand Down Expand Up @@ -365,7 +366,15 @@ at build-time.

sub stashmeta {
my($self, $text, $file) = @_;
$self->echo($text, $file, { allow_variables => 0, append => 0 });
-d $STASHDIR or die "$STASHDIR: $!" unless mkdir $STASHDIR;
my $stashfile = File::Spec->catfile($STASHDIR, $file);
write_file_via_tmp($stashfile, [ $text ]);
my $qlfile = $self->quote_literal($file);
my $qlstashfile = $self->quote_literal($stashfile);
(
sprintf('-$(NOECHO) $(RM_F) %s', $qlfile),
sprintf('-$(NOECHO) $(CP) %s %s', $qlstashfile, $qlfile),
);
}


Expand Down Expand Up @@ -687,7 +696,7 @@ clean :: clean_subdirs
');

my @files = sort values %{$self->{XS}}; # .c files from *.xs files
my @dirs = qw(blib);
my @dirs = qw(blib _eumm);

# Normally these are all under blib but they might have been
# redefined.
Expand Down
35 changes: 22 additions & 13 deletions t/meta_convert.t
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
BEGIN {
chdir '..' if -d '../t';
unshift @INC, 't/lib';
use lib 'lib';
}
#!perl -w

use strict;
use warnings;

BEGIN { unshift @INC, 't/lib'; }
use Test::More;
eval { require CPAN::Meta; };
plan skip_all => 'Failed to load CPAN::Meta' if $@;
plan 'no_plan';

use File::Temp qw[tempdir];
require ExtUtils::MM_Any;

my $tmpdir = tempdir( DIR => 't', CLEANUP => 1 );
chdir $tmpdir or die "chdir $tmpdir: $!";

my $METAJSON = File::Spec->catfile('_eumm', 'META_new.json');

sub ExtUtils::MM_Any::quote_literal { $_[1] }

my $new_mm = sub {
Expand All @@ -33,7 +36,7 @@ my $warn_ok = sub {
return $ret;
};

my $version_regex = qr/version: ''/;
my $version_regex = qr/['"]?version['"]?\s*:\s*['"]['"]/;
my $version_action = "they're converted to empty string";


Expand All @@ -48,7 +51,8 @@ note "Filename as version"; {
qr{Can't parse version 'Recursive.pm'}
);
ok $res, 'we know how to deal with bogus versions defined in Makefile.PL';
like $res, $version_regex, $version_action;
my $content = do { open my $fh, '<', $METAJSON or die "$METAJSON: $!\n"; local $/; <$fh>; };
like $content, $version_regex, $version_action;
}


Expand All @@ -62,7 +66,8 @@ note "'undef' version from parse_version"; {
qr{Can't parse version 'undef'}
);
ok $res, q|when there's no $VERSION in Module.pm, $self->{VERSION} = 'undef'; via MM_Unix::parse_version and we know how to deal with that|;
like $res, $version_regex, $version_action;
my $content = do { open my $fh, '<', $METAJSON or die "$METAJSON: $!\n"; local $/; <$fh>; };
like $content, $version_regex, $version_action;
}


Expand All @@ -78,7 +83,8 @@ note "x.y.z version"; {
qr{Can't parse version '\x00\x00\x03'}
);
ok $res, q|we know how to deal with our $VERSION = 0.0.3; style versions defined in the module|;
like $res, $version_regex, $version_action;
my $content = do { open my $fh, '<', $METAJSON or die "$METAJSON: $!\n"; local $/; <$fh>; };
like $content, $version_regex, $version_action;
}


Expand All @@ -92,7 +98,8 @@ note ".5 version"; {
qr{Can't parse version '.5'}
);
ok $res, q|we know how to deal with our $VERSION = '.5'; style versions defined in the module|;
like $res, $version_regex, $version_action;
my $content = do { open my $fh, '<', $METAJSON or die "$METAJSON: $!\n"; local $/; <$fh>; };
like $content, $version_regex, $version_action;
}


Expand All @@ -108,7 +115,8 @@ note "Non-camel case metadata"; {
);
my $res = eval { $mm->metafile_target };
ok $res, q|we know how to deal with non-camel-cased custom meta resource keys defined in Makefile.PL|;
like $res, qr/x_Repositoryclone/, "they're camel-cased";
my $content = do { open my $fh, '<', $METAJSON or die "$METAJSON: $!\n"; local $/; <$fh>; };
like $content, qr/x_Repositoryclone/, "they're camel-cased";
}


Expand All @@ -126,5 +134,6 @@ note "version object in provides"; {
},
);
my $res = eval { $mm->metafile_target };
like $res, qr{version: \s* v1.2.3}x;
my $content = do { open my $fh, '<', $METAJSON or die "$METAJSON: $!\n"; local $/; <$fh>; };
like $content, qr/['"]?version['"]?\s*:\s*['"]v1\.2\.3['"]/;
}

0 comments on commit b6a9eba

Please sign in to comment.