http://qs321.pair.com?node_id=315960


in reply to Class::DBI - performing action on column before it is used or saved

No guarentees that this is the best solution (in fact I kinda doubt it), but.. I would probably look at using before_create & before_update triggers, TEMP column, and overriding the search method. Beware though, there may still be issues with this method when another class interacts with this one automatically through relationships (I haven't dug deep enough to work out all the bits yet...)

__PACKAGE__->columns( TEMP => qw/ password / ); __PACKAGE__->add_trigger(before_create => sub { my ($self, %args) = @_; $self->{enc_pass} = $self->encrypt_password($self->{p +assword}); }); __PACKAGE__->add_trigger(before_update => sub { my ($self, %args) = @_; $self->enc_pass = $self->encrypt_password( $self->pas +sword ); }); sub search{ my ($self, %query) = @_; my @results = $self->SUPER::search( %query ); foreach my $result(@results){ $result->password( $self->decrypt_password( $result->encpass ) ); } }

$object->password should be used to get/set the plaintext password, while in the database it is encrypted an stored as enc_pass.

cheers,

J