3 CPAN::Kwalify - Interface between CPAN.pm and Kwalify.pm
8 validate($schema_name, $data, $file, $doc);
14 =item _validate($schema_name, $data, $file, $doc)
16 $schema_name is the name of a supported schema. Currently only
17 C<distroprefs> is supported. $data is the data to be validated. $file
18 is the absolute path to the file the data are coming from. $doc is the
19 index of the document within $doc that is to be validated. The last
20 two arguments are only there for better error reporting.
22 Relies on being called from within CPAN.pm.
24 Dies if something fails. Does not return anything useful.
26 =item yaml($schema_name)
28 Returns the YAML text of that schema. Dies if something fails.
34 Andreas Koenig C<< <andk@cpan.org> >>
38 This program is free software; you can redistribute it and/or
39 modify it under the same terms as Perl itself.
41 See L<http://www.perl.com/perl/misc/Artistic.html>
50 package CPAN::Kwalify;
51 use vars qw($VERSION $VAR1);
58 my $schema_loaded = {};
61 my($schema_name,$data,$abs,$y) = @_;
62 my $yaml_module = CPAN->_yaml_module;
64 $CPAN::META->has_inst($yaml_module)
66 $CPAN::META->has_inst("Kwalify")
68 my $load = UNIVERSAL::can($yaml_module,"Load");
69 unless ($schema_loaded->{$schema_name}) {
71 my $schema_yaml = yaml($schema_name);
72 $schema_loaded->{$schema_name} = $load->($schema_yaml);
75 # we know that YAML.pm 0.62 cannot parse the schema,
76 # so we try a fallback
80 $path = File::Spec->catfile($path, "$schema_name.dd");
82 open FH, $path or die "Could not open '$path': $!";
89 die "parsing of '$schema_name.dd' failed: $err";
91 $schema_loaded->{$schema_name} = $VAR1;
95 if (my $schema = $schema_loaded->{$schema_name}) {
96 my $mtime = (stat $abs)[9];
97 for my $k (keys %{$vcache{$abs}}) {
98 delete $vcache{$abs}{$k} unless $k eq $mtime;
100 return if $vcache{$abs}{$mtime}{$y}++;
101 eval { Kwalify::validate($schema, $data) };
103 my $info = {}; yaml($schema_name, info => $info);
104 die "validation of distropref '$abs'[$y] against schema '$info->{path}' failed: $err";
114 my($schema_name, %opt) = @_;
118 $path = File::Spec->catfile($path, "$schema_name.yml");
120 $opt{info}{path} = $path;
123 open FH, $path or die "Could not open '$path': $!";
134 # cperl-indent-level: 4