Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re^10: Thanks to Ikegami, Chromatic & Corion

by ikegami (Pope)
on Nov 02, 2011 at 23:58 UTC ( #935522=note: print w/ replies, xml ) Need Help??

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

Sigh. For every step forward, there's a step backwards.

That's not true. The output of the plugin is ALWAYS take to be aXML. If it was any other way, aXML would look like the following (when outputting HTML):

plugin produces aXML or HTML code, if the plugin returned aXML, the parser takes that aXML code and produces HTML code, browser takes that HTML code and produces text. if the plugin returned HTML, browser takes that HTML code and produces text.

There is no such check, because such a check is impossible. So, again, what actually happens is

plugin produces (what is taken to be) aXML code, parser takes that aXML code and produces HTML code, browser takes that HTML code and produces text.

Plugins that don't produce aXML are buggy.

Comment on Re^10: Thanks to Ikegami, Chromatic & Corion
Select or Download Code
Replies are listed 'Best First'.
Re^11: Thanks to Ikegami, Chromatic & Corion
by Logicus on Nov 03, 2011 at 00:43 UTC

    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="">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.

      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>

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (10)
As of 2016-02-11 13:36 GMT
Find Nodes?
    Voting Booth?

    How many photographs, souvenirs, artworks, trophies or other decorative objects are displayed in your home?

    Results (369 votes), past polls