|
From: Chris W. <la...@us...> - 2001-11-26 16:27:23
|
Update of /cvsroot/openinteract/SPOPS/SPOPS/ClassFactory
In directory usw-pr-cvs1:/tmp/cvs-serv32210/SPOPS/ClassFactory
Modified Files:
DBI.pm
Log Message:
fixed behavior in clone() method -- multifield checks are now
generated by the multifield class factory behavior, and the previous
clone() behavior has been restored. (Thanks to Ray Z for catching.)
Index: DBI.pm
===================================================================
RCS file: /cvsroot/openinteract/SPOPS/SPOPS/ClassFactory/DBI.pm,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** DBI.pm 2001/11/25 01:26:13 1.13
--- DBI.pm 2001/11/26 16:27:19 1.14
***************
*** 66,69 ****
--- 66,96 ----
my $generic_multifield_etc = <<'MFETC';
+ sub %%CLASS%%::clone {
+ my ( $self, $p ) = @_;
+ my $class = $p->{_class} || ref $self;
+ DEBUG() && _w( 1, "Cloning new object of class ($class) from old ",
+ "object of class (", ref $self, ")" );
+ my %initial_data = ();
+
+ my %id_field = map { $_ => 1 } $class->id_field;
+
+ while ( my ( $k, $v ) = each %{ $self } ) {
+ next unless ( $k );
+ next if ( $id_field{ $k } );
+ $initial_data{ $k } = $p->{ $k } || $v;
+ }
+
+ my $cloned = $class->new({ %initial_data, skip_default_values => 1 });
+ if ( $p->{id} ) {
+ $cloned->id( $p->{id} );
+ }
+ else {
+ foreach my $field ( keys %id_field ) {
+ $cloned->{ $field } = $p->{ $field } if ( $p->{ $field } );
+ }
+ }
+ return $cloned;
+ }
+
sub %%CLASS%%::id_field {
return wantarray ? %%ID_FIELD_NAME_LIST%%
|