Subject: | Field append overrides field from base class |
When loading a base class the derived class overrides a field entirely when using ++ to alter/append the field. I've included a test case that clearly shows this. The expected output of the test would be that all test succeed.
F:\Projects\Validation-Class-7.900057\Validation-Class-7.900057>prove -l -v t\override-bug.t
t\override-bug.t ..
# Failed test 'base: foo not required'
# at t\override-bug.t line 16.
not ok 1 - base: foo not required
ok 2 - derived: foo is required
ok 3 - derived: foo is required
not ok 4 - base: foo not required# Failed test 'base: foo not required'
# at t\override-bug.t line 21.
# Looks like you failed 2 tests of 4.
1..4
Dubious, test returned 2 (wstat 512, 0x200)
Failed 2/4 subtests
Test Summary Report
-------------------
t\override-bug.t (Wstat: 512 Tests: 4 Failed: 2)
Failed tests: 1, 4
Non-zero exit status: 2
Files=1, Tests=4, 0 wallclock secs ( 0.05 usr + 0.03 sys = 0.08 CPU)
Result: FAIL
Subject: | override-bug.t |
package TestBase;
use Validation::Class;
field foo => {required => 0,};
package TestDerived;
use Validation::Class;
set 'role' => 'TestBase';
field '++foo' => {required => 1,};
package main;
use Test::More;
use strict;
use warnings;
my $base = TestBase->new(params => {foo => undef});
ok($base->validate('foo'), 'base: foo not required');
my $derived = TestDerived->new(params => {foo => undef});
ok(!$derived->validate('foo'), 'derived: foo is required');
$derived->foo('bar');
ok($derived->validate('foo'), 'derived: foo is required');
ok($base->validate('foo'), 'base: foo not required');
done_testing();