> of course TIMTOWTDI.

Autoload rules! =)

package OuterPkg; use strict; use warnings; use Carp qw/cluck/; sub foo { my $sub =(caller(0))[3]; $"=","; return "Calling $sub(@_)"; } use Import2Package 'DTD' => 'myDSL'; package myDSL { print TABLE { TR { TD {1}, TD{foo()}, } } } # TABLE(); # not visible in outer Package

exec "perl OuterPkg.pl" unless caller(); use strict; use warnings; use Carp qw/cluck/; package Import2Package; sub delegate_subs { my ( $pkg, $super )=@_; use vars '$AUTOLOAD'; no strict 'refs'; *{${pkg}."::AUTOLOAD"} = sub { my $delegate = $AUTOLOAD; $delegate =~ s/.*:://; # strip packagename goto &{"${super}::${delegate}"}; } } sub install_vocab { my ( $pkg, $super ) = @_; my @vocab = qw/TABLE TR TD/; my $level = 0; no strict 'refs'; for my $CMD (@vocab) { *{"${pkg}::$CMD"} = sub (&) { $level++; my @inside = $_[0]->(); $level--; my $indent = "\n" . "\t" x $level; my $tag =lc($CMD); return join "",map {"<$tag>$_</$tag>"} @inside; } } *{"${pkg}::render"} = sub { print @_ }; } sub import { my ($self, $dtd, $pkg) =@_; my $super = (caller())[0]; delegate_subs $pkg => $super; install_vocab $pkg, $super; } 1;

<table><tr><td>1</td></tr><tr><td>Calling OuterPkg::foo()</td></tr></t +able>

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


In reply to Re^7: Which internal DSL are there in Perl? (Domain Specific Languages - Part 1) by LanX
in thread 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.