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

autrijus at pallas.eruditorum.org autrijus at pallas.eruditorum.org
Wed May 5 19:35:07 EDT 2004


Author: autrijus
Date: Wed May  5 19:35:07 2004
New Revision: 836

Modified:
   RT-Client/   (props changed)
   RT-Client/lib/RT/Client.pm
   RT-Client/t/spec.t
Log:
 ----------------------------------------------------------------------
 r4477 at not:  autrijus | 2004-05-05T23:30:33.346838Z
 
 * Beginning of munge_links autodiscovery algorithm.
 * Accept-Charset support.
 
 ----------------------------------------------------------------------
 r4478 at not:  autrijus | 2004-05-05T23:32:01.479888Z
 
 * move all transactional attributes to be global to the $rt
   instance.  Keeping them all in the object has proved to be
   non-economic for huge number of objects, not to mention
   encoding inconsistency between a container and its objects.
 ----------------------------------------------------------------------


Modified: RT-Client/lib/RT/Client.pm
==============================================================================
--- RT-Client/lib/RT/Client.pm	(original)
+++ RT-Client/lib/RT/Client.pm	Wed May  5 19:35:07 2004
@@ -150,6 +150,12 @@
     return $self->{current_user};
 }
 
+sub encoding {
+    my $self = shift;
+    $self->{encoding} = shift if @_;
+    return $self->{encoding};
+}
+
 sub server {
     my $self = shift;
     if (@_) {
@@ -187,6 +193,9 @@
     $req->header(
         'X-RT-CurrentUser' => $self->current_user,
     );
+    $req->header(
+        'Accept-Charset' => $self->encoding,
+    );
     return $req unless $self->realm;
     return $self->SUPER::munge_request($req);
 }
@@ -197,6 +206,59 @@
     return $self->SUPER::munge_response($res);
 }
 
+# The algorithm here is pure lazy loading - nothing gets retrived for sure
+# until the first autoload is called upon that object.
+#
+# Whenever AUTOLOAD is called with something that is not found in the {links}
+# table, a representation of the object is fetched and all links put into
+# {links} as the proper type of sub-object.
+#
+# The discovery process: Get each <link>, and look at the 'title' attribute:
+#
+#  Prefixed with '_': skipped.
+#  Prefixed with '!': an action for this object. store in {actions}.
+#  Otherwise: A link. store in {links}.
+#
+# The 'href' attribute is the link to be stored.  The 'rel' attribute determines
+# the type of the link:
+#
+#  "service.feed": a Container.
+#  "service.edit": an Object.
+#  "service.post": an action supported by the object that shares the same 'title'.
+#
+# For example, the main page has following links:
+#
+#  Groups-feed http://localhost/Atom/0.3/RT-Groups
+#  Groups-post http://localhost/Atom/0.3/RT-Groups!add
+#
+# Hence the {links} hash will contain:
+#
+#  $rt->{links} = {
+#      Groups => bless(
+#          {
+#              uri => 'http://localhost/Atom/0.3/RT-Groups'
+#              actions => {
+#                 add => 'http://localhost/Atom/0.3/RT-Groups!add'
+#              }
+#          },
+#          'RT::Client::Container'
+#      ),
+#  }
+
+
+our $AUTOLOAD;
+sub AUTOLOAD {
+    my $self = shift;
+    $AUTOLOAD =~ s/.*:://;
+    my $links = $self->{links} ||= {};
+    $self->munge_links($links) unless $links->{$AUTOLOAD};
+    return $links->{$AUTOLOAD};
+}
+
+sub munge_links {
+    my ($self, $links) = @_;
+}
+
 
 1;
 

Modified: RT-Client/t/spec.t
==============================================================================
--- RT-Client/t/spec.t	(original)
+++ RT-Client/t/spec.t	Wed May  5 19:35:07 2004
@@ -6,12 +6,16 @@
 
 use_ok('RT::Client');
 my $rt = RT::Client->new('http://root:password@localhost');
-isa_ok($rt, 'RT::Client');
+
+# some way to RaiseError!
 
 # Requirements:
 # 1. Ticket Creation and Modification via an External Interface
 
 my $tickets = $rt->Tickets;
+isa_ok($rt, 'RT::Client');
+
+exit;
 isa_ok($tickets, 'RT::Client::Container');
 can_ok($tickets, 'search');
 can_ok($tickets, 'add');
@@ -24,7 +28,7 @@
 is($tickets->_errstr, undef, 'Nothing bad had happened yet');
 is($tickets->add, undef, 'Adding an empty ticket shall fail');
 isnt($tickets->_errstr, undef, 'Error message is in ->_errstr');
-is($rt->_errstr, undef, 'Error message shall not propagate up');
+is($rt->errstr, $tickets->_errstr, 'Error message is global');
 
 my $ticket = $tickets->add( Queue => 1, Subject => 'Testing' );
 isa_ok($ticket, 'RT::Client::Object');
@@ -55,9 +59,9 @@
 # "requestor" field so that replies are sent to the requestor.
 
 my $email = 'rand-' . rand() . '@example.com';
-is($ticket->Requestor->search->_count, 1);
+is($ticket->Requestor->search->count, 1);
 $ticket->addRequestor($email);
-is($ticket->Requestor->search->_count, 2);
+is($ticket->Requestor->search->count, 2);
 
 # 1.2 Ability to post a ticket to a specific queue.
 
@@ -68,12 +72,12 @@
 # 1.3 Ability to specify message body. May contain utf8 OR localized
 # charset.
 
-$ticket->encoding('hz');
-is($ticket->encoding, $rt->encoding, '->encoding is global');
+$ticket->_encoding('hz');
+is($ticket->_encoding, $rt->encoding, '->_encoding is global');
 $ticket->setSubject('~{1jLb~}');
-$ticket->encoding('gbk');
+$ticket->_encoding('gbk');
 is(length($ticket->Subject), 4);
-$ticket->encoding('utf-8');
+$ticket->_encoding('utf-8');
 
 # 1.4 Ability to set values in n existing custom fields.
 
@@ -82,7 +86,7 @@
     Type => 'SelectSingle',
 );
 
-$cf->addValues( Name => 'foo', Description 'Foo Option' );
+$cf->addValues( Name => 'foo', Description => 'Foo Option' );
 
 # 1.5 Ability to set values in "Select One Value" and "Enter One Value"
 # -type custom fields
@@ -91,15 +95,15 @@
 # RT-Tickets/5/CustomFieldValues/9/1.Content
 $ticket->CustomFieldValues($cf)->set( Content => 'foo');
 
-is($ticket->CustomFieldsValues($cf)->_count, 1);
-is($ticket->CustomFieldsValues($cf)->_first->Content, 'foo');
+is($ticket->CustomFieldsValues($cf)->count, 1);
+is($ticket->CustomFieldsValues($cf)->first->Content, 'foo');
 
 # 1.6 For modifications, need to identify ticket number. We'd prefer to
 # identify modifying user as well if possible.
 
 my $id = $ticket->Id;
 $rt->current_user('Nobody');
-is($ticket->current_user, $rt->current_user, '->current_user is global');
+is($ticket->_current_user, $rt->current_user, '->_current_user is global');
 $rt->Tickets($id)->comment( Content => "Hello!" );
 $rt->current_user($rt->username);
 


More information about the Rt-commit mailing list