The power of Class::XPath revealed

samtregar on 2004-07-22T22:18:28

Class::XPath has turned out to be a very good idea, if I may say so myself. Just now I was working on a change to a Krang element library and Class::XPath saved me a lot of work. I needed to reorganize the element tree and move a subelement one level deeper. Without Class::XPath the code to access this element would probably have been:

$auto = $story->element->child('search_auto');

Which would have to change to:

$auto = $story->element->child('search_auto_container')->child('search_auto');

This would have sucked because that element is used all over the element set. But thanks to Class::XPath the code was:

($auto) = $story->element->match('//search_auto');

This will work no matter where the 'search_auto' element is in the tree, so no change is needed! How cool is that?

-sam