#!/bin/perl -w

#############################################################
#                                                           #
#  This example just prints a list of names and module      #
#  description from the freshmeat.xml file                  #
#                                                           #
#  It prints the info as it's parsing, and purges the twig  #
#  so memory usage remains minimal                          #
#                                                           #
#############################################################

use strict;
use XML::Twig;


my $twig= new XML::Twig(                              # create the twig
              TwigHandlers => { module => \&module }  # call sub when a module
                        );                            # element is parsed                       

if( my $file= $ARGV[0]) { $twig->parsefile( $file); } # process the twig
else                    { $twig->parse( \*STDIN);   }


sub module
  { my( $twig, $module)= @_; # handlers are always called with those 2 arguments
    my $name        = $module->field( 'name');         # get the element text
    my $description = $module->field( 'description');  

    print "$name: \t$description\n";                   # print the info 
    $twig->purge;                                      # purges the twig 
  }

