Your question was nearly incomprehensible because you start out with a code example that is simply a syntax error. My first guess was that you were asking a Perl6 question but didn't bother to say so.

The problem you'll run into is more likely that you can't have two different prototypes for class() (plus a bunch of other problems). But ignoring your first proposal, sub class(&), (since it is probably incompatible with your primary question) you are incorrect in your thinking on how to make class 'Foo' is { ... } work...

The prototype for sub class shouldn't be ($&) since you aren't putting a block as the second argument to class() (tho, & only really works for first arguments anyway). Your second argument to class() is a plain expression that returns a code reference. The prototype of is() is what handles the bare block, not the prototype of class() at all.

The next problem is that you don't want to put a comma between 'Foo' and is{...}. That means you've got that extra-vague syntax that /might/ get interpretted as indirection object syntax (but might not, and is pretty easy to break besides).

So, Perl might interpret your code as 'Foo'->class( is { ... } ) (but it might not, depending).

But my primary advice is to turn back now. Please don't make another module that tries to fool the perl interpretter into understanding some non-Perl5 syntax. Let the people reading Perl5 code and expecting to find Perl5 code understand the code. Attempts to invent alternate syntax always end up being quite fragile; that is, they often confuse the computer in addition to confusing the human.

Next you can try source filters. I hope you have the sense not to, however.

- tye        


In reply to Re: Prototypes and hand-written MMD (Ah! No!!) by tye
in thread Prototypes and hand-written MMD by dragonchild

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.