On 4/3/07, Randal L. Schwartz <merlyn@stonehenge.com> wrote:
>     sub make_clone {
>       ## clone the object except for primary keys and new items
>       my $self = shift;
>       my %updates = @_;
>
>       my $new = (ref $self)->new;
>       for my $column ($new->meta->columns) {
>         my $getter = $column->accessor_method_name;
>         my $setter = $column->mutator_method_name;
>         if (exists $updates{$getter}) {
>           $new->$setter($updates{$getter});
>         } elsif ($column->is_primary_key_member) {
>           # do nothing
>         } else {
>           $new->$setter($self->$getter);
>         }
>       }
>       return $new;
>     }

This is very similar to an existing Helper method:

http://search.cpan.org/dist/Rose-DB-Object/lib/Rose/DB/Object/Helpers.pm#clone_and_reset

clone_and_reset() also leaves unique keys blank, but there's a bug in
the CPAN version that will cause it to fail if your accessor and
mutator method names are different, or if columns lack accessors
and/or mutators.  (Fixed in SVN.)

-John

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object

Reply via email to