moritz has asked for the wisdom of the Perl Monks concerning the following question:
Lots of people who wouldn't touch source filters now write such syntax extensions like MooseX::Declare, and they seem to be well accepted.
However I still have some measure of reserve towards them, which I'd like to discuss with you. There are basically two reasons why source filters are wildly considered very evil™:
- Source filters have to parse Perl code. This is very hard, so sooner or later they fail, leading to errors which are very hard to track
- Since source filters have to parse Perl code themselves, you can't generally combine two source filters, even if they change different parts of the syntax
Now I read that Devel::Declare only hooks on barewords, and use the built-in parser for the rest.
But still the syntax changing module has to parse something. For example MooseX:::Method::Signature allows things like:
method hello (Str :$who, Int :$age where { $_ > 0 }) { ... }
It is my hope that the where-block allows arbitrary Perl code. Is that true? And if so, is the "real" Perl parser used for parsing it? And if yes, can other syntax changes based on Devel::Declare be used in this block?
If the answer to all three questions above is "yes", then I'm happy to acknowledge that Devel::Declare is really a good thing, and worth using (and actually comes quite close to "real" macros, except in scope of what can be changed).
If not, I'd argue that D::D based syntax changes are only gradually less evil than source filters, not conceptionally less evil.
What do you think? Does anybody have experience if D::D based syntax changes are really robust?
Update: tye++ pointed me to the reviews of TryCatch, which says
Great module for try/catch sugar in perl. I love pairing it with Moose::Util::TypeConstraints to have type based exception handling. Make sure that you have the latest Devel::Declare or you can have some weird issues that won't seem to make any sense.
The last sentence seems to suggest that it's not robust, or at least it was not. Still the question remains if it's a conceptional fault, or merely a lacking implementation right now.
|
---|