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

I don't know how to create a post-include type plugin -- well any plugin, really -- but could "lt" be one of them?

Replies are listed 'Best First'.
Re^26: aXML vs TT2
by Logicus (Initiate) on Oct 23, 2011 at 07:16 UTC

    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.

      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.