I am new to Moose and am trying to use it with DBIx::Class. Basic DBIC querying and updating work find, but any trigger I attempt to write does not get executed when I modify an attribute.
use Modern::Perl;
use Data::Dumper;
my $schema = My::Schema->connect(<connect str>, <usr>, <psw>) or die $!;
my $rs = $schema->resultset('Isin')->search( sid => 3929 );
my $security_obj = $rs->first;
print $security_obj->isin, "\n";
$security_obj->isin('Test1Foo'); # <- expect to see FOO printed by trigger
print $security_obj->isin, "\n";
I expect to see the trigger for 'isin' print 'FOO', but nothing happens. If I strip out DBIx::Class from the package the trigger is executed as expected.
I suspect that DBIx::Class is setting the value in a way that prevents the trigger from firing.
Unfortunately, I haven't had much luck finding resources about using DBIx::Class with Moose. What I have written is mostly based on what I found at DBIx::Class and Moose.
Am I using DBIx::Class and/or Moose wrong? Is there a different ORM that I should be using with Moose?
The package with the trigger that won't fire:
package My::Schema::Result::Isin;
use DBIx::Class;
use Moose;
use Carp;
extends 'DBIx::Class';
has 'isin' => ( is => "rw", isa => "Str", trigger => \&_mod_isin);
has 'sid' => ( is => "ro", isa => "Int");
sub _mod_isin {
print "FOO\n";
return;
};
no Moose;
__PACKAGE__->load_components('Core');
__PACKAGE__->table('isin');
__PACKAGE__->add_columns(
isin => { data_type => 'varchar2', size => 12 },
sid => { data_type => 'integer', size => 6 },
);
__PACKAGE__->set_primary_key('isin');