[CDBI] Different subclasses for one table / Factory Pattern?

Oliver Jeeves oj at defuturo.co.uk
Tue Sep 5 13:53:56 BST 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Stephan Brunner wrote:
> Another possibility seems to be Class::DBI::Plugin::Factory, which (if I 
> understood correctly) hooks into the select-trigger and reblesses the given 
> object.

I'm trying to do something similar at the moment, and after reading
this, have implemented it as a select trigger. The code looks like this:

##########
__PACKAGE__->add_trigger(select	=> \&rebless);

sub rebless
{
	my $self	= shift;
	
	my $class = 'My::Base::Class::' . $self->type;
	bless $self, $class;
	
	$self->__service_init;
	
	#return $self;
}


## Sub classes should overload this if they need any extra
## initialisation...
sub __service_init
{
}
##########


All the other classes should (although there's not guarentee) inherit
from this class, so will still be CDBI objects.

This seems to work ok.

My question is; can I add extra might_have relationships to the
subclasses? Is there any reason why this wouldn't work (eg. does the
code need to know about them when the object is initialised)? Is the
behaviour of doing this sort of thing likely to change in the future?

- -Oli
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)

iD8DBQFE/XNkSbWXajvTQ+URAswwAJ0ejN5wGZbx7SY0wK+OQVox83QcBwCgm0dC
fmFn5smX4fvrOvyBzGKatn0=
=RfnT
-----END PGP SIGNATURE-----



More information about the ClassDBI mailing list