RT::Cl...Object(3pm)
π RT::Client::REST::Object β the BASE CLASS of the whole little RT object family π
okay so bestie, welcome to RT::Client::REST::Object, straight out of the User Contributed Perl Documentation collection, running on perl v5.40.1 β this is the main character superclass that every RT client object you build is gonna inherit from π«Ά
β¨ VERSION β¨
version 0.73 π
π SYNOPSIS π
the vibe is: make a new type, inherit from the base, tell it your attributes, tell it your rt_type, and you're done fr fr
# Create a new type
package RT::Client::REST::MyType;
use parent qw(RT::Client::REST::Object);
sub _attributes {{
myattribute => {
validation => {
type => SCALAR,
},
},
}}
sub rt_type { "mytype" }
1;
πΈ DESCRIPTION πΈ
So. RT::Client::REST::Object is a superclass, and likeβ¦ it does SO much for you? It hands you a whole entire pile of class methods and object methods so that building RT's REST client interface is actually not a nightmare. it's giving "I did the boring parts so you don't have to" energy, periodt β¨
π ATTRIBUTES π
Your attributes get defined by a method called _attributes β and you gotta define it in your class, okay? That method returns a reference to a hash, and the keys of that hash are the attributes. The values? Those are the attribute settings, and they go like this:
listβ if this is set to true, congrats, it's a list attribute π go see "LIST ATTRIBUTE PROPERTIES" down below for the tea.validationβ a hash reference. This gets passed straight to the validation routines whenever the associated mutator gets called. For reference, look at Params::Validate πrest_nameβ this sets the attribute's REST name. Likeβ¦ attributefinal_prioritycorresponds to RT REST'sFinalPriority. And lowkey you can just omit this whole option if the only difference between the two is the first letter capitalization β¨form2valueβ converts a form value (the one that comes from the server) into something the attribute can actually digest.value2formβ converts the value into REST form format. the reverse baddie π
Example time, look at this:
sub _attributes {{
id => {
validation => {
type => SCALAR,
regex => qr/^\d+$/,
},
form2value => sub {
shift =~ m~^ticket/(\d+)$~i;
return $1;
},
value2form => sub {
return 'ticket/' . shift;
},
},
admin_cc => {
validation => {
type => ARRAYREF,
},
list => 1,
rest_name => 'AdminCc',
},
}}
π¦ LIST ATTRIBUTE PROPERTIES π¦
List attributes come with these properties, no cap:
- When they're called as accessors, they return a list of items π
- When they're called as mutators, they only accept an array reference (yes, only, don't try anything cute) β οΈ
- Convenience methods
add_attranddelete_attrare available! For example:
# Get the list
my @requestors = $ticket->requestors;
# Replace with a new list
$ticket->requestors( [qw(dude@localhost)] );
# Add some random guys to the current list
$ticket->add_requestors('randomguy@localhost', 'evil@local');
π SPECIAL ATTRIBUTES π
id and parent_id are the special ones, the VIPs, the main characters. Various DB-related methods use them, and these three are especially reliant on them:
autostoreautosyncautoget
π₯ METHODS π₯
newβ the Constructor, obviously π_generate_methodsβ this class method generates accessors and mutators based on the_attributesmethod that your class should provide. And for items that are lists? It creates'add_'and'delete_'methods too. So for instance, these two attributes specified in_attributeswill generate the methods'creator','cc','add_cc', and'delete_cc':
creator => {
validation => { type => SCALAR },
},
cc => {
list => 1,
validation => { type => ARRAYREF },
},
_mark_dirty($attrname)β marks an attribute as dirty π_dirtyβ returns the list of dirty attributes. yes, we're keeping track, always watching π_mark_dirty_cf($attrname)β marks a custom flag as dirty._dirty_cfβ returns the list of dirty custom flags.to_form($all)β converts the object to 'form' (this is the thing the REST protocol uses). It's done based on the_attributesmethod. If$allis true, it creates a form from all of the object's attributes and custom flags. Otherwise it uses only the dirty ones (peep the_dirtymethod). Defaults to the latter, so dirty-only unless you say otherwise πfrom_formβ sets the object's attributes from a form received from the RT server π₯param($name, $value)β sets an arbitrary parameter.cf([$name, [$value]])β this one's got layers, bestie. Give it no arguments and it returns the list of custom field names. Give it one argument and it returns the value of custom field$name. Give it two arguments and it sets custom field$nameto$value. And if you hand it a reference to a hash, it uses that as a list of custom fields and their values, returning the new list of all custom field names πrtβ get or set the'rt'object, which should be of typeRT::Client::REST.
π DB METHODS π
These are the methods that have to do with reading, creating, updating, and searching objects. the whole lifecycle, periodt.
countβ takes the same arguments assearch()but returns the actual count of the found items. And it throws the same exceptions. equal opportunity drama πretrieveβ retrieves the object's attributes. but heads up: the'id'attribute must be set for this to work, no id no service π«search (%opts)β this one's used for searching objects. It returns an object of typeRT::Client::REST::SearchResult, which you then use to process your results.%optsis a list of key-value pairs, and they go like this:limitsβ a reference to an array containing hash references with limits to apply to the search (think SQL limits, iykyk).orderbyβ specifies the attribute to sort the result by (in ascending order) β¬οΈreverseorderβ if set to a true value, it sorts by the attribute specified byorderbybut in descending order β¬οΈ
β οΈ If the client can't construct the query from the arguments you specified, or if the server can't make it out either, then RT::Client::REST::Object::InvalidSearchParametersException gets thrown. so be careful with your params fr fr
storeβ store the object. If'id'is set, this is an update; otherwise a new object gets created and the'id'attribute gets set π And note that only changed (dirty) attributes are sent to the server β efficient queen π
β CLASS METHODS β
use_single_rtβ takes a single argument β anRT::Client::RESTobject β and makes this class use it for all instantiations. For example:
my $rt = RT::Client::REST->new(%args);
# Make all tickets use this RT:
RT::Client::REST::Ticket->use_single_rt($rt);
# Now make all objects use it:
RT::Client::REST::Object->use_single_rt($rt);
use_autostoreβ turn autostoring on and off. Autostoring means you don't have to explicitly callstore()on an object β it just gets called automatically when the object goes out of scope. the laziest, most iconic feature π«Ά
# Autostore tickets:
RT::Client::REST::Ticket->use_autostore(1);
my $ticket = RT::Client::REST::Ticket->new(%opts)->retrieve;
$ticket->priority(10);
# Don't have to call store().
use_autogetβ turn the autoget feature on or off (it's off by default, okay). When it's set to on,retrieve()gets automatically called from the constructor if it's called with that object's special attributes (go peek at "SPECIAL ATTRIBUTES" above) β¨
RT::Client::Ticket->use_autoget(1);
my $ticket = RT::Client::Ticket->new(id => 1);
# Now all attributes are available:
my $subject = $ticket->subject;
use_autosyncβ turn the autosync feature on or off β again, off by default. When it's set, every time an attribute is changed, thestore()method gets invoked. and likeβ¦ that may be pretty expensive, so just know that going in π¬be_transparentβ this turns on autosync and autoget together. Transparency is a neat idea, ngl, but it may be expensive and slow. Depending on your circumstances, you may want a finer control of your objects. What transparency does is make yourretrieve()andstore()calls invisible:
RT::Client::REST::Ticket->be_transparent($rt);
my $ticket = RT::Client::REST::Ticket->new(id => $id); # retrieved
$ticket->add_cc('you@localhost.localdomain'); # stored
$ticket->status('stalled'); # stored
# etc.
π¨ Do not forget to pass the RT::Client::REST object to this method. seriously. don't forget.
π SEE ALSO π
RT::Client::REST::Ticket, RT::Client::REST::SearchResult.
π AUTHOR π
Dean Hamstead <dean@fragfest.com.au>
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2026, 2020 by Dmitri Tikhonov.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
and that's the whole page bestie π mwah π this was perl v5.40.1, dated 2026-04-21, from the RT::Cl...Object(3pm) page in User Contributed Perl Documentation β go build something iconic with it β¨π
π¦ where this page comes from
- ubuntu stonking: librt-client-rest-perl 1:0.73-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms