[Israel.pm] Fwd: [Telux] Next Meeting: "High-Level Programming Concepts Using Perl 6" on 22-March

Mikhael Goikhman migo at homemail.com
Sat Mar 14 16:04:36 PDT 2009


On 15 Mar 2009 00:15:03 +0200, Evgeny wrote:
> 
> The requirements are simple
> 
> They are:
>     Word regular_expression block_of_code
> 
> Where:
>   word is Given/When/Then. Currently I use a function name for this.
>   regular_expression is just that, a regexp
>   block_of_code is an anonymous function, or callback, or call it what you like
> 
> Current minimal syntax for doing this, in perl, as I have found with
> your really really greatly appreciated help is this:
> 
> Given qr/a color (.*)/, sub {
>   $color = shift;
> };

This is probably the best you may achieve for these requirements if we
speak about writting a generic DSL.

> Every character that I wrote (other that the inside of the block) is
> significant. And if only I could make the "qr" and the comma and the
> "sub" go away, it would be just perfect. But it is not bad as it is
> right now really. Quite DSLish :)
> 
> Any way to turn it into :
>   Given /a color (.*)/ {
>     $color = shift;
>   }

This syntax is possible in Perl 6, AFAIK.

If you feel _really_ adventurous and advanced, try source filters.
"perldoc perlfilter".

But do you really need a DSL? My practice shows that even non-technical
people may handle simple perl easily, i.e. to write configs in perl.

So consider not to use custom functions and just use "given" and "when"
from perl 5.10. Read "perldoc perlsyn" under Switch statements section.

Regards,
Mikhael.

-- 
perl -e 'print+chr(64+hex)for+split//,d9b815c07f9b8d1e'



More information about the Perl mailing list