Stevan,

The case for this is based on functional programming and generic functions,
but applied to attributes.  Moose provides some great  building blocks for
code, but does not provide an easy, straightforward for generics.

For instance, I can use *has "+..."* to change the properties of
attributes.  I can use *traits* to change the properties.  And I can use
roles to make reusable attributes.  But there does not seem to handle
generic attributes.  And rename_attribute (and other functions) seems like
one allow generics and seems like missing functionality.

I am pretty tired of writing  attribute specifications.   All my attributes
are essentially the same.  They are dates, they are filenames, they are
strings, they are names, they are directories.  My perl programs are
littered with *has* *=>* definitions.  That are often repeated.  The good
programmer in me says that I should put these reusable codes in modules and
release them on CPAN. My hopes is to put these common attributes into a
Moose Role and use them with some construct like:

with Attributes( date,  name );

The catch is that the attributes, though providing the same functionality
based on the Type, do not always have the same name.  I often want an API to
have attributes with different names.  "Date" might be "begin_date" or
"name" might be "last_name" for instance.

I was thinking that it would be nice to abstract thisas a set of Perl
Modules that provided both the attributes and attribute behaviors for very
common attributes.  I see this as a step up to custom type declarations.
Another case might be if I have two attributes each with the same behavior.
I can say

has "infile" =>
has "outfile" =>

or

has qw( infile outfile ) =>  ...

But I much rather say something like

    with Attributes( infile => "file", outfile=> "file" )


I suppose one solution would be to create a module that returns the
definition of the attribute rather than the attribute itself

    use MooseX::Common::Attributes;
    my $mca = MooseX::Common::Attributes->new;
    has qw(infile, outfile) => $mcs->file;

But that gets uglier.

By the way, I can see generics working on the method side.  Now if history
is a guide, here is where you tell me how to do this really dirt simply.

Thanks in Advance,

Chris




  On Wed, Sep 24, 2008 at 6:23 PM, Stevan Little <
[EMAIL PROTECTED]> wrote:

> Chris,
>
> What would be the use case for this?
>
> Also note that it is an expensive operation since it removes all the
> methods and other items associated with the attribute. A simple alias (*foo
> = \&bar) or delegate method (sub foo { shift->bar }) would be much more
> efficient and handling most of the use cases that I can think of.
>
> - Stevan
>
>
>
> On Sep 24, 2008, at 8:50 PM, Christopher Brown wrote:
>
>  Hi All,
>>
>> Decided to ask this one of the list rather than #Moose.
>>
>> Is there / should there be a *Moose::Meta::Role->rename_attribute* method?
>> It is easy to change the guts of an attribute using the *has "+"  *syntax,
>> but I have not found an official way to change the name of an attribute.
>> I
>> am wondering if Moose::Meta::Role should contain a rename_attribute method
>> that does something like the following:
>>
>>        my ( $self, $old_name, $new_name ) = @_ ;
>>
>>        my $attr = $self->meta->get_attribute( $old_name );
>>        $self->add_attribute( $new_name, $attr );
>>        $self->remove_attribute( $old_name );
>>
>> Thoughts,
>>
>> Chris
>>
>
>

Reply via email to