Keyword::Simple is super easy to use. You choose a keyword, say, "foo", and set up a handler for it like this:

package My::Keyword; use Keyword::Simple; sub import { Keyword::Simple::define(foo => \&_parse_foo); } sub _parse_foo { ...; } 1;

Then when someone uses your keyword (this is at compile time!) the _parse_foo sub will be called. It will be given a single parameter: a scalar ref - the reference to the string of Perl code currently being compiled. Now the _parse_foo can change that string, to change what gets compiled by Perl.

Syntax::Keyword::Val is a really simple example. The val keyword simply gets rewritten to Data::Lock::dlock my, so when people code this:

val $foo = 42;

That Perl code is rewritten to:

Data::Lock::dlock my $foo = 42;

Moops employs a lot of Keyword::Simple trickery.

use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name

In reply to Re^5: OX and routing: how to declare something like /api/action.:format ($DEBUG++ MANIFEST) by tobyink
in thread OX and routing: how to declare something like /api/action.:format by mascip

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.