New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
There should be a way of change the default class for sigiled attributes on custom classes #220
Comments
Maybe we could, when creating a new type and generating an attribute, it could call a method on its metaclass (maybe something like |
Can you provide some examples? Because otherwise it can be hard to see why there should be a way to do that. Edit: to clarify, I would like to see a code example where a feature like this can make someone's life easier. |
@AlexDaniel I can probably give an example:
Very rough, but hope the idea is understandable. |
I am thinking of using that on modules, I think if you are writing a custom metaclass you should be able to do any change you need on the way it creates its types. component Todo {
has Str $.title;
has Bool $.done;
method body {
# it will probably be a html slang, but...
"{ $!done ?? "DONE" !! "" } { $!title }"
}
}
component App {
has Todo @.todos;
method body {
# it's just an example, it should not say anything, just return some objects
say "{ @!todos.elems } todos:";
# render uses body and returns its return
.render.say for @!todos
}
} |
I wonder, if you change the meaning of sigils this way, how would a user
specify that a certain attribute should not be magical, e.g. it's just some
internal thing that's not actually connected to the UI?
|
You can always specify the type you want with something like: |
@FCO Untested, but I believe this is already possible by reusing the same mechanism the
|
Following what I described, by writing the |
In a weird bit of timing, I actually was looking at the code relating to this yesterday (working on the RakuAST support for packages), and pondering whether the |
@jnthn You mean something like this? https://glot.io/snippets/fqez0g83zh |
@jnthn does that exists something like that for methods/submetods? |
Yes, although
No, though you can always mix into each of them during |
It should be a way of using different/custom classes for Positional, Associative and Scalar by default.
The text was updated successfully, but these errors were encountered: