PrePAN

Sign in to PrePAN

MooX::AutoConstructor Extend accessors to automatically call constructors if needed

Good

Synopsis

{
  package Artifact;
  use Moo;
  use MooX::AutoConstructor;
  
  has creator => ( is => 'rw' );

  autoconstructor creator => 'Person';
}

my $a = Artifact->new;
$a->artifact( 'Smith', 'Alice' ); # calls  $a->artifact( Person->new( 'Smith', 'Alice' ) );

Description

I asked for the functionality here at stackoverflow. Did I miss another way to do it, already build into Moo?

Maybe this module should better be named Class::Accessor::AutoConstructor (although not related to Class::Accessor::Constructor)?

Comments

I renamed the package to [Class::Accessor::Coerce](http://prepan.org/module/nXWJ8Y9sBiu)

Please sign up to post a review.