Softpedia
 


LINUX CATEGORIES:



GLOBAL PAGES >>
NEWS ARCHIVE >>
SOFTPEDIA REVIEWS >>
MEET THE EDITORS >>
WEEK'S BEST
  • BackTrack 5 R2
  • Wine 1.4 / 1.5.5
  • Mozilla Firefox 12...
  • Ubuntu 11.04
  • Angry Birds 1.1.2.1
  • Ubuntu 10.04.4 LTS
  • Linux Kernel 3.4
  • Ubuntu Manual 10.10
  • Adobe Flash Player...
  • Pidgin 2.10.4
  • Home > Linux > Programming > Perl Modules

    Data::Stag::BaseHandler 0.11

    Download button

    No screenshots available
    Downloads: 264  View global page NEW!  Tell us about an update
    User Rating:
    Rated by:
    NOT RATED
    0 user(s)
    Developer:

    License / Price:

    Last Updated:

    Category:
    Chris Mungall | More programs
    Perl Artistic License / FREE
    July 11th, 2009, 00:53 GMT
    ROOT / Programming / Perl Modules

     Read user reviews (0)  Refer to a friend  Subscribe

    Data::Stag::BaseHandler description

    Base class for writing tag stream handlers

    Data::Stag::BaseHandler is a simple event handler, other handlers inherit from this class.

    Stag has an event-handling architecture; parsers or generators generate or fire events. Events can be hierarchical/nested, just like stag nodes. These events are caught by handlers. By default, uncaught events stack to form stag trees.

    Stag has built in parsers for parsing xml, sxpr and itext data. You can construct your own parsers for dealing with your own formats specific to your own data; these should inherit from Data::Stag::BaseGenerator

    Stag also has built in handlers for these formats. You can construct your own - either as modules that inherit from this one, or as hashes of anonymous subroutines.

    If you wish to write your own handler that writes out to another format, you may wish to inherit from Data::Stag::Writer

    SYNOPSIS

     # EXAMPLE 1
     package MyPersonHandler;
     use base qw(Data::Stag::BaseHandler);

     # handler that prints < person > nodes as they are parsed;
     # after each < person > node is intercepted, it is discarded
     # (it does not go to form the final tree)
     sub e_person {
     my $self = shift;
     my $node = shift;
     printf "Person name:%s address:%s
    ",
     $node->sget('name'), $node->sget('address');
     return; # prune this from tree
     }
     1;
     
     # EXAMPLE 2
     package MyStatsHandler;
     use base qw(Data::Stag::BaseHandler);

     # handler that modifies tree as it goes
     # changes < measurement >< unit >inch< /unit >< quantity >10< /quantity >< /measurement >
     # to < measurement >< unit >cm< /unit >< quantity >25< /quantity >< /measurement >
     sub e_measurement {
     my $self = shift;
     my $node = shift;
     if ($node->sget('unit') eq 'inch') {
     $node->set('unit', 'cm');
     $node->set('quantity', $node->get('quantity') * 2.5);
     }
     return $node; # replace < measurement > with new data in result tree
     }
     1;
     
     # Using the handlers
     my $handler = MyHandler->new;
     my $stag = Data::Stag->parse(-fh=>$fh, -handler=>$handler);

     # Using a handler from the command line:
     unix> stag-handle.pl -m MyHandler input.xml > post-processed.xml



    Product's homepage

    Requirements:

    · Perl

      


    TAGS:

    tag stream handlers | event handler | Perl module | tag | stream | handler



    HTML code for linking to this page:


    Go to top

    WindowsGamesDriversMacLinuxScriptsMobileHandheldNews

    SUBMIT PROGRAM   |   ADVERTISE   |   GET HELP   |   SEND US FEEDBACK   |   RSS FEEDS   |   UPDATE YOUR SOFTWARE   |   ROMANIAN FORUM