Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

aXML vs TT2

by Logicus (Initiate)
on Oct 21, 2011 at 03:39 UTC ( [id://932813]=perlmeditation: print w/replies, xml ) Need Help??

Many here are bound to be familiar with TT2, so to illustrate aXML a bit more clearly it might be helpful to make a bit of a comparison between the two.

listing of a TT2 template ------------------------- [% INCLUDE header title = 'User Info' %] [% USE DBI('dbi:mSQL:mydbname') %] <table border=0 width="100%"> <tr> <th>User ID</th> <th>Name</th> <th>Email</th> </tr> [% FOREACH user IN DBI.query('SELECT * FROM user ORDER BY id') %] <tr> <td>[% user.id %]</td> <td><a href="action.pl?action=user_profile&user_id=[% user.id %]"> +[% user.name %]</a></td> <td>[% user.email %]</td> </tr> [% END %] </table> [% INCLUDE footer %] The equivalent in aXML ---------------------- <inc title="User Info">header</inc> <table border=0 width="100%"> <tr> <th>User ID</th> <th>Name</th> <th>Email</th> </tr> <db_select> <query> SELECT * FROM user ORDER BY id </query> <mask> <tr> <td><d>id</d></td> <td>[hlink action="user_profile" user_id="<d>id</d>"]<d>name</d> +[/hlink]</td> <td><d>email</d></td> </tr> </mask> </db_select> </table> <inc>footer</inc>

As I'm sure you can see, there are clear similiarities between the two, however this example doesn't use many of aXML's more advanced features and capabilities. As you get into greater complexity than this, the two systems begin to diverge in terms of how they work, and how they are extended. Also the functionality of aXML is not set in stone by the parser, since all the symbols are defined as plugins which can be modified or overloaded as the end programmer desires to produce any result required.

If anyone would like me to translate more examples, please post them below, the more complex the better as it will show the differences and advantage of aXML more clearly.

Replies are listed 'Best First'.
Re: aXML vs TT2
by anneli (Pilgrim) on Oct 21, 2011 at 07:40 UTC

    it will show the differences and advantage of aXML more clearly

    Could you elaborate on the advantages? Here I can't see the advantage of the aXML variant; the TT2 one (to me) is more information dense, and the difference in syntaxes makes clear what's going into my output and what isn't; the aXML version makes it a lot more difficult to see.

      That was my first thought too, anneli; Similar things should look the same, and different things should look different. And code and data are different things. Maybe I just haven't seen enough of it. But when the language extension starts looking like the data my internal alarm goes off telling me I've got to pay extra attention to keep things straight. I'm never thrilled when the internal alarm goes off. ;)


      Dave

        I just thought "Aaarrrggghhhh!!!! He's reinvented Cold Fusion!!!!" and then tried to claw my eyes out to make the horror go away.

        Indeed; it's one failing of Lisp, in a way: too much homoiconicity is not necessarily a good thing -- you spend much of your time trying to work out where are the function calls, what are the arguments. Macros don't help, as you need to look at the callee, work out whether it's a function or macro, and in the case of the latter, whether or how it evaluates its arguments, in order to know if or when side effects will occur!

          A reply falls below the community's threshold of quality. You may see it by logging in.
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: aXML vs TT2
by ikegami (Patriarch) on Oct 21, 2011 at 18:43 UTC
    So aXML only supports XML formats that have neither an element named "db_select", an element named "d" nor an element named "inc". What about those that have an element named "query" or an element named "mask"? Is your parser smart enough to handle those?

      Ok my answer needs to be in two parts.

      Firstly, in accordance with the currently defined given set of symbol definitions, db_select is an aXML tag, whilst query is just meta that db_select requires to function but is not defined as an active tag by itself. (it has no code associated with it)

      Secondly, if you don't like the given tag definitions you can change them to suit your requirements since they are simply perl subs contained in a hash table. Thus if your application requires that you work with an xml file containing tags which correspond to existing definitions, and you don't want those tags to trigger code functionality in the subs, you can just rename those definitions to something else (or delete them from the table, or overload them with a plugin localised to the given action). It's completely soft-coded and your in complete control of your abstractions.

        It's not the worst solution, but it's inherently fragile.

        It requires that I know every element name that can be found in an XML document. Some formats are extensible (e.g. XHTML), so there is no such list for them. And even if we assume that list can be found, most people won't bother trying to create it.

        It requires that I cross check that list against the list of keywords in a hash. How is that possible to do reliably if the list if as dynamic as you say.

        This will lead to errors that can be very subtle. And given how templates are typically used, the errors will not be seen by the dev and they will be seen by end users.

        The thing is, XML has already solved that problem. The mechanism is called "namespaces".

        <root xmlns:a="http://axml.com/1.0/"> <a:inc title="User Info">header</a:inc> <table border=0 width="100%"> <tr> <th>User ID</th> <th>Name</th> <th>Email</th> </tr> <a:db_select> <a:query> SELECT * FROM user ORDER BY id </a:query> <a:mask> <tr> <td><a:d>id</a:d></td> <td>[hlink action="user_profile" user_id="<a:d>id</a:d>"]<a:d>na +me</a:d>[/hlink]</td> <td><a:d>email</a:d></td> </tr> </a:mask> </a:db_select> </table> <a:inc>footer</a:inc> </root>

        PS — I personally prefer <inc name="header"/> over <inc>header</inc>.

Re: aXML vs TT2
by Solo (Deacon) on Oct 23, 2011 at 00:35 UTC
    Is aXML on the CPAN or github or something?

      No not yet, I released a couple of older versions a few months back before I started to work on marrying it with Plack to solve the efficiency problems it had. The current version is almost ready for a demo release, which I will be making available right here on Perlmonks via a link to a zip file on my dev server. After that when I've tidied up the rough edges and fixed any bugs which might be lurking in it I'm hoping to get it onto CPAN with full documentation etc.

Re: aXML vs TT2
by ikegami (Patriarch) on Oct 23, 2011 at 06:19 UTC

    I just notice you didn't include the equivalent of [% USE DBI('dbi:mSQL:mydbname') %], so it's not really a fare comparison. You surely specify the name of the database to connect to somewhere.

    My question is: Does one need to load the modules, or are installed modules are loaded automatically?

      DSN information is stored in the site's private Conf.pm file, and if present automatically causes the system to use DBI and attempt to connect to the database.

      Package Conf; our $conf = { 'sitetitle' => 'Acme Site', 'dsn' => 'DBI:mysql:forum:localhost:3306', 'dsn_username' => 'xxxx', 'dsn_password' => 'xxxxxx', '404' => '404', 'default_action' => 'default', 'doc_root' => '/var/www', 'debug' => 0 }; 1;

      The values in the conf can also be accessed from within the document with the <conf> tag I.E:

      <conf>sitetitle</conf> Output: ------- Acme Site
Re: aXML vs TT2
by talexb (Chancellor) on Oct 21, 2011 at 18:05 UTC

    What problem are you trying to solve here?

    Alex / talexb / Toronto

    "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

      Hrm, my own insanity perhaps. I dunno... the thing itself started out as an ignorant naive hand-rolled templating system, and has grown and developed into a system that I just can't live with out and I have tried.

      Whenever I try and get into the mainstream way of doing things I have nightmare flashbacks to my COBOL lessons... sorry! not sorry!

      Thankfully now I have embraced the uber-awesomeness (TM) of Miyagawa's plack system, I have everything I ever wanted; my simple dynamic declaritive markup based system and blazing performance... for me I feel like I'm approaching Perl Nirvana and I can't understand at all why people don't get it.

        No need to apologize (or not!) for creating something awesome .. but, as an engineer, whenever I see something new whose purpose isn't immediately obvious, I wonder why it's there. And sometimes the answer is, "Because I had an itch!"

        Alex / talexb / Toronto

        "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

Re: aXML vs TT2
by Anonymous Monk on Oct 21, 2011 at 07:03 UTC
    LOL
      +1
        -- You guys are clearly morons.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-03-19 03:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found