[Pdx-pm] standard for copy constructors in Moose?

Paul Liebert paull at peak.org
Tue Apr 26 17:56:07 PDT 2011

This is like the third time I'm having to write a copy constructor so
laziness got the best of me.  Comments?  Critiques?  Pointers to std
Moosian ways to do this etc.

It does shallow copy on unblessed references and pushes heavier lifting
off to like-named constructors for member objects.

Thanks in advance   -Paul

sub copy {
    my( $self ) = @_;

    my @kv_pairs =
        map{ $_, blessed( $self->$_ ) ? $self->$_->copy : $self->$_ }
        map{ $_->name }
        grep{ defined $_->init_arg }

    return $self->new( @kv_pairs );

More information about the Pdx-pm-list mailing list