Permalink
Browse files

Add `validate_pgxn_meta` app.

  • Loading branch information...
1 parent cf8c1f6 commit 9e76fd46b04ed529f562782eae5d7f7619dfed1b @theory theory committed May 25, 2011
Showing with 97 additions and 3 deletions.
  1. +5 −3 Build.PL
  2. +1 −0 Changes
  3. +91 −0 bin/validate_pgxn_meta
View
@@ -13,9 +13,11 @@ Module::Build->new(
},
requires => {
'Carp' => 0,
- 'JSON' => 0,
- 'perl' => 5.010,
- 'SemVer' => '0.2.0',
+ 'Getopt::Long' => 0,
+ 'JSON' => 0,
+ 'perl' => 5.010,
+ 'Pod::Usage' => 0,
+ 'SemVer' => '0.2.0',
},
recommends => {
'Test::Pod' => '1.41',
View
@@ -1,6 +1,7 @@
Revision history for Perl extension PGXN-Meta-Validator.
0.11.0
+ - Added `validate_pgxn_meta`.
0.10.0 2011-05-25T05:33:38
- Initial public release on CPAN.
@@ -0,0 +1,91 @@
+#!/usr/bin/perl -w
+
+use strict;
+use warnings;
+use PGXN::Meta::Validator;
+use Getopt::Long;
+
+GetOptions(
+ 'help|h' => \my $help,
+ 'man|m' => \my $man,
+ 'version|v' => \my $version,
+) or _pod2usage();
+
+_pod2usage(
+ ( $man ? ( '-sections' => '.+' ) : ()),
+ '-exitval' => 0,
+) if $help or $man;
+
+if ($version) {
+ require File::Basename;
+ print File::Basename::basename($0), ' ',
+ PGXN::Meta::Validator->VERSION, $/;
+ exit;
+}
+
+my $file = shift or _pod2usage();
+die "$file is not a valid, readable filename\n" unless -r $file;
+
+my $pmv = PGXN::Meta::Validator->load_file($file);
+
+if ($pmv->is_valid) {
+ print "$file is OK\n";
+ exit;
+}
+
+print "$file is invalid. Errors:\n ",
+ join("\n ", $pmv->errors),
+ "\n";
+exit 1;
+
+sub _pod2usage {
+ require Pod::Usage;
+ Pod::Usage::pod2usage(
+ '-verbose' => 99,
+ '-sections' => '(?i:(Usage))',
+ '-exitval' => 1,
+ '-input' => __FILE__,
+ @_
+ );
+}
+
+1;
+__END__
+
+=head1 Name
+
+validate_pgxn_meta - Validate the structure of a PGXN F<META.json> file
+
+=head1 Usage
+
+ validate_pgxn_meta META.json
+
+=head1 Output
+
+If F<META.json> valid, the output will be:
+
+ META.json is OK
+
+If it's not valid, the output will look something like:
+
+ META.json is invalid. Errors:
+ Missing mandatory field, 'license' (license) [Validation: 1.0.0]
+
+=head1 See Also
+
+L<PGXN::Meta::Validator> is the class that does the actual validation, and may
+be used programmatically.
+
+=head1 Author
+
+David E. Wheeler <david@kineticode.com>
+
+=head1 Copyright and License
+
+Copyright (c) 2011 David E. Wheeler. Some Rights Reserved.
+
+This module is free software; you can redistribute it and/or modify it under
+the same terms as Perl itself.
+
+=cut
+

0 comments on commit 9e76fd4

Please sign in to comment.