forked from miyagawa/Module-Install-CPANfile
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
218 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
use strict; | ||
use warnings; | ||
use Test::More; | ||
use xt::Util; | ||
|
||
note explain my $meta_data = make_meta_data(*DATA); | ||
|
||
subtest requires => sub { | ||
my $requires = $meta_data->{requires}; | ||
is $requires->{Plack}, '0.9986'; | ||
is $requires->{'SQL::Maker'}, 0; | ||
}; | ||
|
||
subtest recommends => sub { | ||
my $recommends = $meta_data->{recommends}; | ||
is $recommends->{'JSON::XS'}, '2.0'; | ||
is $recommends->{'Test::TCP'}, '1.12'; | ||
}; | ||
|
||
done_testing; | ||
|
||
__DATA__ | ||
@@ Makefile.PL | ||
use inc::Module::Install; | ||
cpanfile; | ||
name 'Dummy'; | ||
all_from 'lib/Dummy.pm'; | ||
tests 't/*.t'; | ||
auto_include; | ||
WriteAll; | ||
@@ cpanfile | ||
requires 'Plack' => '0.9986'; | ||
requires 'SQL::Maker'; | ||
recommends 'JSON::XS', '2.0'; | ||
on 'test' => sub { | ||
requires 'Test::More', '>= 0.96, < 2.0'; | ||
recommends 'Test::TCP', '1.12'; | ||
}; | ||
@@ lib/Dummy.pm | ||
package Dummy; | ||
use 5.006; | ||
our $VERSION = '0.1'; | ||
1; | ||
__END__ | ||
=pod | ||
=head1 AUTHOR | ||
Tatsuhiko Miyagawa E<lt>miyagawa@bulknews.netE<gt> | ||
=head1 COPYRIGHT | ||
Copyright 2012- Tatsuhiko Miyagawa | ||
=head1 LICENSE | ||
This library is free software; you can redistribute it and/or modify | ||
it under the same terms as Perl itself. | ||
=cut |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use strict; | ||
use warnings; | ||
use Test::More; | ||
use xt::Util; | ||
use Test::Requires 'Module::Install::AuthorRequires'; | ||
|
||
eval { make_meta_data(*DATA) }; | ||
like $@, qr/\QCan't find author dependency Dummmmmmmmmmmmmmmmmy\E/; | ||
|
||
done_testing; | ||
|
||
__DATA__ | ||
@@ Makefile.PL | ||
use inc::Module::Install; | ||
cpanfile; | ||
name 'Dummy'; | ||
all_from 'lib/Dummy.pm'; | ||
tests 't/*.t'; | ||
auto_include; | ||
WriteAll; | ||
@@ cpanfile | ||
on 'develop' => sub { | ||
requires 'Dummmmmmmmmmmmmmmmmy'; | ||
}; | ||
@@ lib/Dummy.pm | ||
package Dummy; | ||
use 5.006; | ||
our $VERSION = '0.1'; | ||
1; | ||
__END__ | ||
=pod | ||
=head1 AUTHOR | ||
Tatsuhiko Miyagawa E<lt>miyagawa@bulknews.netE<gt> | ||
=head1 COPYRIGHT | ||
Copyright 2012- Tatsuhiko Miyagawa | ||
=head1 LICENSE | ||
This library is free software; you can redistribute it and/or modify | ||
it under the same terms as Perl itself. | ||
=cut |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package xt::Util; | ||
|
||
use strict; | ||
use warnings; | ||
use Test::Builder; | ||
use File::Temp qw(tempdir); | ||
use File::Path qw(mkpath); | ||
use File::Basename qw(dirname); | ||
use Cwd qw(getcwd); | ||
use Config qw(%Config); | ||
use YAML::Tiny; | ||
use Capture::Tiny qw(capture_merged); | ||
use base qw(Exporter); | ||
|
||
use constant DMAKE => $^O eq 'MSWin32' && $Config{make} =~ /dmake(?:\.exe)?$/i; | ||
use constant NMAKE => $^O eq 'MSWin32' && $Config{make} =~ /nmake(?:\.exe)?$/i; | ||
use constant MAKE => $Config{make} || 'make'; | ||
|
||
our @EXPORT = qw/make_meta_data unpack_tree build run_make DMAKE NMAKE/; | ||
|
||
sub make_meta_data { | ||
my $fh = shift; | ||
|
||
local $ENV{PERL5LIB} = join $Config{path_sep}, | ||
map { File::Spec->rel2abs($_) } @INC; | ||
|
||
my $cwd = getcwd; | ||
my $tmpdir = tempdir CLEANUP => 1; | ||
chdir $tmpdir or die $!; | ||
|
||
unpack_tree($fh); | ||
|
||
my $yaml = eval { | ||
build($cwd); | ||
YAML::Tiny->read('META.yml'); | ||
}; | ||
chdir $cwd or die $!; | ||
|
||
die $@ if $@; | ||
|
||
return $yaml->[0]; | ||
} | ||
|
||
sub build { | ||
my $distdir = shift; | ||
die "Makefile.PL not found" unless -f 'Makefile.PL'; | ||
my $tb = Test::Builder->new; | ||
$tb->note( run_cmd(qq{$^X Makefile.PL}) ); | ||
run_make(); | ||
} | ||
|
||
sub run_cmd { | ||
my ($cmd) = @_; | ||
my $result = capture_merged { | ||
system $cmd; | ||
}; | ||
die "`$cmd` failed ($result)" if $?; | ||
return $result; | ||
} | ||
|
||
sub run_make { | ||
run_cmd(join ' ', MAKE, @_); | ||
} | ||
|
||
sub _parse_data { | ||
my $fh = shift; | ||
my ($data, $path); | ||
while (<$fh>) { | ||
if (/^\@\@/) { | ||
($path) = $_ =~ /^\@\@ (.*)/; | ||
next; | ||
} | ||
$data->{$path} .= $_; | ||
} | ||
close $fh; | ||
return $data; | ||
} | ||
|
||
sub unpack_tree { | ||
my $data = _parse_data(shift); | ||
|
||
for my $path (keys %$data) { | ||
my $dir = dirname($path); | ||
unless (-e $dir) { | ||
mkpath($dir) or die "Cannot mkpath '$dir': $!"; | ||
} | ||
|
||
my $content = $data->{$path}; | ||
open my $out, '>', $path or die "Cannot open '$path' for writing: $!"; | ||
print $out $content; | ||
close $out; | ||
} | ||
} | ||
|
||
sub _regex { | ||
my @target = @_; | ||
my $regex = join '|', @target; | ||
return qr/$regex/; | ||
} | ||
|
||
1; | ||
__END__ |