On Tue, Oct 05, 2010 at 04:35:46PM -0700, Alex Aalto wrote:
> Hello all!  I'm an old but rusty Perl programmer - and a noob to the
> modern Perl frameworks.  I'm inheriting a site that uses Catalyst and
> Kioku but am getting the following error when trying to instantiate an
> object User.pm:
> 
>  User->register "Attribute (id) is required at
> /home/alex/Desktop/ParkingMobility-Server/script/../support/lib/perl5/MooseX/Aliases/Meta/Trait/Attribute.pm
> line 70
> 
> ...the User.pm object looks like:
> 
> package MyProject::Model::User;
> use Moose;
> use namespace::autoclean;
> use MooseX::Aliases;
> use MooseX::Types::Email qw/EmailAddress/;
> 
> with qw(
>   KiokuX::User
>   MyProject::Data::Serialize
>   MyProject::Data::ObjectKey
>   MyProject::Model::Does::TimeStamp
>   KiokuDB::Role::Upgrade::Handlers::Table
> );
> 
> has email => (
>     isa      => EmailAddress,
>     is       => 'ro',
>     traits   => [qw(Aliased)],
>     alias    => [qw(id kiokudb_object_id key)],
>     required => 1,
> );
> 
> Can someone explain to me why the "id" attribute alias is not being
> picked up?  Shouldn't "email" and "id" now be synonymous now that it's
> "Aliased"?  I've tried to define an "id" attribute but this results in
> an error telling me that I'm attempting to override the attribute "id"
> (defined in KiokuX::User).

This isn't quite how MooseX::Aliases works - all it does is give an
attribute an alternate accessor, and make the attribute also look for an
additional name in the constructor. It's not affecting the 'id'
attribute at all, and the 'id' attribute is still required. What you
should be doing here is aliasing in the other direction:

    has '+id' => (
        alias => [qw(email kiokudb_object_id key)],
    );

This tells the 'id' attribute to also look for its value in the 'email'
argument passed to the constructor, which is what you want.

-doy

Reply via email to