cpan/Parse-CPAN-Meta/t/04_export.t
cpan/Parse-CPAN-Meta/t/05_errors.t
cpan/Parse-CPAN-Meta/t/data/BadMETA.yml
+cpan/Parse-CPAN-Meta/t/data/bareyaml.meta
+cpan/Parse-CPAN-Meta/t/data/json.meta
cpan/Parse-CPAN-Meta/t/data/META-VR.json
cpan/Parse-CPAN-Meta/t/data/META-VR.yml
+cpan/Parse-CPAN-Meta/t/data/yaml.meta
cpan/Parse-CPAN-Meta/t/lib/Parse/CPAN/Meta/Test.pm
cpan/perlfaq/lib/perlfaq1.pod General Questions About Perl
cpan/perlfaq/lib/perlfaq2.pod Obtaining and Learning about Perl
},
'Parse::CPAN::Meta' => {
- 'DISTRIBUTION' => 'DAGOLDEN/Parse-CPAN-Meta-1.4413.tar.gz',
+ 'DISTRIBUTION' => 'DAGOLDEN/Parse-CPAN-Meta-1.4414.tar.gz',
'FILES' => q[cpan/Parse-CPAN-Meta],
'EXCLUDED' => [
qw[t/00-report-prereqs.t],
use strict;
package Parse::CPAN::Meta;
# ABSTRACT: Parse META.yml and META.json CPAN metadata files
-our $VERSION = '1.4413'; # VERSION
+our $VERSION = '1.4414'; # VERSION
use Exporter;
use Carp 'croak';
sub load_file {
my ($class, $filename) = @_;
+ my $meta = _slurp($filename);
+
if ($filename =~ /\.ya?ml$/) {
- return $class->load_yaml_string(_slurp($filename));
+ return $class->load_yaml_string($meta);
}
-
- if ($filename =~ /\.json$/) {
- return $class->load_json_string(_slurp($filename));
+ elsif ($filename =~ /\.json$/) {
+ return $class->load_json_string($meta);
+ }
+ else {
+ $class->load_string($meta); # try to detect yaml/json
}
+}
- croak("file type cannot be determined by filename");
+sub load_string {
+ my ($class, $string) = @_;
+ if ( $string =~ /^---/ ) { # looks like YAML
+ return $class->load_yaml_string($string);
+ }
+ elsif ( $string =~ /^\s*\{/ ) { # looks like JSON
+ return $class->load_json_string($string);
+ }
+ else { # maybe doc-marker-free YAML
+ return $class->load_yaml_string($string);
+ }
}
sub load_yaml_string {
=head1 VERSION
-version 1.4413
+version 1.4414
=head1 SYNOPSIS
If the source was UTF-8 encoded, the string must be decoded before calling
C<load_json_string>.
+=head2 load_string
+
+ my $metadata_structure = Parse::CPAN::Meta->load_string($some_string);
+
+If you don't know whether a string contains YAML or JSON data, this method
+will use some heuristics and guess. If it can't tell, it assumes YAML.
+
=head2 yaml_backend
my $backend = Parse::CPAN::Meta->yaml_backend;
my $meta_json = catfile( test_data_directory(), 'META-VR.json' );
my $meta_yaml = catfile( test_data_directory(), 'META-VR.yml' );
+my $yaml_meta = catfile( test_data_directory(), 'yaml.meta' );
+my $json_meta = catfile( test_data_directory(), 'json.meta' );
+my $bare_yaml_meta = catfile( test_data_directory(), 'bareyaml.meta' );
### YAML tests
{
{
local $ENV{PERL_YAML_BACKEND}; # ensure we get CPAN::META::YAML
+ is(Parse::CPAN::Meta->yaml_backend(), 'CPAN::Meta::YAML', 'yaml_backend()');
+ my $from_yaml = Parse::CPAN::Meta->load_file( $yaml_meta );
+ is_deeply($from_yaml, $want, "load from YAML .meta file results in expected data");
+}
+
+{
+ local $ENV{PERL_YAML_BACKEND}; # ensure we get CPAN::META::YAML
+
+ is(Parse::CPAN::Meta->yaml_backend(), 'CPAN::Meta::YAML', 'yaml_backend()');
+ my $from_yaml = Parse::CPAN::Meta->load_file( $bare_yaml_meta );
+ is_deeply($from_yaml, $want, "load from bare YAML .meta file results in expected data");
+}
+
+{
+ local $ENV{PERL_YAML_BACKEND}; # ensure we get CPAN::META::YAML
+
my $yaml = load_ok( 'META-VR.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");
# JSON tests with JSON::PP
local $ENV{PERL_JSON_BACKEND}; # ensure we get JSON::PP
+ is(Parse::CPAN::Meta->json_backend(), 'JSON::PP', 'json_backend()');
+ my $from_json = Parse::CPAN::Meta->load_file( $json_meta );
+ is_deeply($from_json, $want, "load from JSON .meta file results in expected data");
+}
+
+{
+ # JSON tests with JSON::PP
+ local $ENV{PERL_JSON_BACKEND}; # ensure we get JSON::PP
+
my $json = load_ok( 'META-VR.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");
--- /dev/null
+abstract: 'a set of version requirements for a CPAN dist'
+author:
+ - 'Ricardo Signes <rjbs@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
--- /dev/null
+{
+ "abstract" : "a set of version requirements for a CPAN dist",
+ "author" : [
+ "Ricardo Signes <rjbs@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"
+}
+
--- /dev/null
+---
+abstract: 'a set of version requirements for a CPAN dist'
+author:
+ - 'Ricardo Signes <rjbs@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
Fix tests to support statically built perls.
+=item *
+
+L<Parse::CPAN::Meta> has been upgraded from version 1.4413 to 1.4414.
+
+Added C<load_string>, which uses heuristics to guess YAML/JSON content.
+C<load_file> will now attempt to detect YAML/JSON content if the suffix is not
+.json, .yml or .yaml.
+
=back
=head2 Removed Modules and Pragmata