[CDBI] Re: construct sucks.

Ryan Tate lists at ryantate.com
Sun Aug 27 21:14:02 BST 2006


Here is the relevant code from CDBI 3.0.15, latest:

sub construct {
	my ($proto, $data) = @_;
	my $class = ref $proto || $proto;
	my $self = $class->_init($data);
	$self->call_trigger('select');
	return $self;
}

sub _init {
	my $class = shift;
	my $data  = shift || {};
	my $key   = $class->_live_object_key($data);
	return $Live_Objects{$key} || $class->_fresh_init($key => $data);
}

Here is my proposed change to _init, which I filed on RT by mail:

sub _init {
        my $class = shift;
        my $data  = shift || {};
        my $key   = $class->_live_object_key($data);
        my $obj;
        if ($obj = $Live_Objects{$key}) {
          $obj->_attribute_store(%$data);
        }
        else {
          $obj = $class->_fresh_init($key => $data);
        }
        return $obj;
}



More information about the ClassDBI mailing list