Skip to content
Browse files

Convert from YAML::Tiny to CPAN::Meta::YAML

  • Loading branch information...
1 parent dcc2784 commit bdd8cde899438c366ccbbc6e37c03aa65b12ff55 @xdg xdg committed Dec 30, 2010
Showing with 52 additions and 88 deletions.
  1. +2 −2 Build.PL
  2. +3 −0 Changes
  3. +0 −37 devtools/update_yamltiny.pl
  4. +5 −9 lib/Module/Build.pm
  5. +1 −1 lib/Module/Build/API.pod
  6. +23 −9 lib/Module/Build/Base.pm
  7. +5 −5 lib/Module/Build/YAML.pm
  8. +1 −4 t/metadata2.t
  9. +7 −11 t/mymeta.t
  10. +1 −4 t/runthrough.t
  11. +4 −6 t/script_dist.t
View
4 Build.PL
@@ -77,7 +77,7 @@ my $build = ModuleBuildBuilder->new(
'Text::ParseWords' => 0,
'Getopt::Long' => 0,
'Test::Harness' => 0,
- 'YAML::Tiny' => 1.40,
+ 'CPAN::Meta::YAML' => 0.002,
# configure_requires repeated here
'Perl::OSType' => 1, # needs 1.0 API
'version' => 0.87, # No longer requires M::B
@@ -152,7 +152,7 @@ my $build = ModuleBuildBuilder->new(
);
$build->create_build_script;
-if (-f "META.yml" && ! -f "MYMETA.yml") { # fallback if we don't have YAML::Tiny
+if (-f "META.yml" && ! -f "MYMETA.yml") { # fallback if we don't have CPAN::Meta::YAML
require File::Copy;
File::Copy::copy("META.yml", "MYMETA.yml") or warn "Error: $!\n";
if ( -f 'MYMETA.yml' ) {
View
3 Changes
@@ -2,6 +2,9 @@ Revision history for Perl extension Module::Build.
0.36_21 -
+ - Changed YAML::Tiny references to the new CPAN::Meta::YAML module
+ instead, which is the YAML-variant that is going into the Perl core
+
0.36_20 - Fri Dec 10 15:36:03 EST 2010
*** DEPRECATIONS ***
View
37 devtools/update_yamltiny.pl
@@ -1,37 +0,0 @@
-#!/usr/bin/env perl
-use strict;
-use warnings;
-
-use Path::Class;
-require YAML::Tiny;
-require PPI;
-require PPI::Dumper;
-
-my $Doc = PPI::Document->new($INC{'YAML/Tiny.pm'});
-$Doc->prune('PPI::Token::Pod');
-$Doc->prune( sub {
- $_[1]->isa('PPI::Statement')
- && $_[1]->first_element->isa('PPI::Token::Symbol')
- && $_[1]->first_element->symbol =~ /EXPORT|ISA/
- }
-);
-$Doc->prune( sub {
- $_[1]->isa('PPI::Statement::Include')
- && $_[1]->child(2)->isa('PPI::Token::Word')
- && $_[1]->child(2)->content eq 'Exporter'
- }
-);
-
-#my $Dumper = PPI::Dumper->new( $Doc );
-#$Dumper->print;
-
-my $content = $Doc->serialize;
-$content =~ s{YAML::Tiny}{Module::Build::YAML}g;
-$content = "# Adapted from YAML::Tiny " . YAML::Tiny->VERSION . "\n$content";
-$content =~ s{^\s+\n(\s+\n)+}{\n}gms;
-
-my $mby = file(qw/lib Module Build YAML.pm/);
-die "Can't find $mby" unless -e $mby;
-my $fh = $mby->openw;
-print {$fh} $content;
-
View
14 lib/Module/Build.pm
@@ -293,17 +293,13 @@ Creates the F<META.yml> file that describes the distribution.
F<META.yml> is a file containing various bits of I<metadata> about the
distribution. The metadata includes the distribution name, version,
abstract, prerequisites, license, and various other data about the
-distribution. This file is created as F<META.yml> in YAML format.
-It is recommended that the C<YAML::Tiny> module be installed to create it.
-If the C<YAML::Tiny> module is not installed, an internal module supplied
-with Module::Build will be used to write the META.yml file, and this
-will most likely be fine.
+distribution. This file is created as F<META.yml> in a simplified YAML format.
F<META.yml> file must also be listed in F<MANIFEST> - if it's not, a
warning will be issued.
-The current version of the F<META.yml> specification can be found at
-L<http://module-build.sourceforge.net/META-spec-current.html>
+The current version of the F<META.yml> specification can be found
+on CPAN as L<CPAN::Meta::Spec>.
=item distsign
@@ -1084,10 +1080,10 @@ modify it under the same terms as Perl itself.
=head1 SEE ALSO
perl(1), L<Module::Build::Cookbook>, L<Module::Build::Authoring>,
-L<Module::Build::API>, L<ExtUtils::MakeMaker>, L<YAML::Tiny>
+L<Module::Build::API>, L<ExtUtils::MakeMaker>
F<META.yml> Specification:
-L<http://module-build.sourceforge.net/META-spec-current.html>
+L<CPAN::Meta::Spec>
L<http://www.dsmit.com/cons/>
View
2 lib/Module/Build/API.pod
@@ -1928,7 +1928,7 @@ modify it under the same terms as Perl itself.
=head1 SEE ALSO
perl(1), L<Module::Build>(3), L<Module::Build::Authoring>(3),
-L<Module::Build::Cookbook>(3), L<ExtUtils::MakeMaker>(3), L<YAML::Tiny>(3)
+L<Module::Build::Cookbook>(3), L<ExtUtils::MakeMaker>(3)
F<META.yml> Specification:
L<http://module-build.sourceforge.net/META-spec-current.html>
View
32 lib/Module/Build/Base.pm
@@ -1642,6 +1642,24 @@ sub _parse_conditions {
}
}
+sub try_require {
+ my ($self, $modname, $spec) = @_;
+ my $status = $self->check_installed_status($modname, defined($spec) ? $spec : 0);
+ return unless $status->{ok};
+ my $path = $modname;
+ $path =~ s{::}{/}g;
+ $path .= ".pm";
+ if ( defined $INC{$path} ) {
+ return 1;
+ }
+ elsif ( exists $INC{$path} ) { # failed before, don't try again
+ return;
+ }
+ else {
+ return eval "require $modname";
+ }
+}
+
sub check_installed_status {
my ($self, $modname, $spec) = @_;
my %status = (need => $spec);
@@ -4470,13 +4488,11 @@ sub read_metafile {
my $self = shift;
my ($metafile) = @_;
- my $status = $self->check_installed_status("YAML::Tiny", 1.4);
- return unless $status->{ok};
- require YAML::Tiny;
+ return unless $self->try_require("CPAN::Meta::YAML", "0.002");
my $string = $self->_slurp($metafile, $] < 5.8 ? "" : ":utf8");
- my $meta = YAML::Tiny->read_string($string)
- or $self->log_warn( "Error parsing '$metafile': " . YAML::Tiny->errstr . "\n");
+ my $meta = CPAN::Meta::YAML->read_string($string)
+ or $self->log_warn( "Error parsing '$metafile': " . CPAN::Meta::YAML->errstr . "\n");
return $meta->[0] || {};
}
@@ -4486,11 +4502,9 @@ sub write_metafile {
my $self = shift;
my ($metafile, $node) = @_;
- my $status = $self->check_installed_status("YAML::Tiny", 1.4);
- return unless $status->{ok};
- require YAML::Tiny;
+ return unless $self->try_require("CPAN::Meta::YAML", "0.002");
- my $yaml = YAML::Tiny->new($node);
+ my $yaml = CPAN::Meta::YAML->new($node);
my $string = $yaml->write_string;
return $self->_spew($metafile, $string, $] < 5.8 ? "" : ":utf8")
}
View
10 lib/Module/Build/YAML.pm
@@ -1,8 +1,8 @@
package Module::Build::YAML;
use strict;
-use YAML::Tiny 1.40 ();
-our @ISA = qw(YAML::Tiny);
-our $VERSION = '1.40';
+use CPAN::Meta::YAML 0.002 ();
+our @ISA = qw(CPAN::Meta::YAML);
+our $VERSION = '1.41';
1;
=head1 NAME
@@ -12,8 +12,8 @@ Module::Build::YAML - DEPRECATED
=head1 DESCRIPTION
This module was originally an inline copy of L<YAML::Tiny>. It has been
-deprecated in favor of using YAML::Tiny directly. This module is kept as a
-subclass wrapper for compatibility.
+deprecated in favor of using L<CPAN::Meta::YAML> directly. This module is kept
+as a subclass wrapper for compatibility.
=cut
View
5 t/metadata2.t
@@ -12,10 +12,7 @@ use DistGen;
############################## ACTION distmeta works without a MANIFEST file
-SKIP: {
- skip( 'YAML::Tiny is not installed', 4 )
- unless eval "require YAML::Tiny; 1";
-
+{
my $dist = DistGen->new( no_manifest => 1 )->chdir_in->regen;
ok ! -e 'MANIFEST';
View
18 t/mymeta.t
@@ -3,12 +3,8 @@
use strict;
use lib 't/lib';
use MBTest;
-if ( eval "require YAML::Tiny; 1" ) {
- plan tests => 25;
-}
-else {
- plan skip_all => "No YAML::Tiny";
-}
+use CPAN::Meta::YAML;
+plan tests => 25;
blib_load('Module::Build');
@@ -60,8 +56,8 @@ $dist->chdir_in;
"Re-ran Build.PL and regenerated MYMETA.yml based on META.yml"
);
- my $meta = YAML::Tiny->read('META.yml')->[0];
- my $mymeta = YAML::Tiny->read('MYMETA.yml')->[0];
+ my $meta = CPAN::Meta::YAML->read('META.yml')->[0];
+ my $mymeta = CPAN::Meta::YAML->read('MYMETA.yml')->[0];
is( delete $mymeta->{dynamic_config}, 0,
"MYMETA 'dynamic_config' is 0"
);
@@ -78,7 +74,7 @@ $dist->chdir_in;
"Ran Build.PL with dynamic config"
);
ok( -e "MYMETA.yml", "MYMETA.yml exists" );
- $mymeta = YAML::Tiny->read('MYMETA.yml')->[0];
+ $mymeta = CPAN::Meta::YAML->read('MYMETA.yml')->[0];
isnt( $meta->{requires}{'File::Spec'},
$mymeta->{requires}{'File::Spec'},
"MYMETA requires differs from META"
@@ -90,14 +86,14 @@ $dist->chdir_in;
# manually change META and check that changes are preserved
$meta->{author} = ['John Gault'];
- ok( YAML::Tiny->new($meta)->write('META.yml'),
+ ok( CPAN::Meta::YAML->new($meta)->write('META.yml'),
"Wrote manually modified META.yml" );
$output = stdout_of sub { $dist->run_build_pl };
like($output, qr/Creating new 'MYMETA.yml' with configuration results/,
"Ran Build.PL"
);
- my $mymeta2 = YAML::Tiny->read('MYMETA.yml')->[0];
+ my $mymeta2 = CPAN::Meta::YAML->read('MYMETA.yml')->[0];
is_deeply( $mymeta2->{author}, [ 'John Gault' ],
"MYMETA preserved META modifications"
);
View
5 t/runthrough.t
@@ -6,7 +6,6 @@ use MBTest tests => 29;
blib_load('Module::Build');
blib_load('Module::Build::ConfigData');
-my $have_yaml = eval "require YAML::Tiny; 1";
#########################
@@ -106,9 +105,7 @@ ok grep {$_ eq 'save_out' } $mb->cleanup;
}
}
-SKIP: {
- skip( 'YAML::Tiny is not available', 7 ) unless $have_yaml;
-
+{
my $output = eval {
stdout_stderr_of( sub { $mb->dispatch('disttest') } )
};
View
10 t/script_dist.t
@@ -7,6 +7,7 @@ use lib 't/lib';
use MBTest 'no_plan';
use DistGen qw(undent);
+use CPAN::Meta::YAML;
blib_load('Module::Build');
blib_load('Module::Build::ConfigData');
@@ -72,10 +73,7 @@ my $result;
stdout_stderr_of( sub { $result = $mb->dispatch('distmeta') } );
ok $result;
-SKIP: {
- skip( 'YAML::Tiny is not installed', 1 )
- unless eval "require YAML::Tiny; 1";
- my $yml = YAML::Tiny::LoadFile('META.yml');
- is_deeply($yml->{provides}, \%meta_provides);
-}
+my $yml = CPAN::Meta::YAML->read_string(slurp('META.yml'))->[0];
+is_deeply($yml->{provides}, \%meta_provides);
+
$dist->chdir_original if $dist->did_chdir;

0 comments on commit bdd8cde

Please sign in to comment.
Something went wrong with that request. Please try again.