xml - How does the Perl Template::Declare modul work in terms of Perl language syntax? -


i need create complex xml documents (mets), using prefixes, namespaces, schema validation, document-internally referenced element ids, attributes mixed namespaces... pretty xml allows do. there loads of heavily nested elements, making difficult track starting- , ending-tags manually.

researching several possibilities came across template::declare.

the synopsis provides example show here reference:

template simple => sub {         html {             head {}             body {                 p { 'hello, world wide web!' }             }         }     }; 

my question is: happening here in terms of perl language elements? how translate valid perl syntax? example, "html", "head" keywords etc. here representing perl compiler? implicit sub declaration? perl (or allows do) many things implicitly never know happening. don't want copy , paste example , hope can bend need, i'd know i'm doing...

can enlighten me here?

the beauty of cpan can take @ code. 1 bit complicated admit, here looking for:

https://metacpan.org/source/alexmv/template-declare-0.46/lib/template/declare/tags.pm#l525

basically sugary syntax comes prototype &, tells perl sub accepting code reference. { ... } here not hashes, blocks, same ones in map or grep. in example, chained together.

because of prototype, can ommit parenthesis , commas, write example this:

template simple => sub {   html(     sub {       head(         sub { },         body(           sub {             p( sub { 'hello, world wide web!' } );           } ) );     } ); }; 

the way implemented, if written out directly, be:

sub template(%) { ... } # % tells expect hash sub html(&) { ... } sub head(&) { ... } sub body(&) { ... } sub p(&) { ... } 

this kind of stuff called syntactic sugar, or dsl (domain-specific language).

note you should use prototypes in code if know doing! chances are, not want them.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -