+=head2 get_transactions
+
+Takes ticket and returns L<RT::Transactions> object with transactions
+of the ticket according to command line arguments C<--transaction>
+and <--transaction-type>.
+
+=cut
+
+sub get_transactions {
+ my $ticket = shift;
+ my $txns = $ticket->Transactions;
+ my $order = $transaction eq 'last'? 'DESC': 'ASC';
+ $txns->OrderByCols(
+ { FIELD => 'Created', ORDER => $order },
+ { FIELD => 'id', ORDER => $order },
+ );
+ if ( $transaction_type ) {
+ $transaction_type =~ s/^\s+//;
+ $transaction_type =~ s/\s+$//;
+ foreach my $type ( split /\s*,\s*/, $transaction_type ) {
+ $txns->Limit( FIELD => 'Type', VALUE => $type, ENTRYAGGREGATOR => 'OR' );
+ }
+ }
+ $txns->RowsPerPage(1) unless $transaction eq 'all';
+ return $txns;
+}
+
+=head2 get_template
+
+Takes a ticket and returns a template according to command line options.
+
+=cut
+
+{ my $cache = undef;
+sub get_template {
+ my $ticket = shift;
+ return undef unless $template;
+
+ unless ( $template =~ /\D/ ) {
+ # by id
+ return $cache if $cache;
+
+ my $cache = RT::Template->new( $RT::SystemUser );
+ $cache->Load( $template );
+ die "Failed to load template '$template'"
+ unless $cache->id;
+ return $cache;
+ }
+
+ my $queue = $ticket->Queue;
+ return $cache->{ $queue } if $cache->{ $queue };
+
+ my $res = RT::Template->new( $RT::SystemUser );
+ $res->LoadQueueTemplate( Queue => $queue, Name => $template );
+ unless ( $res->id ) {
+ $res->LoadGlobalTemplate( $template );
+ die "Failed to load template '$template', either for queue #$queue or global"
+ unless $res->id;
+ }
+ return $cache->{ $queue } = $res;
+} }
+