Skip to content

Instantly share code, notes, and snippets.

@three18ti
Created June 18, 2012 22:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save three18ti/2951098 to your computer and use it in GitHub Desktop.
Save three18ti/2951098 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
package Test;
use Moose;
sub get_template {
my $template =<<'END_TEMPLATE';
[%- USE assert -%]
<kayako_staffapi>
<create staffapiid="[%- staffapiid -%]">
<!-- Begin Creator Properties -->
<fullname>[%- user.fullname -%]</fullname>
<email>[%- assert.user.email -%]</email>
<creator>staff</creator>
<userid>0</userid>
<staffid>[%- user.id -%]</staffid>
<!-- Begin Ticket Properties -->
<subject>[%- assert.ticket.subject -%]</subject>
<departmentid<[%- assert.ticket.departmentid -%]</departmentid>
<ticketstatusid>[%- ticket.statusid -%]</ticketstatusid>
<ticketpriorityid>[%- ticket.priorityid -%]</ticketpriorityid>
<tickettypeid>[%- ticket.typeid -%]</tickettypeid>
<ownerstaffid>[%- ticket.ownerstaffid -%]</ownerstaffid>
<emailqueueid>[%- ticket.emailqueueid -%]</emailqueueid>
</create>
</kayako_staffapi>
END_TEMPLATE
}
package main;
use strict;
use warnings;
use Template;
use Data::Dumper;
my %data = (
staffapiid => "1234",
ticket => {
subject => "test",
departmentid => '1',
statusid => '2',
priorityid => '3',
typeid => '4',
ownerstaffid => '5',
emailqueueid => '6',
},
user => {
id => "1234567",
fullname => "Bob Something",
email => 'foo@bar.com',
},
);
print Dumper %data;
my $cfg = Test->new;
my $tt = Template->new;
my $template = $cfg->get_template();
print $tt->process(\$template, \%data) || $tt->error;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment