in reply to Re^25: aXML vs TT2
in thread aXML vs TT2

Well, it's a special case and the ability is going to need to be coded into the parser itself (like the 4 special char codes). One of the older versions specifically the one currently in use on my sites, has just such a routine built in. I will make sure it's done by the time I put out the first release.

As for making a custom plugin, it's very simple.

Lets say you want to add a plugin called foo which takes two attributes called bar and baz, and some meta data.

In the aXML doc --------------- <foo bar="hello" baz="world"> good to be here </foo> In your sites private subs module --------------------------------- my $plugins = { foo => sub { my $args = $_[0]; #a hashref my $data = $_[1]; #good to be here $args->{'tag_name'}; #foo $args->{'bar'}; #hello $args->{'baz'}; #world #do some stuff with the args and data here return 'some result'; } };

In the case where your plugin does not need to return any value to the document, you can just return '<null>'. This is to prevent the parser from throwing a warning about doing a substitution on an empty string, and is automatically removed from the document in the post processing stage.

Also you could create a plugin called "lt" with the following code:

lt => sub { return '<'; } or lt => sub { '<' } #golfed :P

However it wouldn't achieve anything and would result exactly the same as just putting a < into the document to begin with.

Replies are listed 'Best First'.
Re^27: aXML vs TT2
by ikegami (Patriarch) on Oct 23, 2011 at 09:30 UTC
    Wait, that means a plugin can't safely return "<" because it might end up calling another plugin it knows nothing about!!!

      Ahh yes, well that's when you start to progress beyond baby-aXML, and start to build highly complex compound dynamic declarations, declarations that build declarations, recursive structures... and god only knows what else besides.

      I've only just started to scratch the surface of what's possible with the paradigm. I'm sure there are techniques and patterns that I haven't even dreamed of yet, which is another good reason to open the thing up for others to explore and find out what works best and what is possible.

        So it is far from trivial to safely output text from a plugin that looks like aXML but is not interpreted as aXML again.

        I would reconsider this design choice because you might end up with problems ranging from annoying problems like not being able to use aXML to generate XML and aXML, to really big security holes like user generated content triggering internal aXML code.

        Of course, proper documentation on how to generate various output would also help, and also the replacement rules when aXML turns &amp; into &, &lt; into < and when it passes them through.

        When the basics are next to impossible, I should start building complex systems... what??