Hacking Thy Fearful Symmetry

Hacker, hacker coding bright

XML::XPathScript 1.47 is out

January 20, 2007
perl xml::xpathscript

It is with great relish that I announce that XML::XPathScript v1.47 is on its way to a CPAN mirror near you.

[ ED: Do'h! The test that was supposed to gracefully skip if B::XPath isn't installed bombs instead. (blame it on my naive assumption that 'eval { use B::XPath; 1 }' would work). I'll do a s/use/require/ on that test and release 1.48 tonight. ]

What is new in this release:

* template tag attributes can now be functions as well as strings.

        For example,

                $template->set( 'foo' => { testcode => sub {

                                my( $n, $t ) = @_;

                                my $name = $n->findvalue( 'name()' );

                                $t->set({ pre => transfurbicate( $name ) });

                                return $DO_SELF_AND_CHILDREN;

                        }

                } );

        can now be written

                $template->set( 'foo' => { pre => sub {

                                my( $n, $t ) = @_;

                                my $name = $n->findvalue( 'name()' );

                                return transfurbicate( $name );

                        }

                } );

* The 'content' template attribute, which associates template elements to

mini-stylesheets.

        E.g., the code

        <%

                $template->set( 'foo' => {

                                pre => '',

                                post => '
',

                                action => 'bar', # only process 'bar' node children

                } );

        %>

                can now be written

        <%

                $template->set( 'foo' => { content => <<'END_CONTENT' } );

                        <%# look Ma, we interpolate! %>

                                <%~ bar %> <%# only process bar children %>

                       


        END_CONTENT

        %>

        <%# process all foo's %>

        <%~//foo %>

        Or, to be more easy on the eye, we can use the short-hand version:

        <%@ foo

                <%# look Ma, we interpolate! %>

                        <%~ bar %> <%# only proces bar children %>

               


        %>

        <%# process all foo's %>

        <%~//foo %>

* B::XPath now a supported DOM tree. Bored with transforming XML documents?

How about transforming Perl Optrees?:-)

                use B::XPath;

                use XML::XPathScript;

                sub guinea_pig {

                        my $x = shift;

                        print "oink oink " x $x;

                }

                my $xps = XML::XPathScript->new;

                $xps->set_dom( B::XPath->fetch_root( \&guinea_pig ) );

                $xps->set_stylesheet( '<%~ //print %>' );

                print $xps->transform;

comments powered by Disqus

About the author

Yanick Champoux
Perl necrohacker , ACP writer, orchid lover. Slightly bonker all around. he/him/his