I have a series of DBIx::Class classes that have been auto-generated by the Schema Loader.
I also want to maintain an audit trail of changes to any database table entries, so I've started overriding the update() method on each. But after the first couple, I've realised that the overrides will actually be completely identical.
I'd obviously rather not duplicate 35 lines of identical code in all 20 classes if I can get away with it. What is the best way to achieve this?
--------------------- | DBIx::Class::Core | | update() | --------------------- / | | \ / | | \ ------------ ------------ ------------ ------------ | Table A | | Table B | | Table C | | Table D | ....... | update() | | update() | | update() | | update() | ------------ ------------ ------------ ------------
The first option that I considered was multiple inheritance, but the overriding method needs to call its parent method in the DBIx::Class::Core:
sub update { my __PACKAGE__ $self = shift; # Pre-processing : : : # Call the parent method $self->next::method(\%new_values); # If successful, record audit trail : : : }
In reply to Overriding method in multiple DBIx::Class child classes by MattLG
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |