For any given result class MySchema::Result::Foo (built from default schema loader generated syntax which uses Moose/MooseX::nonmoose)
If I add a BUILDARGS method wrapper to sanitize the constructor data for a row like so:
package MySchema::Result::Foo;
use Moose;
use MooseX::NonMoose;
[etc ..]
around 'BUILDARGS' => sub {
my $orig = shift;
my $class = shift;
delete $_[0]->{not_a_real_column};
return $class->$orig(@_);
};
It works when using the schema directly. For example the following works as expected: A new row object is created with real_column=>'value' and not_a_real_column removed before ->new is called
use MySchema;
my $s = MySchema->connect('dbi:blahblahblah');
$s->resultset('Foo')->new({ real_column=>'value', not_a_real_column=>'some other thing' }); #win
However, when using the same schema via Catalyst::Model::DBIC::Schema the order is different. The following fails when trying to create a new Foo row object because not_a_real_column is invalid. In other words the arguments to new are not run through BUILDARGS before ->new is called.
$c->model('MySchemaModel')->resultset('Foo')->new({ real_column=>'value', not_a_real_column=>'some other thing' }); #fails
Interestingly enough, if I wrap around 'new' => sub{} instead of around 'BUILDARGS' => sub{} the behavior is the same in both cases, and works fine, but to my understanding Moose dogma states to never mess with new.
Anyone care to help me understand why this is the case, or if there's a better way?
I see, you are using MooseX::NonMoose.
Given that, I have a guess that you need to use FOREIGNBUILDARGS
around 'FOREGINBUILDARGS' => sub {
my $orig = shift;
my $class = shift;
delete $_[0]->{not_a_real_column};
return $class->$orig(@_);
};
"MooseX::NonMoose allows you to manipulate the argument list that gets passed to the superclass constructor by defining a FOREIGNBUILDARGS method."
http://metacpan.org/pod/MooseX::NonMoose
I really hope this works for you!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With