[Rt-commit] r2584 - rt/branches/3.4-RELEASE/lib/RT

tla at bestpractical.com tla at bestpractical.com
Mon Apr 4 04:18:23 EDT 2005


Author: tla
Date: Mon Apr  4 04:18:22 2005
New Revision: 2584

Modified:
   rt/branches/3.4-RELEASE/lib/RT/Record.pm
Log:
Add a simple sub to return the object class with the RT::Lib:: prefix
stripped off.  Useful for displaying, e.g., "Ticket #35" or "Article #3".


Modified: rt/branches/3.4-RELEASE/lib/RT/Record.pm
==============================================================================
--- rt/branches/3.4-RELEASE/lib/RT/Record.pm	(original)
+++ rt/branches/3.4-RELEASE/lib/RT/Record.pm	Mon Apr  4 04:18:22 2005
@@ -124,6 +124,29 @@
     } 
 }
 
+=head2 ObjectTypeStr
+
+Returns a string which is this object's type.  The type is the class,
+without the "RT::" prefix.
+
+=begin testing
+
+my $ticket = RT::Ticket->new($RT::SystemUser);
+my $group = RT::Group->new($RT::SystemUser);
+is($ticket->ObjectTypeStr, 'Ticket', "Ticket returns correct typestring");
+is($group->ObjectTypeStr, 'Group', "Group returns correct typestring");
+
+=end testing
+
+=cut
+
+sub ObjectTypeStr {
+    my $self = shift;
+    my $type = ref($self);
+    $type =~ s/^.*::(\w+)$/$1/;
+    return $type;
+}
+
 =head2 Attributes
 
 Return this object's attributes as an RT::Attributes object


More information about the Rt-commit mailing list