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?