Hi Montgomery,

I don't have a ready answer to your problem, but I'm going to discuss what I 
feel is a more general issue, which I've been thinking about it the past few 
days.

On Tuesday 20 Apr 2010 04:01:09 Montgomery Conner wrote:
> Hi All,
> 
> I've got a question that I didn't see addressed in any of the fine Moose
> documentation... or maybe I just missed it. At any rate, it seems like a
> common enough case that I thought others may benefit from my problem...
> 
> Say I have an attribute that represents a one-to-many relationship
> implemented as a HashRef of ArrayRef of Str: that is, I have a list of
> keys, each of which is associated with a corresponding list of tags.
> 
> I'd like to use the Moose::Meta::Attribute::Native::* trait-methods to
> simplify these accesses if possible.
[SNIP]
> 
> If chaining M::M::A::N handlers isn't natively possible, does anyone have a
> suggestion for a better way to implement the functionality I'm describing?
> Since a Trait is a Role under-the-covers (or so I've read) would I be able
> to simply implement a new Role to handle a "compound-trait", then just
> declare e.g. "traits => [ 'HashofArray' ]" and implement attribute-specific
> aliases in this attribute to my new Role's methods?

I've been thinking about chaining / function composition in the context of 
Moose (and Perl in general). For example I have an array ref called 
_tags_stack for which I did:

[code]
handles =>
{
        '_get_tag' => 'get',
},
[/code]

And then wrote this:

[code]
sub _top_tag
{
        my $self = shift;
        
        return $self->_get_tag(-1);
}
[/code]

And I recall wanting to do a lot of method / value-lists composition / 
chaining with a convenient syntax in the past. Now Haskell has a convenient 
syntax for function composition (I think it's ":", but it may be "$" or 
something else), but it's not very object oriented.

Perhaps we can extend handles to be something like:

[code]
handles =>
{
        '_get_get' => ['get1', 'get2'],
}
[/code]

(Syntax may be made better.)

Of course now the million dollar question is whether it should be $self-
>field->get1->get2 (Law of Demeter anyone?) or $self->field->get1($self-
>get2()). But it still seems like something to consider.

Regards,

        Shlomi Fish

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
Funny Anti-Terrorism Story - http://shlom.in/enemy

Deletionists delete Wikipedia articles that they consider lame.
Chuck Norris deletes deletionists whom he considers lame.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

Reply via email to