Skip to content

Instantly share code, notes, and snippets.

@three18ti
Created June 18, 2012 21:41
Show Gist options
  • Save three18ti/2950896 to your computer and use it in GitHub Desktop.
Save three18ti/2950896 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>[%- user.assert.email -%]</email>
<creator>staff</creator>
<userid>0</userid>
<staffid>[%- user.id -%]</staffid>
<!-- Begin Ticket Properties -->
<subject>[%- ticket.assert.subject -%]</subject>
<departmentid<[%- ticket.assert.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);
#!/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>
</create>
</kayako_staffapi>
END_TEMPLATE
}
package main;
use strict;
use warnings;
use Template;
use Data::Dumper;
my %data = (
staffapiid => "1234",
user => {
fullname => "bob",
}
);
print Dumper %data;
my $cfg = Test->new;
my $tt = Template->new;
my $template = $cfg->get_template();
print $tt->process(\$template, \%data)
#!/usr/bin/perl
package Test;
use Moose;
sub get_template {
my $var =<<'END_TEMPLATE';
League Standings
League Name: [% name %]
Season : [% season %]
Teams:
[% FOREACH team = teams -%]
[% team.name %] [% team.played -%]
[% team.won %] [% team.drawn %] [% team.lost %]
[% END %]
END_TEMPLATE
}
package main;
use lib './lib';
use strict;
use warnings;
use Template;
my @teams = ( { name => 'Man Utd',
played => 16,
won => 12,
drawn => 3,
lost => 1 },
{ name => 'Bradford',
played => 16,
won => 2,
drawn => 5,
lost => 9 });
my %data = ( name => 'English Premier League',
season => '2000/01',
teams => \@teams );
use Data::Dumper;
print Dumper %data;
my $cfg = Test->new;
my $tt = Template->new;
my $template = $cfg->get_template();
print $tt->process(\$template, \%data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment