Skip to content

Instantly share code, notes, and snippets.

@dagolden
Created April 3, 2009 17:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dagolden/89842 to your computer and use it in GitHub Desktop.
Save dagolden/89842 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use XDG;
use Data::Rx;
use YAML::XS qw/LoadFile/;
#--------------------------------------------------------------------------#
# spec
#--------------------------------------------------------------------------#
my $spec_version = '1.4';
my $meta_spec = {
type => '//rec',
required => {
url => '//str', # actually, a URL
version => {
type => '//num',
value => $spec_version,
},
},
#optional => {rx_schema => '//def' }, # location of schema
};
my $list_of_strings = {
type => '//arr',
contents => '//str',
length => { min => 1 },
};
my $dist_type_enum = {
type => '//any',
of => [
{ type => '//str', value => 'module' },
{ type => '//str', value => 'script' },
],
};
my $prereq_map = {
type => '//map',
values => '//str', # really needs to be a PCRE string
};
my $features_spec = {
type => '//map',
values => {
type => '//rec',
requires => {
description => '//str',
},
optional => {
build_requires => $prereq_map,
requires => $prereq_map,
conflicts => $prereq_map,
},
},
};
my $no_index_spec = {
type => '//rec',
optional => {
file => { type => '//arr', contents => '//str' },
directory => { type => '//arr', contents => '//str' },
package => { type => '//arr', contents => '//str' },
namespace => { type => '//arr', contents => '//str' },
}
};
my $provides_spec = {
type => '//map',
values => {
type => '//rec',
required => {
file => '//str',
},
optional => {
version => '//str',
},
},
};
my $resources_spec = {
type => '//rec',
optional => {
license => '//str',
homepage => '//str',
bugtracker => '//str',
repository => '//str',
},
rest => '//str', # should be PCRE: /[A-Z].*/
};
my $meta_spec_1_4 = {
type => '//rec',
required => {
'meta-spec' => $meta_spec,
abstract => '//str',
author => $list_of_strings,
generated_by => '//str',
license => '//str',
name => '//str',
version => '//str',
},
optional => {
configure_requires => $prereq_map,
build_requires => $prereq_map,
requires => $prereq_map,
recommends => $prereq_map,
conflicts => $prereq_map,
distribution_type => $dist_type_enum,
dynamic_config => '//bool',
keywords => $list_of_strings,
no_index => $no_index_spec,
optional_features => $features_spec,
provides => $provides_spec,
resources => $resources_spec,
},
};
my $rx = Data::Rx->new;
my $schema = $rx->make_schema($meta_spec_1_4);
#--------------------------------------------------------------------------#
# main
#--------------------------------------------------------------------------#
my $metafile = shift @ARGV or die "usage: $0 <metafile>";
my $contents = LoadFile($metafile);
say $schema->check( $contents ) ? "Valid" : "Invalid";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment