[Dbix-class] initialize()
Matt S Trout
dbix-class at trout.me.uk
Sat Nov 19 03:01:04 CET 2005
On Fri, Nov 18, 2005 at 03:32:03PM -0500, Vsevolod (Simon) Ilyushchenko wrote:
> Hi,
>
> I'd like to see an initialize() method that is always called from new().
> Obviously, it should be an empty method in the framework's classes, but
> I'd like to be able to override this.
>
> The reason is that sometimes I need to do additional processing during
> class creation. If I'm creating a class directly, I can make sure it
> happens, but if it's created from a relationship, I have no control over it.
Do you really mean class or object here?
> I can't simply override new(), because the DBIx classes put themselves
> in the beginning of @ISA, and Class::Row->new() doesn't call NEXT, so my
> new() never gets called.
Ok. Two solutions (just because I don't have an answer when you ask me on IRC
doesn't mean I don't think about it later). The quick and dirty -
__PACKAGE__->load_components(qw/.../);
unshift(@ISA, 'My::Base::Class');
The nice one would be to think about how we can make load_components smarter
in the C3 branch - abraxxa's patch (which needs a little tweaking to its
tests but is otherwise good) will let you do
MySchema->load_classes({ 'MyOthers' => [ qw/Foo Bar/ ] },
qw/Baz Quux/);
to load MyOthers::Foo, MyOthers::Bar, MySchema::Baz and MySchema::Quux.
We could maybe adapt the concept, or perhaps I should just get on with
refactoring the core so (with a little help from C3) you don't need an ISA
list a mile long in the first place ...
--
Matt S Trout Specialists in Perl consulting, web development, and
Technical Director UNIX/Linux systems architecture and automation. Mail
Shadowcat Systems Ltd. mst (at) shadowcatsystems.co.uk for more information
+ Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +
More information about the Dbix-class
mailing list