Permalink
Browse files

* all of _additional_rules now does not warn on uninitialized values

  • Loading branch information...
1 parent 9bca4d1 commit ccd36286ff0c6b91272b9fed3f27c6d4cf480074 @eserte committed Nov 8, 2010
Showing with 12 additions and 2 deletions.
  1. +1 −1 lib/Kwalify.pm
  2. +11 −1 t/Kwalify.t
View
@@ -77,6 +77,7 @@ sub _validate {
sub _additional_rules {
my($self, $schema, $data, $path) = @_;
+ no warnings 'uninitialized'; # legal undef values may happen everywhere
for my $schema_key (keys %$schema) {
if (defined $schema->{$schema_key}) {
if ($schema_key eq 'pattern') {
@@ -118,7 +119,6 @@ sub _additional_rules {
if (!UNIVERSAL::isa($schema->{enum}, 'ARRAY')) {
$self->_die("'enum' must be an array");
}
- no warnings 'uninitialized'; # undef amongst the enum values may be intended!
my %valid = map { ($_,1) } @{ $schema->{enum} };
if (!exists $valid{$data}) {
$self->_error("'$data': invalid " . _base_path($path) . " value");
View
@@ -25,7 +25,7 @@ BEGIN {
my $yaml_syck_tests;
BEGIN {
$yaml_syck_tests = 38;
- plan tests => 2 + $yaml_syck_tests + 38;
+ plan tests => 2 + $yaml_syck_tests + 40;
}
BEGIN {
@@ -710,6 +710,16 @@ EOF
ok(validate($schema, undef), "enum with undefined value");
}
+{
+ my $schema =
+ {
+ type => "any",
+ pattern => '/^(|something)$/',
+ };
+ ok(validate($schema, 'something'), "legally undefined pattern");
+ ok(validate($schema, undef), "legally undefined pattern");
+}
+
SKIP: {
skip("Don't bother with warnings on old perls without warnings.pm", 1)
if $] < 5.006;

0 comments on commit ccd3628

Please sign in to comment.