MattLG has asked for the wisdom of the Perl Monks concerning the following question:
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 : : : }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Overriding method in multiple DBIx::Class child classes
by Your Mother (Archbishop) on Sep 16, 2016 at 16:33 UTC | |
by MattLG (Beadle) on Sep 19, 2016 at 09:45 UTC | |
by Your Mother (Archbishop) on Sep 19, 2016 at 12:59 UTC | |
|
Re: Overriding method in multiple DBIx::Class child classes
by talexb (Chancellor) on Sep 16, 2016 at 14:16 UTC | |
by MattLG (Beadle) on Sep 19, 2016 at 09:46 UTC | |
|
Re: Overriding method in multiple DBIx::Class child classes
by trwww (Priest) on Sep 21, 2016 at 19:52 UTC |