Taking some definitions from Wikipedia and Martin Fowlers Book: (emphasizes added)

DSLs are small languages, focused on a particular aspect of a software system. You can't build a whole program with a DSL, but you often use multiple DSLs in a system mainly written in a general purpose language.

DSLs come in two main forms: external and internal

An external DSL is a language that's parsed independently of the host general purpose language: good examples include regular expressions and CSS

Internal DSLs are a particular form of API in a host general purpose language, often referred to as a fluent interface.

They are represented within the syntax of a general-purpose language. It’s a stylized use of that language for a domain-specific purpose.

People find DSLs valuable because a well designed DSL can be much easier to program with than a traditional library.

This improves programmer productivity , which is always valuable. In particular it may also improve communication with domain experts , which is an important tool for tackling one of the hardest problems in software development.

Now there are some more frequently used examples in Perl which come to mind like SQL and Template languages like in Template::Toolkit2

[% FOREACH file=files %] [% IF ( matches = file.date.match('dd/mm/(\d+)') ) %] <a href='#'>[% matches.0 %]</a> [% END %] [% END %]

Both qualify as are for sure as DSLs.

They are sub-languages which can be used by "domain experts" without any knowledge of Perl.

And they are external, because neither SQL nor TT commands are implemented as Perl functions or follow Perl syntax.

So far for external DSLs , but what are good examples for internal DSLs in Perl?

Well designed traditional modules and classes are sometimes close to represent a sub-language but they still come with a lot of boilerplate.

For instance an expert in the domain of TCL/TK may (probably?) not care much if the "host" language is Perl or Python or Ruby as long as he can call the commonly known methods. (see http://www.tkdocs.com/ for comparison of snippets in various languages).

But the necessity to constantly repeat an $obj-> or PACK::AGE:: on the left hand side of a command doesn't make it a completely "fluent" approach.

(On a side note: avoiding to repeat this LHS for method calls seems to be the principal mechanism in Ruby for transforming a simple class to what Rubyists like to call a "DSL", a bunch of function calls inside a block are somehow interpreted as method calls on the same object, hence very similar to the with(obj) {} mechanism in JavaScript - please correct me if not)

Now, what are examples for internal DSLs in Perl?

The only widely known one which comes to my mind is CGI::HTML::Functions which used to be part of CGI

For example, here's one way to make an ordered list:
print ul( li({-type=>'disc'},['Sneezy','Doc','Sleepy','Happy']) );
This example will result in HTML output that looks like this:
<ul> <li type="disc">Sneezy</li> <li type="disc">Doc</li> <li type="disc">Sleepy</li> <li type="disc">Happy</li> </ul>

Nice but IMHO it could be even more fluent.

But are there others?

There is for instance Rex which I suppose was inspired by Ruby's Puppet

use Rex -feature => ['1.0']; desc "Get Uptime"; task "uptime", sub { say run "uptime"; }

And I think I could theoretically implement most Assembler languages as Perl code just with some minor changes. I just need to implement ASM-commands as uppercase subs, quote literals and adjust the comment symbol.

like

CPX '3' ;# Year starts in March to bypass BCS 'MARCH' ;# leap year problem DEY ;# If Jan or Feb, decrement year MARCH: EOR '$7F' ;# Invert A so carry works right ...
(original example)

But there must be more examples of internal DSLs in Perl ...

Could you please help me to find and classify them?

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!


In reply to Which internal DSL are there in Perl? (Domain Specific Languages - Part 1) by LanX

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.