develooper Front page | perl.perl6.language | Postings from July 2005

Autogenerated attribute accessor names

Thread Next
From:
Stevan Little
Date:
July 5, 2005 16:26
Subject:
Autogenerated attribute accessor names
Message ID:
200507051726.AA1792803112@mail.iinteractive.com
Hello,

As I am building the metamodel, I had a question, I did not find anything specifically in 
the docs regarding this.

What should I do when I encounter two attributes which can peacefully co-exist as 
attributes, but cause a class when we autogenerate the accessors for them. Here is a 
quick example:

class Foo {
	has @.bar;
	has $.bar;
}

Should $.bar win out because it is defined last? Or would @.bar win because it would 
create the accessor first, then when an attempt to create the accessor for $.bar is made, 
it will see an entry for bar() already in the class, and so not generate one (as that is the 
default behavior when a user-created bar() is made)?

Should we enforce something along the lines of method conflict in roles? So that any 
conflicts for autogenerated accessor methods will result in neither of them being 
generated and therefore force the user to disambiguate manually?

On some level this might be able to be handled with MMD, and call context detection, 
but I think that might actually make things far more confusing than they actually need 
to be, but that is just MHO. Especially since it would create difficulties when something 
like this is encountered.

class Foo {
	has @.bar;
	has $.bar;

	# the autogenerated mutli method accessors
	# multi method bar(Array @value) returns Array;
	# multi method bar(Scalar $value) returns Scalar;

	method bar () {...}
}

Unless of course we use Yuval's "everything is a MMD under the hood" idea. But that is 
another thread entirely.

Thanks,

Stevan



Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About