[Rt-commit] [svn] r904 - in RT-Client: . lib/RT t

autrijus at pallas.eruditorum.org autrijus at pallas.eruditorum.org
Sun May 16 12:40:47 EDT 2004


Author: autrijus
Date: Sun May 16 12:40:47 2004
New Revision: 904

Modified:
   RT-Client/   (props changed)
   RT-Client/lib/RT/Client.pm
   RT-Client/t/1-procedural.t
Log:
 ----------------------------------------------------------------------
 r4928 at not:  autrijus | 2004-05-16T16:40:43.957514Z
 
 * Add erorr handler.
 * Do not run any test if we can't auth at all.
 ----------------------------------------------------------------------


Modified: RT-Client/lib/RT/Client.pm
==============================================================================
--- RT-Client/lib/RT/Client.pm	(original)
+++ RT-Client/lib/RT/Client.pm	Sun May 16 12:40:47 2004
@@ -6,10 +6,16 @@
 
 use strict;
 use warnings;
+
 use Spiffy '-Base';
+
 use URI;
+use Carp;
 use HTTP::Request::Common;
 use XML::Atom::Client;
+
+BEGIN { %LWP::Authen::Wsse:: = (); }
+
 use LWP::Authen::Wsse;
 use LWP::UserAgent::RTClient;
 
@@ -28,6 +34,7 @@
 field 'current_user';
 field 'status';
 field 'errstr';
+field 'handle_error';
 
 sub new {
     my %args = (@_ % 2) ? (URI => @_) : @_;
@@ -85,6 +92,7 @@
     if ($1 eq 'html') {
         $self->errstr($res->content);
         $self->status(500);
+        $self->_handle_error;
         return undef;
     }
 
@@ -177,6 +185,7 @@
 
     if ($res->is_error) {
         $self->errstr($res->content);
+        $self->_handle_error;
         return;
     }
     else {
@@ -186,6 +195,13 @@
     return $res;
 }
 
+sub _handle_error {
+    my $code = $self->handle_error or return;
+    $code = \&Carp::croak if $code eq 'die';
+    $code = \&Carp::carp if $code eq 'warn';
+    $code->($self->status, $self->errstr);
+}
+
 1;
 
 __END__

Modified: RT-Client/t/1-procedural.t
==============================================================================
--- RT-Client/t/1-procedural.t	(original)
+++ RT-Client/t/1-procedural.t	Sun May 16 12:40:47 2004
@@ -1,23 +1,33 @@
 #!/usr/bin/perl
 
+use Carp;
 use FindBin;
 use lib "$FindBin::Bin/../lib";
-use Test::More tests => 64;
+use Test::More;
+use LWP::Simple 'get';
 
-$SIG{__WARN__} = sub { use Carp; Carp::cluck(@_) };
-$SIG{__DIE__} = sub { use Carp; Carp::confess(@_) };
+$SIG{__WARN__} = \&Carp::cluck;
+$SIG{__DIE__} = \&Carp::confess;
+
+if (get('http://root:password@localhost/Atom/0.3/') =~ /<feed/) {
+    plan tests => 64;
+}
+else {
+    plan skip_all => 'Atom 0.3 not available on localhost';
+}
 
 use_ok('RT::Client');
 my $rt = RT::Client->new('http://root:password@localhost');
 isa_ok($rt, 'RT::Client', 'Client');
 
-# XXX - Some way to RaiseError
+# Debug and error handler:
+#
+# $rt->debug(1);
+# $rt->handle_error('die');
 
 # Requirements:
 # 1. Ticket Creation and Modification via an External Interface
 
-$rt->debug(0);
-
 my $tickets = $rt->describe('Tickets');
 isa_ok($tickets, 'RT::Client::Container', '->describe($uri)');
 isnt($tickets->uri, undef, 'Tickets has a URI: '.$tickets->uri);


More information about the Rt-commit mailing list