Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^4: RFC : Abstraction Markup

by Anonymous Monk
on Jul 13, 2011 at 10:24 UTC ( [id://914090]=note: print w/replies, xml ) Need Help??


in reply to Re^3: RFC : Abstraction Markup
in thread RFC : Abstraction Markup

From my understanding it boils down to  $DB->($query, $mask) Where query is sql and mask is a template, and $DB is a function that basically does
my $sth = $dbh->prepare($query); $sth->execute; $out = ''; foreach my $queryResult( $sth->fetchrow_hashref ) $out .= $mask->process( $queryResult ) } return $out;
Except he chose delimiters to be different and significant -- which is why he had to use regular expressions to parse his xml-ish balanced tags, instead of using XML::Twig or HTML::Seamstress

To do the same in TT2, you create a template DB which uses Template::Plugin::DBI so you can write

<table width="50%"> [% MACRO mask BLOCK %] <tr> <td> [% news_title %] </td> <td> [% news_headline %] </td> <td>[% WRAPPER link action = "readnews" newsitem = news_id %]Read More...[% END # block test %] </td> </tr> [% END # macro block mask %] [% INCLUDE DB ## db calls macro mask, can be redefined query=' SELECT * FROM latestnews; ' %] </table>
query is a variable, mask is macro ( a template ) , and the template DB calls the macro mask, after defining variables based on database column names (presumably news_id, news_title, news_headline ) to populate mask

This works out of the box with TT2.

Sure, you have to define the MACRO mask before INCLUDE-ing the template DB, but that could be remedied by expanding the syntax so you can assign macros to a variable, or it could be implemented as a Template::Plugin or Template::View -- not a lot of work

Replies are listed 'Best First'.
Re^5: RFC : Abstraction Markup
by yitzchak (Sexton) on Jul 13, 2011 at 18:03 UTC
    I think you misunderstood my question. From what I can tell, this is supposed to be completely generic, being able to attach handlers to any "tag" (or have it pass through verbatim if there is no handler), with each handler receiving its children as content and returning a rendered version. With <> tags, child content has already been processed, but handling of () tags is supposed to take precedence over their children; does that mean the contents of a () tag aren't subject to any handlers? Or that upon return of the () tag handler, any tags in the return are handled? Other?

      I think you misunderstood my question

      I don't think I did :) I explained how the given template example unravels in both perl and tt2 terms

      does that mean the contents of a () tag aren't subject to any handlers?

      I don't understand what you're asking :)

      Based on his actual proof of concept (both old, new) "(DB)" "DB" is the name of plugin, its perl code, either ...DB.aXMLpl or ...DB.pm

      Since (DB) has no () children, it is processed first, as a complete unit

      Its responsible for processing all tags contained within as a template

      Or that upon return of the () tag handler, any tags in the return are handled? Other?

      Lets try another , shorter example

      (Foo) <Fruit>Apples</Fruit> (Bar) <pants>red</pants><d>varyable</d> (/Bar) (/Foo)
      That would be functionally equivalent to this perl code
      return $Foo->( '<Fruit>Apples</Fruit>' .$Bar->('<pants>red</pants><d>varyable</d>') );

      Like chromatic said, its basically scheme

      Am I closer now?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://914090]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2024-04-19 13:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found