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… attribute final_priority corresponds to RT REST's FinalPriority. 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_attr and delete_attr are 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:

  • autostore
  • autosync
  • autoget

πŸ”₯ METHODS πŸ”₯

  • new β€” the Constructor, obviously πŸ’…
  • _generate_methods β€” this class method generates accessors and mutators based on the _attributes method 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 _attributes will 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 _attributes method. If $all is true, it creates a form from all of the object's attributes and custom flags. Otherwise it uses only the dirty ones (peep the _dirty method). 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 $name to $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 type RT::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 as search() 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 type RT::Client::REST::SearchResult, which you then use to process your results. %opts is 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 by orderby but 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 β€” an RT::Client::REST object β€” 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 call store() 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, the store() 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 your retrieve() and store() 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>

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