NAME
XML::CuteQueries::Error - a simple exception class for CQ
SYNOPSIS
use strict;
use warnings;
use XML::CuteQueries;
my $twig = XML::CuteQueries->new;
$twig->parsefile("something.xml");
unless( eval { $twig->cute_query(...) } ) {
die "something bad happened: $@";
}
# or
unless( eval { $twig->cute_query(...) } ) {
if( $@->query_error ) {
die "dude, query error: " . $@->text;
}
elsif( $@->data_error ) {
die "dude, the XML doesn't seem to contain the data you asked for: " . $@->text;
}
else {
die "hrm: $@";
}
}
METHODS
- new()
-
New takes a few arguments describing the error.
- type
-
This is a numeric argument describing the error type. The only valid choices so far are DATA_ERRORs and QUERY_ERRORs. The symbols aren't exported, so you'd invoke them like this:
XML::CuteQueries::Error->new( type => XML::CuteQueries::Error::QUERY_ERROR(), )->throw;
Arguably sloppy, but this interface isn't really intended for end users. This can also be set with "type()" below.
- text
-
This is a textual description of the error.
XML::CuteQueries::Error->new( type => XML::CuteQueries::Error::QUERY_ERROR(), text => "that query makes no sense because of the Ten Commandments", )->throw;
Arguably sloppy, but this interface isn't really intended for end users. This can also be set with "text()" below.
- type()
-
An accessor for the "type" of the error.
warn "type: " . $@->type; my $e = XML::CuteQueries::Error->new; $e->type( XML::CuteQueries::Error::DATA_ERROR() );
- text()
-
An accessor for the "text" of the error.
warn "type: " . $@->type; my $e = XML::CuteQueries::Error->new; $e->text( "haha, error. You == fail." );
- query_error()
-
Returns true if the error type is a query error.
- data_error()
-
Returns true if the error type is a data error.
- throw()
-
Croak the error, setting $@ to the error object.
AUTHOR
Paul Miller <jettero@cpan.org>
I am using this software in my own projects... If you find bugs, please please please let me know. Actually, let me know if you find it handy at all. Half the fun of releasing this stuff is knowing that people use it.
If you see anything wrong with the callbacks, the docs, or anything: Definitely let me know! rt.cpan, irc, email, whatever. Just let me know.
COPYRIGHT
Copyright (c) 2009 Paul Miller
SEE ALSO
perl(1), XML::Twig, XML::CuteQueries