Gentlemen! I bring you peace in our time!
package Foo;
use Method::Signatures;
method new (%args) {
return bless {%args}, $self;
};
method get ($key) {
return $self->{$key};
};
method set ($key, $val) {
return $self->{$key} = $val;
};
And with NO SOURCE FILTERS! Just a hairy pile of black magic that, fortunately, I didn't write!
Really the kudos goes to Matt Trout who wrote Devel::Declare and the test/demo code which I just packaged up and shipped. There are, as you can see, a few nits. That trailing semicolon for one. The other is it doesn't work on "sub" so all you get right now is methods. These are all Devel::Declare issues.
The prototype syntax is very simplistic and does no checks. Expanding on that is the easy part, or at least just a SMOP. I plan on stealing a bunch of features from Perl 6.
Horray!! (Score:1)
Very nice! My wrists thank you :)
You should stop by #moose and chat, I know mst has been planning on writing a Perl 6-ish Moose wrapper using Devel::Declare (tentatively called Moose::Declare), but has been without the tuits to do it. We also already have some work towards method signature checking with MooseX::Method, which can easily be converted to use a Devel::Declare based syntactic sugar. There has also been some talk of pulling the type system out of Moose so it is easier to use it in non-Moose s
innovative (Score:1)
I wish for customizing the name of "$self", but this is a nice start, and a welcome competitor to "self.pm", which I also liked it was a little weird because it was "self", not "$self", and didn't actually allow you to "shift" off $self through the system, just reference it.
Wow, that was a run-on sentence.
Mark
Re: (Score:1)
Re: sefvars.pm (Score:1)
I wonder if it used "Sub::Exporter", if the "self" scalar name could be easily customized, like it can for "self.pm". However, I don't see any examples in the Sub::Exporter docs of exporting scalars. (Perhaps only because it is recommended against in most cases).
Re: (Score:1)
You can customize the "self" scalar name with an import line:
Or only import self as $this but not args:
Or only import self as $self:
More suggestions are welcome as well!
Re: (Score:1)
Re: (Score:2)
Then again, I've found some fascinating bugs in Method::Signatures.
Re: (Score:1)
Re: (Score:2)
Re: (Score:1)
Re: (Score:1)
If so, how about making available a %opts so you can say:
If you wish you can even import selfvars like this, populating named options into %_:
Would that resemble what you want?
Re: (Score:1)
Unstable magic (Score:1)
I've always looked at that part of perl and gone "OMG, this is nasty looking" so perhaps this is not as horrible as I'm imagining. I just don't think it's the kind of thing of which stable software is made. In a year from now if it continues to work on 5.6 -> 5.11 I guess I could believe it then. There'll be more than enough unanticipated delta to
Re: (Score:2)