Creating a Simple DSL in Perl
Let's look at the XSPF playlist format. It's a pretty simple XML-based file format.
<?xml version="1.0" encoding="UTF-8"?> <playlist version="1" xmlns="http://xspf.org/ns/0/"> <title>80's Music</title> <trackList> <track> <title>Take On Me</title> <creator>A-ha</creator> <location>https://example.com/music/01.mp3</location> </track> <track> <title>Tainted Love</title> <creator>Soft Cell</creator> <location>https://example.com/music/02.mp3</location> </track> <track> <title>Livin' on a Prayer</title> <creator>Bon Jovi</creator> <location>https://example.com/music/03.mp3</location> </track> </track> </trackList> </playlist>
The full specification has a lot more details, but for now, we'll just use those elements.
If we are building a Perl application that needs to allow less experienced users to write playlists in Perl, it might be useful to define a domain-specific dialect of Perl for writing playlists.