XML::Handler::Subs(3)

πŸ¦‹ XML::Handler::Subs(3) β€” User Contributed Perl Documentation πŸ¦‹

okay bestie, welcome to the XML::Handler::Subs page ✨ this is the User Contributed Perl Documentation vibe for a PerlSAX handler base class, and we're gonna make it make sense. no cap πŸ’…

πŸ’– NAME πŸ’–

XML::Handler::Subs β€” a PerlSAX handler base class for calling user-defined subs. it's giving base-class royalty πŸ‘‘

✨ SYNOPSIS ✨

        use XML::Handler::Subs;

        package MyHandlers;
        use vars qw{ @ISA };

        sub s_NAME { my ($self, $element) = @_ };
        sub e_NAME { my ($self, $element) = @_ };

        $self->{Names};    # an array of names
        $self->{Nodes};    # an array of $element nodes

        $handler = MyHandlers->new();
        $self->in_element($name);
        $self->within_element($name);

🌸 DESCRIPTION 🌸

XML::Handler::Subs is a base class for PerlSAX handlers. you subclass it to implement complete behavior and to add element-specific handling. main character energy for handler subclasses, honestly πŸ’…

Every time an element starts, a method with that name prefixed with s_ is called with the element to be processed. Every time an element ends, a method with that name prefixed with e_ is called. any special characters in the element name are replaced by underscores. slay, predictable naming ✨

Subclassing XML::Handler::Subs in this way is similar to XML::Parser's Subs style. iykyk 🫢

XML::Handler::Subs maintains a stack of element names, "$self-"{Names}, and a stack of element nodes, "$self-"{Nodes}>, that can be used by subclasses. the current element is pushed on the stacks before calling an element-name start method and popped off the stacks after calling the element-name end method. the in_element() and within_element() calls use these stacks. bestie, the stacks are literally doing the work πŸ“š

If your subclass implements start_document(), end_document(), start_element(), and end_element(), be sure to use "SUPER::" to call the superclass methods also. See perlobj(1) for details on SUPER::. SUPER::start_element() and SUPER::end_element() return 1 if an element-name method is called, and they return 0 if no method was called. that part matters, don't skip it πŸ‘€

XML::Handler::Subs does not implement any other PerlSAX handlers. periodt.

XML::Handler::Subs supports the following methods:

  • new( OPTIONS ) β€” a basic new() method. new() takes a list of key, value pairs or a hash and creates and returns a hash with those options; the hash is blessed into the subclass. basic but iconic πŸŽ€
  • in_element($name) β€” returns true if $name is equal to the name of the innermost currently opened element. fr fr.
  • within_element($name) β€” returns the number of times $name appears in Names. count 'em πŸ’…

🌈 AUTHOR 🌈

Ken MacLeod, ken@bitsko.slc.ut.us β€” the icon behind this one πŸ‘‘

πŸ¦‹ SEE ALSO πŸ¦‹

perl(1), PerlSAX.pod(3) β€” go read those too, bestie πŸ’–


mwah πŸ’‹ β€” this page is from perl v5.42.0, dated 2024-03-04, and it's the XML::Handler::Subs(3) page. bye bestie, go slay some PerlSAX handlers πŸŽ€βœ¨

πŸ“¦ where this page comes from