James Mastros wrote:
>
> As far as setting|getting, I'd like to make a simple proposal. Consider it
> an idea for whoever writes the RFC (I'm looking at you, Nate)
Oh, jeez, as if I didn't have enough already! ;-)
> The idea is this: every variable should have a psudohash of attributes.
Idea is good, implementation I think should be different. Especially
since Schwern has professed "pseudohashes must die!".
> To access the attribhash, you'd use somthing like this:
> my($scalar,@array,%hash,^placeholder,&sub);
> my %arraysattribs = %@array:;
> my $subsline = $&sub:{line};
>
> print "\%hash has the following attributes:\n";
> foreach (keys %%hash:) {
> print "\$\%hash:{$_} = ", $%hash:{$_}, "\n";
> }
>
> $subsattribsref = \%&sub:;
Here's what I'm thinking: a new builtin, attr(). This might also be
implementable as UNIVERSAL::attr.
Syntax would be such:
@attrs = $object->attr;
@attrs = attr %hash;
$is_fluffy = attr %hash, 'fluffy'; # query a specific attribute
Another keyword could be 'is', which is cuter:
$can_puff = is %hash, 'fluffy';
but it's way too close to 'isa' for my tastes. If attributes were the
proper tense then 'has' would work:
$nice_coat = has $spot, 'fluffiness';
which I kinda like.
The attr keyword could be overloaded to also do sub/struct-like
definitions, as specified in RFC 337.
However, overall I think this should be hidden. The internal magic of
attributes will likely not map 1:1 to hash keys, so requiring what is
essentially an accessor function for these is probably a good thing.
That way, attributes can be applied to objects, packages, subs, and
other things that don't have variable representations:
package BigInt : autotie;
package main;
if ( has BigInt 'autotie' ) {
# class is automatically tied...
}
The declaration of attrs is proposed vaguely in RFC 337. I'll add access
before the freeze.
-Nate