Skip Menu |
 

This queue is for tickets about the Validation-Class CPAN distribution.

Report information
The Basics
Id: 124086
Status: open
Priority: 0/
Queue: Validation-Class

People
Owner: Nobody in particular
Requestors: c.kras [...] pcc-online.net
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Field append overrides field from base class
Download (untitled) / with headers
text/plain 952b
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
Download override-bug.t
text/x-perl 638b
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();
Download (untitled) / with headers
text/plain 590b
I dug around and I think I found the solution. I noticed that the memory address of the fields of both the base and inherited class were the same. The solution to this issue is simply using clone(). At https://metacpan.org/source/AWNCORP/Validation-Class-7.900057/lib/Validation/Class/Prototype.pm#L1736: Change that line to: my $role_profile = clone($role_proto->configuration->profile); And make sure to include: use Clone 'clone'; This passes my included test and the rest of the testsuite. Do you have a public Git repository for this module so I can submit a proper fix?


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.