Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^11: Thanks to Ikegami, Chromatic & Corion

by Logicus (Initiate)
on Nov 03, 2011 at 00:43 UTC ( [id://935525]=note: print w/replies, xml ) Need Help??


in reply to Re^10: Thanks to Ikegami, Chromatic & Corion
in thread Thanks to Ikegami, Chromatic & Corion

Nope, your looking at it the wrong way, probably my fault for comparing it with TT2 lol.

Try this analogy, it's like self-golfing code.

Let's take an example from that file I sent you.

(db_mask) <query> SELECT * FROM threads WHERE threadid="(sqd)threadid(/sqd)" < +/query> <mask> <h2>[hlink action="show_section" sectionid="<d>sectionid</d>" ][db_get]sections.sectionid="<d>sectionid</d>".display_name[/db_g +et][/hlink] > <d>title</d></h2><hr/> </mask> (/db_mask)
mumble mumble... make text box much wider on PerlNights.. mumble.. mumble

The state of the document changes as it is being parsed, first the parser runs a fast regex to look for primary ( ) tags, and marks them with the ` control char

(`db_mask) <query> SELECT * FROM threads WHERE threadid="(`sqd)threadid(/sqd)" +</query> <mask> <h2>[hlink action="show_section" sectionid="<d>sectionid</d>" ][db_get]sections.sectionid="<d>sectionid</d>".display_name[/db_g +et][/hlink] > <d>title</d></h2><hr/> </mask> (/db_mask)

It's found 2 primary tags to compute, one is nested inside the other. Now because it has found at least one primary tag, a slower regex runs which finds the whole tag and it's close, and then treats it like a subroutine call, returning the return value to the document.

The slower regex is looped and it negates the ` char within the tag structure, so that only tags which have no nested commands get processed each time we go around the loop.

The result is that the first tag to be computed is the (sqd) tag, followed immediately by the (db_mask) tag. So let's say that the (sqd) tag returned a value of 1. The db_mask tag then gets picked up and run with the following data :

in $_[0] we have ---------------- <query> SELECT * FROM threads WHERE threadid="1"</query> <mask> <h2>[hlink action="show_section" sectionid="<d>sectionid</d>" ][db_get]sections.sectionid="<d>sectionid</d>".display_name[/db_g +et][/hlink] > <d>title</d></h2><hr/> </mask>

The query and mask tags are extracted, the query gets run and returns hashrefs which are then used to populate the mask. The db_mask plugin will return a copy of the mask interpolated with the specified columns for each row the query produces.

Since in this case the query will only return a single row, the return value looks like this :

<h2>[hlink action="show_section" sectionid="1" ][db_get]sections.sectionid="1".display_name[/db_get][/hlink] >Th +e first thread</h2><hr/>

The parser now looks for any remaining ( ) primary tags, determines there are none left, and moves on to the secondary tags < >. Since there are none of these either (h2 is not a defined aXML tag), it skips on the the tertiary tags, [ ]

<h2>[`hlink action="show_section" sectionid="1" ][`db_get]sections.sectionid="1".display_name[/db_get][/hlink] >T +he first thread</h2><hr/>

Once again it has found 2 tags that it recognises with the fast scanner, and invokes the slower scanner which loops negating the control char, causing the tags to be run db_get first, followed by hlink.

db_get runs first ----------------- <h2>[`hlink action="show_section" sectionid="1" ]The Castle Gates[/hlink] >The first thread</h2><hr/> Followed by hlink ----------------- <h2><a href="action.pl?action=show_section&sectionid=1">The Castle G +ates</a> >The first thread</h2><hr/>

The parser then concludes there is nothing left to do and exits to the post processing stage.

Replies are listed 'Best First'.
Re^12: Thanks to Ikegami, Chromatic & Corion
by ikegami (Patriarch) on Nov 03, 2011 at 01:12 UTC

    Yes, I know, I heard you the first few million times.

    If you are saying that what the plugin returns is searched for aXML tags then you actually agree with me; what a plugin returns is treated as aXML. Not HTML.

    All plugins that can return arbitrary HTML are buggy and the others are potentially buggy.

      I tend not to put any HTML into the plugin code, but instead send it to the plugin from the document level.

      <ul> <some_list_creating_plugin> <li><some_marker></li> </some_list_creating_plugin> </ul> some_list_creating_plugin => sub { my @list = ['foo','bar','baz']; my $mask = $_[0]; my $result; foreach my $item (@list) { my $maskCopy = $mask; $maskCopy =~ s@<some_marker>@$item@gs; push (@results, $maskCopy); } return join (@results); } output ------ <ul> <li>foo</li> <li>bar</li> <li>baz</li> </ul>

        $maskCopy =~ s@<some_marker>@$item@gs;

        But what if $item was HTML from a database instead of being hardcoded aXML...

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-04-18 18:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found