Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

How do I parse CPAN .meta files

by 1arryb (Acolyte)
on Jan 19, 2013 at 00:27 UTC ( [id://1014156]=perlquestion: print w/replies, xml ) Need Help??

1arryb has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

I build an index from a CPAN mirror (downloaded from rsync.nic.funet.fi::CPAN). The .../AUTHORS/ID/ area of the mirror contains the actual module .tar.gz archives. Next to most of these files is a .meta file with the same name. I've included a typical one at the end of my post. My question is, what module should I use to parse this file? I cannot find any references to .meta files on CPAN. .yml, yes. .json, also. But no .meta. I tried to parse the files anyway with Parse::CPAN::Meta, but without luck. I'd like to avoid re-inventing this wheel if I can. Thanks!

$ cat AUTHORS/ID/C/CH/CHENRYN/Message-Passing-Filter-Regexp-0.02.meta { "abstract" : "Regexp Capture Filter For Message::Passing", "author" : [ "chenryn <rao.chenlin@gmail.com>" ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 6.62, CPAN::Meta::Con +verter version 2.112150", "license" : [ "unknown" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Message-Passing-Filter-Regexp", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : 0 } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : 0 } }, "runtime" : { "requires" : { "Config::Tiny" : 0, "JSON::Types" : 0, "Message::Passing" : "0.11", "Regexp::Log" : 0 } } }, "release_status" : "stable", "version" : "0.02" }

Replies are listed 'Best First'.
Re: How do I parse CPAN .meta files
by davido (Cardinal) on Jan 19, 2013 at 01:59 UTC

    That's JSON. JSON ought to do the trick, or minimally JSON::Tiny:

    use Data::Dumper; use JSON::Tiny; my $json = do { local $/ = undef; <DATA>; }; my $hash = JSON::Tiny->new->decode($json); print Dumper $hash; __DATA__ { "abstract" : "Regexp Capture Filter For Message::Passing", "author" : [ "chenryn <rao.chenlin@gmail.com>" ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 6.62, CPAN::Meta::Con +verter version 2.112150", "license" : [ "unknown" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Message-Passing-Filter-Regexp", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : 0 } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : 0 } }, "runtime" : { "requires" : { "Config::Tiny" : 0, "JSON::Types" : 0, "Message::Passing" : "0.11", "Regexp::Log" : 0 } } }, "release_status" : "stable", "version" : "0.02" }

    I won't bother dumping the output here, but it does work. ;)

    As for understanding the spec itself, there's CPAN::Meta::Spec

    Or more minimally, as a one-liner: perl -0777 -MData::Dumper -MJSON::Tiny -e 'print Dumper( JSON::Tiny->new->decode( <> ) );' file.txt


    Dave

Re: How do I parse CPAN .meta files
by zwon (Abbot) on Jan 19, 2013 at 01:58 UTC

    .meta files are either YAML or JSON. Try the following script:

    use 5.010; use strict; use warnings; use DDP; use YAML::XS qw(LoadFile); my $ref = LoadFile($ARGV[0]); p $ref;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1014156]
Approved by davido
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-23 19:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found