r67957 - in /branches/upstream/libparse-cpan-meta-perl/current: ./ lib/Parse/CPAN/ t/ t/data/ t/lib/Parse/CPAN/Meta/
periapt-guest at users.alioth.debian.org
periapt-guest at users.alioth.debian.org
Thu Jan 27 21:24:22 UTC 2011
Author: periapt-guest
Date: Thu Jan 27 21:23:56 2011
New Revision: 67957
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=67957
Log:
[svn-upgrade] new version libparse-cpan-meta-perl (1.4200)
Added:
branches/upstream/libparse-cpan-meta-perl/current/t/02_api.t
branches/upstream/libparse-cpan-meta-perl/current/t/03_functions.t
branches/upstream/libparse-cpan-meta-perl/current/t/04_export.t
branches/upstream/libparse-cpan-meta-perl/current/t/05_errors.t
branches/upstream/libparse-cpan-meta-perl/current/t/data/VR-META.json
branches/upstream/libparse-cpan-meta-perl/current/t/data/VR-META.yml
Removed:
branches/upstream/libparse-cpan-meta-perl/current/t/02_basic.t
branches/upstream/libparse-cpan-meta-perl/current/t/03_regression.t
branches/upstream/libparse-cpan-meta-perl/current/t/04_scalar.t
branches/upstream/libparse-cpan-meta-perl/current/t/05_export.t
branches/upstream/libparse-cpan-meta-perl/current/t/11_meta_yml.t
branches/upstream/libparse-cpan-meta-perl/current/t/12_plagger.t
branches/upstream/libparse-cpan-meta-perl/current/t/13_perl_smith.t
branches/upstream/libparse-cpan-meta-perl/current/t/14_yaml_org.t
branches/upstream/libparse-cpan-meta-perl/current/t/15_multibyte.t
branches/upstream/libparse-cpan-meta-perl/current/t/16_nullrefs.t
branches/upstream/libparse-cpan-meta-perl/current/t/17_toolbar.t
branches/upstream/libparse-cpan-meta-perl/current/t/18_tap.t
branches/upstream/libparse-cpan-meta-perl/current/t/19_errors.t
branches/upstream/libparse-cpan-meta-perl/current/t/21_bom.t
branches/upstream/libparse-cpan-meta-perl/current/t/data/HTML-WebDAO.yml
branches/upstream/libparse-cpan-meta-perl/current/t/data/Spreadsheet-Read.yml
branches/upstream/libparse-cpan-meta-perl/current/t/data/Template-Provider-Unicode-Japanese.yml
branches/upstream/libparse-cpan-meta-perl/current/t/data/multibyte.yml
branches/upstream/libparse-cpan-meta-perl/current/t/data/sample.yml
branches/upstream/libparse-cpan-meta-perl/current/t/data/toolbar.yml
branches/upstream/libparse-cpan-meta-perl/current/t/data/utf_16_le_bom.yml.packed
branches/upstream/libparse-cpan-meta-perl/current/t/data/vanilla.yml
branches/upstream/libparse-cpan-meta-perl/current/uupacktool.pl
Modified:
branches/upstream/libparse-cpan-meta-perl/current/Changes
branches/upstream/libparse-cpan-meta-perl/current/MANIFEST
branches/upstream/libparse-cpan-meta-perl/current/META.yml
branches/upstream/libparse-cpan-meta-perl/current/Makefile.PL
branches/upstream/libparse-cpan-meta-perl/current/lib/Parse/CPAN/Meta.pm
branches/upstream/libparse-cpan-meta-perl/current/t/01_compile.t
branches/upstream/libparse-cpan-meta-perl/current/t/lib/Parse/CPAN/Meta/Test.pm
Modified: branches/upstream/libparse-cpan-meta-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libparse-cpan-meta-perl/current/Changes?rev=67957&op=diff
==============================================================================
--- branches/upstream/libparse-cpan-meta-perl/current/Changes (original)
+++ branches/upstream/libparse-cpan-meta-perl/current/Changes Thu Jan 27 21:23:56 2011
@@ -1,4 +1,25 @@
Changes for Perl programming language extension Parse-CPAN-Meta
+
+1.4200 Mon Jan 24 2011
+ - No changes from 1.41_04
+
+1.41_04 Mon Jan 3 2011
+ - Support PERL_JSON_BACKEND environment (defaulting to JSON::PP)
+ - Support PERL_YAML_BACKEND environment (defaulting to CPAN::Meta:YAML)
+ - Update Makefile.PL to install to sitelib on Perl 5.12+
+
+1.41_03 Fri Dec 17 2010
+ - Throw exception when CPAN::Meta::YAML has a parse error
+ (RT#47608)
+
+1.41_02 Fri Dec 17 2010
+ - Convert to using CPAN::Meta::YAML instead of YAML::Tiny
+
+1.41_01 Fri Dec 10 2010
+ - add support for JSON metafiles and load_* methods (RJBS)
+ - Move binary file unpacking to test file from Makefile.PL so tests
+ will pass in the Perl core using a generated Makefile.PL
+ - Move bundled uupacktool.pl to t/bin/
1.40 Sat 25 Jul 2009
- Add core perl 5.10.1's uupacktool.pl
Modified: branches/upstream/libparse-cpan-meta-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libparse-cpan-meta-perl/current/MANIFEST?rev=67957&op=diff
==============================================================================
--- branches/upstream/libparse-cpan-meta-perl/current/MANIFEST (original)
+++ branches/upstream/libparse-cpan-meta-perl/current/MANIFEST Thu Jan 27 21:23:56 2011
@@ -3,28 +3,11 @@
Makefile.PL
MANIFEST This list of files
t/01_compile.t
-t/02_basic.t
-t/03_regression.t
-t/04_scalar.t
-t/05_export.t
-t/11_meta_yml.t
-t/12_plagger.t
-t/13_perl_smith.t
-t/14_yaml_org.t
-t/15_multibyte.t
-t/16_nullrefs.t
-t/17_toolbar.t
-t/18_tap.t
-t/19_errors.t
-t/21_bom.t
-t/data/HTML-WebDAO.yml
-t/data/multibyte.yml
-t/data/sample.yml
-t/data/Spreadsheet-Read.yml
-t/data/Template-Provider-Unicode-Japanese.yml
-t/data/toolbar.yml
-t/data/utf_16_le_bom.yml.packed
-t/data/vanilla.yml
+t/02_api.t
+t/03_functions.t
+t/04_export.t
+t/05_errors.t
+t/data/VR-META.json
+t/data/VR-META.yml
t/lib/Parse/CPAN/Meta/Test.pm
-uupacktool.pl
META.yml Module meta-data (added by MakeMaker)
Modified: branches/upstream/libparse-cpan-meta-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libparse-cpan-meta-perl/current/META.yml?rev=67957&op=diff
==============================================================================
--- branches/upstream/libparse-cpan-meta-perl/current/META.yml (original)
+++ branches/upstream/libparse-cpan-meta-perl/current/META.yml Thu Jan 27 21:23:56 2011
@@ -1,12 +1,26 @@
-# http://module-build.sourceforge.net/META-spec.html
-#XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX#
-name: Parse-CPAN-Meta
-version: 1.40
-version_from:
-installdirs: site
+--- #YAML:1.0
+name: Parse-CPAN-Meta
+version: 1.4200
+abstract: Parse META.yml and META.json CPAN metadata files
+author:
+ - Adam Kennedy <adamk at cpan.org>
+license: perl
+distribution_type: module
+configure_requires:
+ ExtUtils::MakeMaker: 0
+build_requires:
+ ExtUtils::MakeMaker: 0
requires:
- File::Spec: 0.80
- Test::More: 0.47
-
-distribution_type: module
-generated_by: ExtUtils::MakeMaker version 6.30_01
+ CPAN::Meta::YAML: 0.002
+ File::Spec: 0.80
+ JSON::PP: 2.27103
+ Module::Load::Conditional: 0.26
+ Test::More: 0.47
+no_index:
+ directory:
+ - t
+ - inc
+generated_by: ExtUtils::MakeMaker version 6.56
+meta-spec:
+ url: http://module-build.sourceforge.net/META-spec-v1.4.html
+ version: 1.4
Modified: branches/upstream/libparse-cpan-meta-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libparse-cpan-meta-perl/current/Makefile.PL?rev=67957&op=diff
==============================================================================
--- branches/upstream/libparse-cpan-meta-perl/current/Makefile.PL (original)
+++ branches/upstream/libparse-cpan-meta-perl/current/Makefile.PL Thu Jan 27 21:23:56 2011
@@ -1,73 +1,24 @@
use strict;
-BEGIN {
- require 5.003_96;
- $main::VERSION = '1.40';
-}
+require 5.003_96;
use ExtUtils::MakeMaker;
WriteMakefile(
NAME => 'Parse::CPAN::Meta',
- ABSTRACT => 'Parse META.yml and other similar CPAN metadata files',
- VERSION => $main::VERSION,
PREREQ_PM => {
'File::Spec' => '0.80',
'Test::More' => '0.47',
+ 'JSON::PP' => 2.27103,
+ 'CPAN::Meta::YAML' => '0.002',
+ 'Module::Load::Conditional' => '0.26',
},
($] >= 5.005 ? (
AUTHOR => 'Adam Kennedy <adamk at cpan.org>',
+ ABSTRACT_FROM => 'lib/Parse/CPAN/Meta.pm',
+ VERSION_FROM => 'lib/Parse/CPAN/Meta.pm',
) : ()),
($ExtUtils::MakeMaker::VERSION ge '6.30_00' ? (
LICENSE => 'perl',
) : ()),
- (INSTALLDIRS => $] >= 5.010001 ? 'perl' : 'site'),
+ (INSTALLDIRS => ($] ge '5.010001' && $] lt '5.012') ? 'perl' : 'site'),
);
-package MY;
-
-# ExtUtil::MakeMaker's default PMLIBDIRS finds uupacktool.pl but
-# that's only a utility so I'd like it to be skipped over.
-sub libscan {
- my $self = shift @_;
- my ( $pl_or_pm ) = @_;
- return 0 if $pl_or_pm eq 'uupacktool.pl';
- return $self->SUPER::libscan( @_ );
-}
-
-# Just like core perl's _test_prep function in Makefile, we unpack
-# binary files before testing. This function also converts the
-# double-colon test dependency list to a single colon list. This
-# turned out to be be necessary because unpacking the binary files
-# must happen before any other test tasks will run and potentially
-# require them.
-#
-# TODO: consider whether the test rule should be gutted so it only
-# handles test preparation, then delegates to another rule which is
-# double-colon like this rule normally is.
-sub test {
- my $inherited = shift->SUPER::test(@_);
- $inherited =~ s{^test\s*:+\s*(.*)}{
- "test : unpack_files $1";
- }me || die $inherited;
- return $inherited;
-}
-
-# Adding cleanup_unpacked_files to the clean rule.
-sub clean {
- my $inherited = shift->SUPER::clean(@_);
- $inherited =~ s{^(clean\s*:.*)}{
- "$1 cleanup_unpacked_files";
- }me || die $inherited;
- return $inherited;
-}
-
-# Define the unpack_files and cleanup_unpacked_files Makefile rules.
-sub postamble {
- return <<'MAKE_FRAG';
-unpack_files:
- $(FULLPERLRUN) uupacktool.pl -u -m
-
-cleanup_unpacked_files:
- $(FULLPERLRUN) uupacktool.pl -c
-
-MAKE_FRAG
-}
Modified: branches/upstream/libparse-cpan-meta-perl/current/lib/Parse/CPAN/Meta.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libparse-cpan-meta-perl/current/lib/Parse/CPAN/Meta.pm?rev=67957&op=diff
==============================================================================
--- branches/upstream/libparse-cpan-meta-perl/current/lib/Parse/CPAN/Meta.pm (original)
+++ branches/upstream/libparse-cpan-meta-perl/current/lib/Parse/CPAN/Meta.pm Thu Jan 27 21:23:56 2011
@@ -2,9 +2,12 @@
use strict;
use Carp 'croak';
+use Module::Load::Conditional qw/can_load/;
# UTF Support?
sub HAVE_UTF8 () { $] >= 5.007003 }
+sub IO_LAYER () { $] >= 5.008001 ? ":utf8" : "" }
+
BEGIN {
if ( HAVE_UTF8 ) {
# The string eval helps hide this from Test::MinimumVersion
@@ -15,325 +18,91 @@
# Class structure
require 5.004;
require Exporter;
- $Parse::CPAN::Meta::VERSION = '1.40';
+ $Parse::CPAN::Meta::VERSION = '1.4200';
@Parse::CPAN::Meta::ISA = qw{ Exporter };
@Parse::CPAN::Meta::EXPORT_OK = qw{ Load LoadFile };
}
-# Prototypes
-sub LoadFile ($);
-sub Load ($);
-sub _scalar ($$$);
-sub _array ($$$);
-sub _hash ($$$);
-
-# Printable characters for escapes
-my %UNESCAPES = (
- z => "\x00", a => "\x07", t => "\x09",
- n => "\x0a", v => "\x0b", f => "\x0c",
- r => "\x0d", e => "\x1b", '\\' => '\\',
-);
-
-
-
-
-
-#####################################################################
-# Implementation
-
+sub load_file {
+ my ($class, $filename) = @_;
+
+ if ($filename =~ /\.ya?ml$/) {
+ return $class->load_yaml_string(_slurp($filename));
+ }
+
+ if ($filename =~ /\.json$/) {
+ return $class->load_json_string(_slurp($filename));
+ }
+
+ croak("file type cannot be determined by filename");
+}
+
+sub load_yaml_string {
+ my ($class, $string) = @_;
+ my $backend = _choose_yaml_backend();
+ my $data = eval { no strict 'refs'; &{"$backend\::Load"}($string) };
+ if ( $@ ) {
+ croak $backend->can('errstr') ? $backend->errstr : $@
+ }
+ return $data || {}; # in case document was valid but empty
+}
+
+sub load_json_string {
+ my ($class, $string) = @_;
+ return _choose_json_backend()->new->decode($string);
+}
+
+sub _choose_yaml_backend {
+ local $Module::Load::Conditional::CHECK_INC_HASH = 1;
+ if (! defined $ENV{PERL_YAML_BACKEND} ) {
+ can_load( modules => {'CPAN::Meta::YAML' => 0.002}, verbose => 0 )
+ or croak "CPAN::Meta::YAML 0.002 is not available\n";
+ return "CPAN::Meta::YAML";
+ }
+ else {
+ my $backend = $ENV{PERL_YAML_BACKEND};
+ can_load( modules => {$backend => undef}, verbose => 0 )
+ or croak "Could not load PERL_YAML_BACKEND '$backend'\n";
+ $backend->can("Load")
+ or croak "PERL_YAML_BACKEND '$backend' does not implement Load()\n";
+ return $backend;
+ }
+}
+
+sub _choose_json_backend {
+ local $Module::Load::Conditional::CHECK_INC_HASH = 1;
+ if (! $ENV{PERL_JSON_BACKEND} or $ENV{PERL_JSON_BACKEND} eq 'JSON::PP') {
+ can_load( modules => {'JSON::PP' => 2.27103}, verbose => 0 )
+ or croak "JSON::PP 2.27103 is not available\n";
+ return 'JSON::PP';
+ }
+ else {
+ can_load( modules => {'JSON' => 2.5}, verbose => 0 )
+ or croak "JSON 2.5 is required for " .
+ "\$ENV{PERL_JSON_BACKEND} = '$ENV{PERL_JSON_BACKEND}'\n";
+ return "JSON";
+ }
+}
+
+sub _slurp {
+ open my $fh, "<" . IO_LAYER, "$_[0]"
+ or die "can't open $_[0] for reading: $!";
+ return do { local $/; <$fh> };
+}
+
+# Kept for backwards compatibility only
# Create an object from a file
sub LoadFile ($) {
- # Check the file
- my $file = shift;
- croak('You did not specify a file name') unless $file;
- croak( "File '$file' does not exist" ) unless -e $file;
- croak( "'$file' is a directory, not a file" ) unless -f _;
- croak( "Insufficient permissions to read '$file'" ) unless -r _;
-
- # Slurp in the file
- local $/ = undef;
- local *CFG;
- unless ( open( CFG, $file ) ) {
- croak("Failed to open file '$file': $!");
- }
- my $yaml = <CFG>;
- unless ( close(CFG) ) {
- croak("Failed to close file '$file': $!");
- }
-
- # Hand off to the actual parser
- Load( $yaml );
+ require CPAN::Meta::YAML;
+ return CPAN::Meta::YAML::LoadFile(shift)
+ or die CPAN::Meta::YAML->errstr;
}
# Parse a document from a string.
-# Doing checks on $_[0] prevents us having to do a string copy.
sub Load ($) {
- my $string = $_[0];
- unless ( defined $string ) {
- croak("Did not provide a string to load");
- }
-
- # Byte order marks
- if ( $string =~ /^(?:\376\377|\377\376|\377\376\0\0|\0\0\376\377)/ ) {
- croak("Stream has a non UTF-8 Unicode Byte Order Mark");
- } else {
- # Strip UTF-8 bom if found, we'll just ignore it
- $string =~ s/^\357\273\277//;
- }
-
- # Try to decode as utf8
- utf8::decode($string) if HAVE_UTF8;
-
- # Check for some special cases
- return () unless length $string;
- unless ( $string =~ /[\012\015]+\z/ ) {
- croak("Stream does not end with newline character");
- }
-
- # Split the file into lines
- my @lines = grep { ! /^\s*(?:\#.*)?\z/ }
- split /(?:\015{1,2}\012|\015|\012)/, $string;
-
- # Strip the initial YAML header
- @lines and $lines[0] =~ /^\%YAML[: ][\d\.]+.*\z/ and shift @lines;
-
- # A nibbling parser
- my @documents = ();
- while ( @lines ) {
- # Do we have a document header?
- if ( $lines[0] =~ /^---\s*(?:(.+)\s*)?\z/ ) {
- # Handle scalar documents
- shift @lines;
- if ( defined $1 and $1 !~ /^(?:\#.+|\%YAML[: ][\d\.]+)\z/ ) {
- push @documents, _scalar( "$1", [ undef ], \@lines );
- next;
- }
- }
-
- if ( ! @lines or $lines[0] =~ /^(?:---|\.\.\.)/ ) {
- # A naked document
- push @documents, undef;
- while ( @lines and $lines[0] !~ /^---/ ) {
- shift @lines;
- }
-
- } elsif ( $lines[0] =~ /^\s*\-/ ) {
- # An array at the root
- my $document = [ ];
- push @documents, $document;
- _array( $document, [ 0 ], \@lines );
-
- } elsif ( $lines[0] =~ /^(\s*)\S/ ) {
- # A hash at the root
- my $document = { };
- push @documents, $document;
- _hash( $document, [ length($1) ], \@lines );
-
- } else {
- croak("Parse::CPAN::Meta failed to classify line '$lines[0]'");
- }
- }
-
- if ( wantarray ) {
- return @documents;
- } else {
- return $documents[-1];
- }
-}
-
-# Deparse a scalar string to the actual scalar
-sub _scalar ($$$) {
- my ($string, $indent, $lines) = @_;
-
- # Trim trailing whitespace
- $string =~ s/\s*\z//;
-
- # Explitic null/undef
- return undef if $string eq '~';
-
- # Quotes
- if ( $string =~ /^\'(.*?)\'\z/ ) {
- return '' unless defined $1;
- $string = $1;
- $string =~ s/\'\'/\'/g;
- return $string;
- }
- if ( $string =~ /^\"((?:\\.|[^\"])*)\"\z/ ) {
- # Reusing the variable is a little ugly,
- # but avoids a new variable and a string copy.
- $string = $1;
- $string =~ s/\\"/"/g;
- $string =~ s/\\([never\\fartz]|x([0-9a-fA-F]{2}))/(length($1)>1)?pack("H2",$2):$UNESCAPES{$1}/gex;
- return $string;
- }
-
- # Special cases
- if ( $string =~ /^[\'\"!&]/ ) {
- croak("Parse::CPAN::Meta does not support a feature in line '$lines->[0]'");
- }
- return {} if $string eq '{}';
- return [] if $string eq '[]';
-
- # Regular unquoted string
- return $string unless $string =~ /^[>|]/;
-
- # Error
- croak("Parse::CPAN::Meta failed to find multi-line scalar content") unless @$lines;
-
- # Check the indent depth
- $lines->[0] =~ /^(\s*)/;
- $indent->[-1] = length("$1");
- if ( defined $indent->[-2] and $indent->[-1] <= $indent->[-2] ) {
- croak("Parse::CPAN::Meta found bad indenting in line '$lines->[0]'");
- }
-
- # Pull the lines
- my @multiline = ();
- while ( @$lines ) {
- $lines->[0] =~ /^(\s*)/;
- last unless length($1) >= $indent->[-1];
- push @multiline, substr(shift(@$lines), length($1));
- }
-
- my $j = (substr($string, 0, 1) eq '>') ? ' ' : "\n";
- my $t = (substr($string, 1, 1) eq '-') ? '' : "\n";
- return join( $j, @multiline ) . $t;
-}
-
-# Parse an array
-sub _array ($$$) {
- my ($array, $indent, $lines) = @_;
-
- while ( @$lines ) {
- # Check for a new document
- if ( $lines->[0] =~ /^(?:---|\.\.\.)/ ) {
- while ( @$lines and $lines->[0] !~ /^---/ ) {
- shift @$lines;
- }
- return 1;
- }
-
- # Check the indent level
- $lines->[0] =~ /^(\s*)/;
- if ( length($1) < $indent->[-1] ) {
- return 1;
- } elsif ( length($1) > $indent->[-1] ) {
- croak("Parse::CPAN::Meta found bad indenting in line '$lines->[0]'");
- }
-
- if ( $lines->[0] =~ /^(\s*\-\s+)[^\'\"]\S*\s*:(?:\s+|$)/ ) {
- # Inline nested hash
- my $indent2 = length("$1");
- $lines->[0] =~ s/-/ /;
- push @$array, { };
- _hash( $array->[-1], [ @$indent, $indent2 ], $lines );
-
- } elsif ( $lines->[0] =~ /^\s*\-(\s*)(.+?)\s*\z/ ) {
- # Array entry with a value
- shift @$lines;
- push @$array, _scalar( "$2", [ @$indent, undef ], $lines );
-
- } elsif ( $lines->[0] =~ /^\s*\-\s*\z/ ) {
- shift @$lines;
- unless ( @$lines ) {
- push @$array, undef;
- return 1;
- }
- if ( $lines->[0] =~ /^(\s*)\-/ ) {
- my $indent2 = length("$1");
- if ( $indent->[-1] == $indent2 ) {
- # Null array entry
- push @$array, undef;
- } else {
- # Naked indenter
- push @$array, [ ];
- _array( $array->[-1], [ @$indent, $indent2 ], $lines );
- }
-
- } elsif ( $lines->[0] =~ /^(\s*)\S/ ) {
- push @$array, { };
- _hash( $array->[-1], [ @$indent, length("$1") ], $lines );
-
- } else {
- croak("Parse::CPAN::Meta failed to classify line '$lines->[0]'");
- }
-
- } elsif ( defined $indent->[-2] and $indent->[-1] == $indent->[-2] ) {
- # This is probably a structure like the following...
- # ---
- # foo:
- # - list
- # bar: value
- #
- # ... so lets return and let the hash parser handle it
- return 1;
-
- } else {
- croak("Parse::CPAN::Meta failed to classify line '$lines->[0]'");
- }
- }
-
- return 1;
-}
-
-# Parse an array
-sub _hash ($$$) {
- my ($hash, $indent, $lines) = @_;
-
- while ( @$lines ) {
- # Check for a new document
- if ( $lines->[0] =~ /^(?:---|\.\.\.)/ ) {
- while ( @$lines and $lines->[0] !~ /^---/ ) {
- shift @$lines;
- }
- return 1;
- }
-
- # Check the indent level
- $lines->[0] =~ /^(\s*)/;
- if ( length($1) < $indent->[-1] ) {
- return 1;
- } elsif ( length($1) > $indent->[-1] ) {
- croak("Parse::CPAN::Meta found bad indenting in line '$lines->[0]'");
- }
-
- # Get the key
- unless ( $lines->[0] =~ s/^\s*([^\'\" ][^\n]*?)\s*:(\s+|$)// ) {
- if ( $lines->[0] =~ /^\s*[?\'\"]/ ) {
- croak("Parse::CPAN::Meta does not support a feature in line '$lines->[0]'");
- }
- croak("Parse::CPAN::Meta failed to classify line '$lines->[0]'");
- }
- my $key = $1;
-
- # Do we have a value?
- if ( length $lines->[0] ) {
- # Yes
- $hash->{$key} = _scalar( shift(@$lines), [ @$indent, undef ], $lines );
- } else {
- # An indent
- shift @$lines;
- unless ( @$lines ) {
- $hash->{$key} = undef;
- return 1;
- }
- if ( $lines->[0] =~ /^(\s*)-/ ) {
- $hash->{$key} = [];
- _array( $hash->{$key}, [ @$indent, length($1) ], $lines );
- } elsif ( $lines->[0] =~ /^(\s*)./ ) {
- my $indent2 = length("$1");
- if ( $indent->[-1] >= $indent2 ) {
- # Null hash entry
- $hash->{$key} = undef;
- } else {
- $hash->{$key} = {};
- _hash( $hash->{$key}, [ @$indent, length($1) ], $lines );
- }
- }
- }
- }
-
- return 1;
+ require CPAN::Meta::YAML;
+ return CPAN::Meta::YAML::Load(shift)
+ or die CPAN::Meta::YAML->errstr;
}
1;
@@ -344,7 +113,7 @@
=head1 NAME
-Parse::CPAN::Meta - Parse META.yml and other similar CPAN metadata files
+Parse::CPAN::Meta - Parse META.yml and META.json CPAN metadata files
=head1 SYNOPSIS
@@ -352,13 +121,10 @@
# In your file
---
- rootproperty: blah
- section:
- one: two
- three: four
- Foo: Bar
- empty: ~
-
+ name: My-Distribution
+ version: 1.23
+ resources:
+ homepage: "http://example.com/dist/My-Distribution"
#############################################
@@ -366,49 +132,97 @@
use Parse::CPAN::Meta;
- # Create a YAML file
- my @yaml = Parse::CPAN::Meta::LoadFile( 'Meta.yml' );
+ my $distmeta = Parse::CPAN::Meta->load_file('META.yml');
# Reading properties
- my $root = $yaml[0]->{rootproperty};
- my $one = $yaml[0]->{section}->{one};
- my $Foo = $yaml[0]->{section}->{Foo};
+ my $name = $distmeta->{name};
+ my $version = $distmeta->{version};
+ my $homepage = $distmeta->{resources}{homepage};
=head1 DESCRIPTION
-B<Parse::CPAN::Meta> is a parser for F<META.yml> files, based on the
-parser half of L<YAML::Tiny>.
-
-It supports a basic subset of the full YAML specification, enough to
-implement parsing of typical F<META.yml> files, and other similarly simple
-YAML files.
-
-If you need something with more power, move up to a full YAML parser such
-as L<YAML>, L<YAML::Syck> or L<YAML::LibYAML>.
-
-B<Parse::CPAN::Meta> provides a very simply API of only two functions,
+B<Parse::CPAN::Meta> is a parser for F<META.json> and F<META.yml> files, using
+L<JSON::PP> and/or L<CPAN::Meta::YAML>.
+
+B<Parse::CPAN::Meta> provides three methods: C<load_file>, C<load_json_string>,
+and C<load_yaml_string>. These will read and deserialize CPAN metafiles, and
+are described below in detail.
+
+B<Parse::CPAN::Meta> provides a legacy API of only two functions,
based on the YAML functions of the same name. Wherever possible,
-identical calling semantics are used.
+identical calling semantics are used. These may only be used with YAML sources.
All error reporting is done with exceptions (die'ing).
+Note that META files are expected to be in UTF-8 encoding, only. When
+converted string data, it must first be decoded from UTF-8.
+
+=head1 METHODS
+
+=head2 load_file
+
+ my $metadata_structure = Parse::CPAN::Meta->load_file('META.json');
+
+ my $metadata_structure = Parse::CPAN::Meta->load_file('META.yml');
+
+This method will read the named file and deserialize it to a data structure,
+determining whether it should be JSON or YAML based on the filename. On
+Perl 5.8.1 or later, the file will be read using the ":utf8" IO layer.
+
+=head2 load_yaml_string
+
+ my $metadata_structure = Parse::CPAN::Meta->load_yaml_string($yaml_string);
+
+This method deserializes the given string of YAML and returns the first
+document in it. (CPAN metadata files should always have only one document.)
+If the source was UTF-8 encoded, the string must be decoded before calling
+C<load_yaml_string>.
+
+=head2 load_json_string
+
+ my $metadata_structure = Parse::CPAN::Meta->load_json_string($json_string);
+
+This method deserializes the given string of JSON and the result.
+If the source was UTF-8 encoded, the string must be decoded before calling
+C<load_json_string>.
+
=head1 FUNCTIONS
-For maintenance clarity, no functions are exported.
+For maintenance clarity, no functions are exported. These functions are
+available for backwards compatibility only and are best avoided in favor of
+C<load_file>.
=head2 Load
- my @yaml = Load( $string );
+ my @yaml = Parse::CPAN::Meta::Load( $string );
Parses a string containing a valid YAML stream into a list of Perl data
structures.
=head2 LoadFile
- my @yaml = LoadFile( 'META.yml' );
+ my @yaml = Parse::CPAN::Meta::LoadFile( 'META.yml' );
Reads the YAML stream from a file instead of a string.
+=head1 ENVIRONMENT
+
+=head2 PERL_JSON_BACKEND
+
+By default, L<JSON::PP> will be used for deserializing JSON data. If the
+C<PERL_JSON_BACKEND> environment variable exists, is true and is not
+"JSON::PP", then the L<JSON> module (version 2.5 or greater) will be loaded and
+used to interpret C<PERL_JSON_BACKEND>. If L<JSON> is not installed or is too
+old, an exception will be thrown.
+
+=head2 PERL_YAML_BACKEND
+
+By default, L<CPAN::Meta::YAML> will be used for deserializing YAML data. If
+the C<PERL_YAML_BACKEND> environment variable is defined, then it is intepreted
+as a module to use for deserialization. The given module must be installed,
+must load correctly and must implement the C<Load()> function or an exception
+will be thrown.
+
=head1 SUPPORT
Bugs should be reported via the CPAN bug tracker at
@@ -419,14 +233,9 @@
Adam Kennedy E<lt>adamk at cpan.orgE<gt>
-=head1 SEE ALSO
-
-L<YAML>, L<YAML::Syck>, L<Config::Tiny>, L<CSS::Tiny>,
-L<http://use.perl.org/~Alias/journal/29427>, L<http://ali.as/>
-
=head1 COPYRIGHT
-Copyright 2006 - 2009 Adam Kennedy.
+Copyright 2006 - 2010 Adam Kennedy.
This program is free software; you can redistribute
it and/or modify it under the same terms as Perl itself.
Modified: branches/upstream/libparse-cpan-meta-perl/current/t/01_compile.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libparse-cpan-meta-perl/current/t/01_compile.t?rev=67957&op=diff
==============================================================================
--- branches/upstream/libparse-cpan-meta-perl/current/t/01_compile.t (original)
+++ branches/upstream/libparse-cpan-meta-perl/current/t/01_compile.t Thu Jan 27 21:23:56 2011
@@ -1,6 +1,4 @@
#!/usr/bin/perl
-
-# Load testing for YAML::Tiny
BEGIN {
if( $ENV{PERL_CORE} ) {
Added: branches/upstream/libparse-cpan-meta-perl/current/t/02_api.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libparse-cpan-meta-perl/current/t/02_api.t?rev=67957&op=file
==============================================================================
--- branches/upstream/libparse-cpan-meta-perl/current/t/02_api.t (added)
+++ branches/upstream/libparse-cpan-meta-perl/current/t/02_api.t Thu Jan 27 21:23:56 2011
@@ -1,0 +1,132 @@
+#!/usr/bin/perl
+
+# Testing of a known-bad file from an editor
+
+BEGIN {
+ if( $ENV{PERL_CORE} ) {
+ chdir 't';
+ @INC = ('../lib', 'lib');
+ }
+ else {
+ unshift @INC, 't/lib/';
+ }
+}
+
+use strict;
+BEGIN {
+ $| = 1;
+ $^W = 1;
+}
+
+use File::Spec::Functions ':ALL';
+use Parse::CPAN::Meta;
+use Parse::CPAN::Meta::Test;
+# use Test::More skip_all => 'Temporarily ignoring failing test';
+use Test::More 'no_plan';
+
+#####################################################################
+# Testing that Perl::Smith config files work
+
+my $want = {
+ "abstract" => "a set of version requirements for a CPAN dist",
+ "author" => [ 'Ricardo Signes <rjbs at cpan.org>' ],
+ "build_requires" => {
+ "Test::More" => "0.88"
+ },
+ "configure_requires" => {
+ "ExtUtils::MakeMaker" => "6.31"
+ },
+ "generated_by" => "Dist::Zilla version 2.100991",
+ "license" => "perl",
+ "meta-spec" => {
+ "url" => "http://module-build.sourceforge.net/META-spec-v1.4.html",
+ "version" => 1.4
+ },
+ "name" => "Version-Requirements",
+ "recommends" => {},
+ "requires" => {
+ "Carp" => "0",
+ "Scalar::Util" => "0",
+ "version" => "0.77"
+ },
+ "resources" => {
+ "repository" => "git://git.codesimply.com/Version-Requirements.git"
+ },
+ "version" => "0.101010",
+};
+
+my $meta_json = catfile( test_data_directory(), 'VR-META.json' );
+my $meta_yaml = catfile( test_data_directory(), 'VR-META.yml' );
+
+### YAML tests
+{
+ local $ENV{PERL_YAML_BACKEND}; # ensure we get CPAN::META::YAML
+
+ my $from_yaml = Parse::CPAN::Meta->load_file( $meta_yaml );
+ is_deeply($from_yaml, $want, "load from YAML file results in expected data");
+}
+
+{
+ local $ENV{PERL_YAML_BACKEND}; # ensure we get CPAN::META::YAML
+
+ my $yaml = load_ok( 'VR-META.yml', $meta_yaml, 100);
+ my $from_yaml = Parse::CPAN::Meta->load_yaml_string( $yaml );
+ is_deeply($from_yaml, $want, "load from YAML str results in expected data");
+}
+
+SKIP: {
+ skip "YAML module not installed", 2
+ unless eval "require YAML; 1";
+ local $ENV{PERL_YAML_BACKEND} = 'YAML';
+
+ my $yaml = load_ok( 'VR-META.yml', $meta_yaml, 100);
+ my $from_yaml = Parse::CPAN::Meta->load_yaml_string( $yaml );
+ is_deeply($from_yaml, $want, "load_yaml_string using PERL_YAML_BACKEND");
+}
+
+### JSON tests
+{
+ # JSON tests with JSON::PP
+ local $ENV{PERL_JSON_BACKEND}; # ensure we get JSON::PP
+
+ my $from_json = Parse::CPAN::Meta->load_file( $meta_json );
+ is_deeply($from_json, $want, "load from JSON file results in expected data");
+}
+
+{
+ # JSON tests with JSON::PP
+ local $ENV{PERL_JSON_BACKEND}; # ensure we get JSON::PP
+
+ my $json = load_ok( 'VR-META.json', $meta_json, 100);
+ my $from_json = Parse::CPAN::Meta->load_json_string( $json );
+ is_deeply($from_json, $want, "load from JSON str results in expected data");
+}
+
+{
+ # JSON tests with JSON::PP, take 2
+ local $ENV{PERL_JSON_BACKEND} = 0; # request JSON::PP
+
+ my $json = load_ok( 'VR-META.json', $meta_json, 100);
+ my $from_json = Parse::CPAN::Meta->load_json_string( $json );
+ is_deeply($from_json, $want, "load_json_string with PERL_JSON_BACKEND = 0");
+}
+
+{
+ # JSON tests with JSON::PP, take 3
+ local $ENV{PERL_JSON_BACKEND} = 'JSON::PP'; # request JSON::PP
+
+ my $json = load_ok( 'VR-META.json', $meta_json, 100);
+ my $from_json = Parse::CPAN::Meta->load_json_string( $json );
+ is_deeply($from_json, $want, "load_json_string with PERL_JSON_BACKEND = 'JSON::PP'");
+}
+
+SKIP: {
+ skip "JSON module version 2.5 not installed", 2
+ unless eval "require JSON; JSON->VERSION(2.5); 1";
+ local $ENV{PERL_JSON_BACKEND} = 1;
+
+ my $json = load_ok( 'VR-META.json', $meta_json, 100);
+ my $from_json = Parse::CPAN::Meta->load_json_string( $json );
+ is_deeply($from_json, $want, "load_json_string with PERL_JSON_BACKEND = 1");
+}
+
Added: branches/upstream/libparse-cpan-meta-perl/current/t/03_functions.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libparse-cpan-meta-perl/current/t/03_functions.t?rev=67957&op=file
==============================================================================
--- branches/upstream/libparse-cpan-meta-perl/current/t/03_functions.t (added)
+++ branches/upstream/libparse-cpan-meta-perl/current/t/03_functions.t Thu Jan 27 21:23:56 2011
@@ -1,0 +1,40 @@
+#!/usr/bin/perl
+
+# Testing of basic document structures
+
+BEGIN {
+ if( $ENV{PERL_CORE} ) {
+ chdir 't';
+ @INC = ('../lib', 'lib');
+ }
+ else {
+ unshift @INC, 't/lib/';
+ }
+}
+
+use strict;
+BEGIN {
+ $| = 1;
+ $^W = 1;
+}
+
+use Test::More tests => 2;
+use Parse::CPAN::Meta ();
+
+my $one = <<'END_YAML';
+---
+- foo
+END_YAML
+
+my $two = <<'END_YAML';
+---
+- foo
+---
+- bar
+END_YAML
+
+my $one_scalar_tiny = Parse::CPAN::Meta::Load( $one );
+my $two_scalar_tiny = Parse::CPAN::Meta::Load( $two );
+
+is_deeply( $one_scalar_tiny, [ 'foo' ], 'one: Parsed correctly' );
+is_deeply( $two_scalar_tiny, [ 'bar' ], 'two: Parsed correctly' );
Added: branches/upstream/libparse-cpan-meta-perl/current/t/04_export.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libparse-cpan-meta-perl/current/t/04_export.t?rev=67957&op=file
==============================================================================
--- branches/upstream/libparse-cpan-meta-perl/current/t/04_export.t (added)
+++ branches/upstream/libparse-cpan-meta-perl/current/t/04_export.t Thu Jan 27 21:23:56 2011
@@ -1,0 +1,29 @@
+#!/usr/bin/perl
+
+# Testing of basic document structures
+
+BEGIN {
+ if( $ENV{PERL_CORE} ) {
+ chdir 't';
+ @INC = ('../lib', 'lib');
+ }
+ else {
+ unshift @INC, 't/lib/';
+ }
+}
+
+use strict;
+BEGIN {
+ $| = 1;
+ $^W = 1;
+}
+
+use Test::More tests => 4;
+use Parse::CPAN::Meta;
+
+
+
+ok not(defined &main::Load), 'Load is not exported';
+ok not(defined &main::Dump), 'Dump is not exported';
+ok not(defined &main::LoadFile), 'LoadFile is not exported';
+ok not(defined &main::DumpFile), 'DumpFile is not exported';
Added: branches/upstream/libparse-cpan-meta-perl/current/t/05_errors.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libparse-cpan-meta-perl/current/t/05_errors.t?rev=67957&op=file
==============================================================================
--- branches/upstream/libparse-cpan-meta-perl/current/t/05_errors.t (added)
+++ branches/upstream/libparse-cpan-meta-perl/current/t/05_errors.t Thu Jan 27 21:23:56 2011
@@ -1,0 +1,31 @@
+#!/usr/bin/perl
+
+# Testing of basic document structures
+
+BEGIN {
+ if( $ENV{PERL_CORE} ) {
+ chdir 't';
+ @INC = ('../lib', 'lib');
+ }
+ else {
+ unshift @INC, 't/lib/';
+ }
+}
+
+use strict;
+BEGIN {
+ $| = 1;
+ $^W = 1;
+}
+
+use Test::More tests => 1;
+use Parse::CPAN::Meta ();
+
+my $one = <<'END_YAML';
+---
+- foo: - bar
+END_YAML
+
+my $one_scalar_tiny = eval { Parse::CPAN::Meta->load_yaml_string( $one ) };
+like( $@, '/illegal characters/', "error causes exception");
+
Added: branches/upstream/libparse-cpan-meta-perl/current/t/data/VR-META.json
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libparse-cpan-meta-perl/current/t/data/VR-META.json?rev=67957&op=file
==============================================================================
--- branches/upstream/libparse-cpan-meta-perl/current/t/data/VR-META.json (added)
+++ branches/upstream/libparse-cpan-meta-perl/current/t/data/VR-META.json Thu Jan 27 21:23:56 2011
@@ -1,0 +1,30 @@
+{
+ "abstract" : "a set of version requirements for a CPAN dist",
+ "author" : [
+ "Ricardo Signes <rjbs at cpan.org>"
+ ],
+ "build_requires" : {
+ "Test::More" : "0.88"
+ },
+ "configure_requires" : {
+ "ExtUtils::MakeMaker" : "6.31"
+ },
+ "generated_by" : "Dist::Zilla version 2.100991",
+ "license" : "perl",
+ "meta-spec" : {
+ "url" : "http://module-build.sourceforge.net/META-spec-v1.4.html",
+ "version" : 1.4
+ },
+ "name" : "Version-Requirements",
+ "recommends" : {},
+ "requires" : {
+ "Carp" : "0",
+ "Scalar::Util" : "0",
+ "version" : "0.77"
+ },
+ "resources" : {
+ "repository" : "git://git.codesimply.com/Version-Requirements.git"
+ },
+ "version" : "0.101010"
+}
+
Added: branches/upstream/libparse-cpan-meta-perl/current/t/data/VR-META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libparse-cpan-meta-perl/current/t/data/VR-META.yml?rev=67957&op=file
==============================================================================
--- branches/upstream/libparse-cpan-meta-perl/current/t/data/VR-META.yml (added)
+++ branches/upstream/libparse-cpan-meta-perl/current/t/data/VR-META.yml Thu Jan 27 21:23:56 2011
@@ -1,0 +1,22 @@
+---
+abstract: 'a set of version requirements for a CPAN dist'
+author:
+ - 'Ricardo Signes <rjbs at cpan.org>'
+build_requires:
+ Test::More: 0.88
+configure_requires:
+ ExtUtils::MakeMaker: 6.31
+generated_by: 'Dist::Zilla version 2.100991'
+license: perl
+meta-spec:
+ url: http://module-build.sourceforge.net/META-spec-v1.4.html
+ version: 1.4
+name: Version-Requirements
+recommends: {}
+requires:
+ Carp: 0
+ Scalar::Util: 0
+ version: 0.77
+resources:
+ repository: git://git.codesimply.com/Version-Requirements.git
+version: 0.101010
Modified: branches/upstream/libparse-cpan-meta-perl/current/t/lib/Parse/CPAN/Meta/Test.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libparse-cpan-meta-perl/current/t/lib/Parse/CPAN/Meta/Test.pm?rev=67957&op=diff
==============================================================================
--- branches/upstream/libparse-cpan-meta-perl/current/t/lib/Parse/CPAN/Meta/Test.pm (original)
+++ branches/upstream/libparse-cpan-meta-perl/current/t/lib/Parse/CPAN/Meta/Test.pm Thu Jan 27 21:23:56 2011
@@ -59,7 +59,7 @@
sub yaml_error {
my $string = shift;
my $yaml = eval { Parse::CPAN::Meta::Load( $string ); };
- Test::More::like( $@, qr/$_[0]/, "YAML::Tiny throws expected error" );
+ Test::More::like( $@, qr/$_[0]/, "CPAN::Meta::YAML throws expected error" );
}
sub slurp {
More information about the Pkg-perl-cvs-commits
mailing list