Re: Shortcutting a SAX parser

Michael Ludwig <[email protected]>
Newsgroups gmane.comp.lang.perl.xml
Message-ID <[email protected]>
Tod Harter schrieb:
> There are various ways to tweak how die works. IIRC it for one thing
> depends on how you call it, with or without parenthesis and with or
> without an argument.

Hi Tod,

thanks for replying. I've never encountered these variations. The usual
way to obtain a consistent output string is by terminating it with a
newline. This will prevent the line number blurb to be tagged onto the
end of the string.

> Also you can use various modules like Carp.pm to adjust how it works,
> or install your own die handler. Finally there is no requirement that
> the argument to die be any particular type of variable. All it has to
> be is a scalar of some kind. It could be a string, number, hash ref,
> array ref, maybe even a typeglob. Specifically it can be a blessed
> hash ref. So you can throw objects out of a die. Anyway, you can
> definitely get a consistent output string.

Dying with a hash reference as in [ die { bla => 'Blub' }; ] is another
way of obtaining a consistent output string as in $@->{bla}.

eval { die "Gurke\n" };
print $@ if $@;

eval { die { bla => 'Blub' } };
print $@->{bla}, "\n" if $@;

The problem in the example I posted in the message to which you replied
is that something stringifies this exception:

throw XML::SAX::Exception::Done( Message => 'Doc done' )

So if I examine it:

print Dumper $@ if $@;

It looks like this:

$VAR1 = 'Doc done at /usr/local/lib/perl/5.8.8/XML/LibXML/SAX.pm line 73
   at /home/milu/ds/chax.pl line 61
';

And while it is consistent as long as I don't change the program, it
includes the line number, which is not what I want or expect. Something
gets in the way and imposes stringification where it is not wanted, thus
defeating the purpose of raising an exception using an exception class.

Michael Ludwig
_______________________________________________
Perl-XML mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.