.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "RT::Client::REST::Object 3pm" .TH RT::Client::REST::Object 3pm "2023-12-21" "perl v5.36.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" RT::Client::REST::Object \- base class for RT objects .SH "VERSION" .IX Header "VERSION" version 0.72 .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& # 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; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" The RT::Client::REST::Object module is a superclass providing a whole bunch of class and object methods in order to streamline the development of \s-1RT\s0's \s-1REST\s0 client interface. .SH "ATTRIBUTES" .IX Header "ATTRIBUTES" Attributes are defined by method \f(CW\*(C`_attributes\*(C'\fR that should be defined in your class. This method returns a reference to a hash whose keys are the attributes. The values of the hash are attribute settings, which are as follows: .IP "list" 2 .IX Item "list" If set to true, this is a list attribute. See \&\*(L"\s-1LIST ATTRIBUTE PROPERTIES\*(R"\s0 below. .IP "validation" 2 .IX Item "validation" A hash reference. This is passed to validation routines when associated mutator is called. See Params::Validate for reference. .IP "rest_name" 2 .IX Item "rest_name" This specifies this attribute's \s-1REST\s0 name. For example, attribute \&\*(L"final_priority\*(R" corresponds to \s-1RT REST\s0's \*(L"FinalPriority\*(R". This option may be omitted if the two only differ in first letter capitalization. .IP "form2value" 2 .IX Item "form2value" Convert form value (one that comes from the server) into attribute-digestible format. .IP "value2form" 2 .IX Item "value2form" Convert value into \s-1REST\s0 form format. .PP Example: .PP .Vb 10 \& sub _attributes {{ \& id => { \& validation => { \& type => SCALAR, \& regex => qr/^\ed+$/, \& }, \& form2value => sub { \& shift =~ m~^ticket/(\ed+)$~i; \& return $1; \& }, \& value2form => sub { \& return \*(Aqticket/\*(Aq . shift; \& }, \& }, \& admin_cc => { \& validation => { \& type => ARRAYREF, \& }, \& list => 1, \& rest_name => \*(AqAdminCc\*(Aq, \& }, \& }} .Ve .SH "LIST ATTRIBUTE PROPERTIES" .IX Header "LIST ATTRIBUTE PROPERTIES" List attributes have the following properties: .IP "\(bu" 2 When called as accessors, return a list of items .IP "\(bu" 2 When called as mutators, only accept an array reference .IP "\(bu" 2 Convenience methods \*(L"add_attr\*(R" and \*(L"delete_attr\*(R" are available. For example: .Sp .Vb 2 \& # 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(\*(Aqrandomguy@localhost\*(Aq, \*(Aqevil@local\*(Aq); .Ve .SH "SPECIAL ATTRIBUTES" .IX Header "SPECIAL ATTRIBUTES" \&\fBid\fR and \fBparent_id\fR are special attributes. They are used by various DB-related methods and are especially relied upon by: .IP "autostore" 2 .IX Item "autostore" .PD 0 .IP "autosync" 2 .IX Item "autosync" .IP "autoget" 2 .IX Item "autoget" .PD .SH "METHODS" .IX Header "METHODS" .IP "new" 2 .IX Item "new" Constructor .IP "_generate_methods" 2 .IX Item "_generate_methods" This class method generates accessors and mutators based on \&\fB_attributes\fR method which your class should provide. For items that are lists, 'add_' and 'delete_' methods are created. For instance, the following two attributes specified in \fB_attributes\fR will generate methods 'creator', 'cc', 'add_cc', and 'delete_cc': .Sp .Vb 7 \& creator => { \& validation => { type => SCALAR }, \& }, \& cc => { \& list => 1, \& validation => { type => ARRAYREF }, \& }, .Ve .IP "_mark_dirty($attrname)" 2 .IX Item "_mark_dirty($attrname)" Mark an attribute as dirty. .IP "_dirty" 2 .IX Item "_dirty" Return the list of dirty attributes. .IP "_mark_dirty_cf($attrname)" 2 .IX Item "_mark_dirty_cf($attrname)" Mark an custom flag as dirty. .IP "_dirty_cf" 2 .IX Item "_dirty_cf" Return the list of dirty custom flags. .IP "to_form($all)" 2 .IX Item "to_form($all)" Convert the object to 'form' (used by \s-1REST\s0 protocol). This is done based on \&\fB_attributes\fR method. If \f(CW$all\fR is true, create a form from all of the object's attributes and custom flags, otherwise use only dirty (see \fB_dirty\fR method) attributes and custom flags. Defaults to the latter. .IP "from_form" 2 .IX Item "from_form" Set object's attributes from form received from \s-1RT\s0 server. .ie n .IP "param($name, $value)" 2 .el .IP "param($name, \f(CW$value\fR)" 2 .IX Item "param($name, $value)" Set an arbitrary parameter. .IP "cf([$name, [$value]])" 2 .IX Item "cf([$name, [$value]])" Given no arguments, returns the list of custom field names. With one argument, returns the value of custom field \f(CW$name\fR. With two arguments, sets custom field \f(CW$name\fR to \f(CW$value\fR. Given a reference to a hash, uses it as a list of custom fields and their values, returning the new list of all custom field names. .IP "rt" 2 .IX Item "rt" Get or set the 'rt' object, which should be of type RT::Client::REST. .SH "DB METHODS" .IX Header "DB METHODS" The following are methods that have to do with reading, creating, updating, and searching objects. .IP "count" 2 .IX Item "count" Takes the same arguments as \f(CW\*(C`search()\*(C'\fR but returns the actual count of the found items. Throws the same exceptions. .IP "retrieve" 2 .IX Item "retrieve" Retrieve object's attributes. Note that 'id' attribute must be set for this to work. .IP "search (%opts)" 2 .IX Item "search (%opts)" This method is used for searching objects. It returns an object of type RT::Client::REST::SearchResult, which can then be used to process results. \f(CW%opts\fR is a list of key-value pairs, which are as follows: .RS 2 .IP "limits" 2 .IX Item "limits" This is a reference to array containing hash references with limits to apply to the search (think \s-1SQL\s0 limits). .IP "orderby" 2 .IX Item "orderby" Specifies attribute to sort the result by (in ascending order). .IP "reverseorder" 2 .IX Item "reverseorder" If set to a true value, sorts by attribute specified by \fBorderby\fR in descending order. .RE .RS 2 .Sp If the client cannot construct the query from the specified arguments, or if the server cannot make it out, \&\f(CW\*(C`RT::Client::REST::Object::InvalidSearchParametersException\*(C'\fR is thrown. .RE .IP "store" 2 .IX Item "store" Store the object. If 'id' is set, this is an update; otherwise, a new object is created and the 'id' attribute is set. Note that only changed (dirty) attributes are sent to the server. .SH "CLASS METHODS" .IX Header "CLASS METHODS" .IP "use_single_rt" 2 .IX Item "use_single_rt" This method takes a single argument \*(-- RT::Client::REST object and makes this class use it for all instantiations. For example: .Sp .Vb 1 \& 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); .Ve .IP "use_autostore" 2 .IX Item "use_autostore" Turn \fIautostoring\fR on and off. \fIAutostoring\fR means that you do not have to explicitly call \f(CW\*(C`store()\*(C'\fR on an object \- it will be called when the object goes out of scope. .Sp .Vb 5 \& # Autostore tickets: \& RT::Client::REST::Ticket\->use_autostore(1); \& my $ticket = RT::Client::REST::Ticket\->new(%opts)\->retrieve; \& $ticket\->priority(10); \& # Don\*(Aqt have to call store(). .Ve .IP "use_autoget" 2 .IX Item "use_autoget" Turn \fIautoget\fR feature on or off (off by default). When set to on, \&\f(CW\*(C`retrieve()\*(C'\fR will be automatically called from the constructor if it is called with that object's special attributes (see \&\*(L"\s-1SPECIAL ATTRIBUTES\*(R"\s0 above). .Sp .Vb 4 \& RT::Client::Ticket\->use_autoget(1); \& my $ticket = RT::Client::Ticket\->new(id => 1); \& # Now all attributes are available: \& my $subject = $ticket\->subject; .Ve .IP "use_autosync" 2 .IX Item "use_autosync" Turn \fIautosync\fR feature on or off (off by default). When set, every time an attribute is changed, \f(CW\*(C`store()\*(C'\fR method is invoked. This may be pretty expensive. .IP "be_transparent" 2 .IX Item "be_transparent" This turns on \fBautosync\fR and \fBautoget\fR. Transparency is a neat idea, but it may be expensive and slow. Depending on your circumstances, you may want a finer control of your objects. Transparency makes \&\f(CW\*(C`retrieve()\*(C'\fR and \f(CW\*(C`store()\*(C'\fR calls invisible: .Sp .Vb 1 \& RT::Client::REST::Ticket\->be_transparent($rt); \& \& my $ticket = RT::Client::REST::Ticket\->new(id => $id); # retrieved \& $ticket\->add_cc(\*(Aqyou@localhost.localdomain\*(Aq); # stored \& $ticket\->status(\*(Aqstalled\*(Aq); # stored \& \& # etc. .Ve .Sp Do not forget to pass RT::Client::REST object to this method. .SH "SEE ALSO" .IX Header "SEE ALSO" RT::Client::REST::Ticket, RT::Client::REST::SearchResult. .SH "AUTHOR" .IX Header "AUTHOR" Dean Hamstead .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2023, 2020 by Dmitri Tikhonov. .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.