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
MIME-Version: 1.0
X-Mailer: MIME-tools 5.504 (Entity 5.504)
X-RT-Interface: Web
Message-ID: <rt-4.0.18-17328-1516024661-92.0-0-0 [...] rt.cpan.org>
X-RT-Original-Encoding: utf-8
Content-Type: multipart/mixed; boundary="----------=_1516024661-17328-2"
X-RT-Encrypt: 0
X-RT-Sign: 0
Content-Length: 0
Content-Disposition: inline
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: binary
Content-Length: 952
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
MIME-Version: 1.0
Content-Type: application/octet-stream; name="override-bug.t"
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Disposition: inline; filename="override-bug.t"
Content-Transfer-Encoding: base64
Content-Length: 638
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();
MIME-Version: 1.0
In-Reply-To: <rt-4.0.18-17328-1516024661-92.0-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Disposition: inline
X-RT-Interface: Web
References: <rt-4.0.18-17328-1516024661-92.0-0-0 [...] rt.cpan.org>
Content-Type: text/plain; charset="utf-8"
Message-ID: <rt-4.0.18-25259-1517912532-59.124086-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Encrypt: 0
X-RT-Sign: 0
Content-Length: 590
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.