| 1 | # $Id: Subs.pm,v 1.1 2003/07/27 16:07:49 matt Exp $ |
| 2 | |
| 3 | package XML::Parser::Style::Subs; |
| 4 | |
| 5 | sub Start { |
| 6 | no strict 'refs'; |
| 7 | my $expat = shift; |
| 8 | my $tag = shift; |
| 9 | my $sub = $expat->{Pkg} . "::$tag"; |
| 10 | eval { &$sub($expat, $tag, @_) }; |
| 11 | } |
| 12 | |
| 13 | sub End { |
| 14 | no strict 'refs'; |
| 15 | my $expat = shift; |
| 16 | my $tag = shift; |
| 17 | my $sub = $expat->{Pkg} . "::${tag}_"; |
| 18 | eval { &$sub($expat, $tag) }; |
| 19 | } |
| 20 | |
| 21 | 1; |
| 22 | __END__ |
| 23 | |
| 24 | =head1 NAME |
| 25 | |
| 26 | XML::Parser::Style::Subs |
| 27 | |
| 28 | =head1 SYNOPSIS |
| 29 | |
| 30 | use XML::Parser; |
| 31 | my $p = XML::Parser->new(Style => 'Subs', Pkg => 'MySubs'); |
| 32 | $p->parsefile('foo.xml'); |
| 33 | |
| 34 | { |
| 35 | package MySubs; |
| 36 | |
| 37 | sub foo { |
| 38 | # start of foo tag |
| 39 | } |
| 40 | |
| 41 | sub foo_ { |
| 42 | # end of foo tag |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | =head1 DESCRIPTION |
| 47 | |
| 48 | Each time an element starts, a sub by that name in the package specified |
| 49 | by the Pkg option is called with the same parameters that the Start |
| 50 | handler gets called with. |
| 51 | |
| 52 | Each time an element ends, a sub with that name appended with an underscore |
| 53 | ("_"), is called with the same parameters that the End handler gets called |
| 54 | with. |
| 55 | |
| 56 | Nothing special is returned by parse. |
| 57 | |
| 58 | =cut |