Recently there has been quite a hype about syntax extensions to Perl that don't work via traditional source filters, but through Devel::Declare.

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™:

  1. 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
  2. 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.

Perl 6 - links to (nearly) everything that is Perl 6.

In reply to Is Devel::Declare really so much less evil than source filters? by moritz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.