Hodges, Paul writes:
> How about
>
> use Baz; # assume object type
> my property foo;
> my @bar of Baz is false but foo; # maybe not what you meant?
Definitely not what you meant. Fortunately, the compiler will teach you
a thing or two about it: C<false> is not a trait.
But indeed foo would apply to @bar itself, rather then to any element
that goes into @bar later.
> If you apply a trait like false to an array, I expect it to apply to the
> "array instance object" itself and not the content, so that
> push @bar, Baz.new();
> if @bar { print "stuff"; } else { print "empty"; } # oops! false!
> if @bar[0] { print " oops"; } else { print " ok"; } # oops! not false!
> would print "empty oops" instead of "stuff ok".
>
> I'd *like* to be able to predeclare a trait or property to be distributed
> across any values placed in this array, but only this array. For example, it
> would be nice if I could have the default aspects of false and foo be
> applied to any Baz that gets stuck into @bar, but obviously this isn't the
> syntax to do it. I could make Baz's new() do it, but I don't want *ALL* Baz
> objects to be false and foo...just the ones in @bar. So, what I need is
> something more like
>
> my @bar of Baz;
> @bar.STORE.wrap { my $r = call; return $r >>but=<< (false,foo); }
Something likely more like:
my role property_wrap[Property [EMAIL PROTECTED] {
method STORE($newval) { SUPER::STORE($newval but [EMAIL PROTECTED]) }
}
@bar but= property_wrap[false, foo];
With emphasis on "something". (Extrapolating wildly the little bit I
know about roles and making up some semantics, such as C<but [EMAIL PROTECTED]>).
As for just declaring it, um... why would you want to do that? I could
see making the array default to some value with a trait, which is
trivially:
my @bar is default(undef but foo);
But automatically marking every value that ever goes into the array... I
don't see the utility.
> But I'm not sure C<$r >>but=<< (false,foo)> works, and I really wanted to
> figure out a way to do it all in the declaration. Maybe it could be
>
> my @bar of Baz will do STORE.wrap { call >>but=<< (false,foo); }
Yeah, that's definitely not right. C<will> works as follows:
:w <declaration> will <identifier> <block>
It's really just a shorthand for C<is>, so you don't have to put parens
around the block.
> but I'm not sure call will behave as an lvalue and still set up the
> appropriate return, I don't expect @bar to accept "will do", and I don't
> think "will do" is where the wrap should go. I'm just trying to wrap my
> brain around this brick and I can't find all the references that tell me all
> the little pieces so that I can compare them for a closer approximation,
> lol....
Luke