[open-ils-commits] r12440 - trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger (erickson)
svn at svn.open-ils.org
svn at svn.open-ils.org
Fri Mar 6 11:36:36 EST 2009
Author: erickson
Date: 2009-03-06 11:36:34 -0500 (Fri, 06 Mar 2009)
New Revision: 12440
Modified:
trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor.pm
Log:
added copy price and org setting helpers. put helper functions into 'helpers' hash to reduce global namespace pollution
Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor.pm 2009-03-06 16:19:07 UTC (rev 12439)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor.pm 2009-03-06 16:36:34 UTC (rev 12440)
@@ -6,58 +6,77 @@
use OpenSRF::Utils qw/:datetime/;
use OpenSRF::Utils::Logger qw(:logger);
use OpenILS::Application::AppUtils;
+my $U = 'OpenILS::Application::AppUtils';
sub fourty_two { return 42 }
sub NOOP_True { return 1 }
sub NOOP_False { return 0 }
+
+
+# helper functions inserted into the TT environment
+my $_TT_helpers = {
+
+ # turns a date into something TT can understand
+ format_date => sub {
+ my $date = shift;
+ $date = DateTime::Format::ISO8601->new->parse_datetime(clense_ISO8601($date));
+ return sprintf(
+ "%0.2d:%0.2d:%0.2d %0.2d-%0.2d-%0.4d",
+ $date->hour,
+ $date->minute,
+ $date->second,
+ $date->day,
+ $date->month,
+ $date->year
+ );
+ },
+
+ # escapes a string for inclusion in an XML document. escapes &, <, and > characters
+ escape_xml => sub {
+ my $str = shift;
+ $str =~ s/&/&/sog;
+ $str =~ s/</</sog;
+ $str =~ s/>/>/sog;
+ return $str;
+ },
+
+ # returns the calculated user locale
+ get_user_locale => sub {
+ my $user_id = shift;
+ return $U->get_user_locale($user_id);
+ },
+
+ # returns the calculated copy price
+ get_copy_price => sub {
+ my $copy_id = shift;
+ return $U->get_copy_price($copy_id);
+ },
+
+ # returns the org unit setting value
+ get_org_setting => sub {
+ my($org_id, $setting) = @_;
+ return $U->ou_ancestor_setting_value($org_id, $setting);
+ }
+};
+
+
# processes templates. Returns template output on success, undef on error
sub run_TT {
my $self = shift;
my $env = shift;
- return '' unless $env->{template};
+ return undef unless $env->{template};
my $output = '';
my $tt = Template->new;
+ $env->{helpers} = $_TT_helpers;
- $env->{format_date} = \&format_date;
- $env->{escape_xml} = \&escape_xml;
- $env->{user_locale} = \&user_locale;
-
$tt->process(\$env->{template}, $env, \$output) or
$logger->error("Error processing Trigger template: " . $tt->error);
return $output;
}
-# turns a date into something TT can understand
-sub format_date {
- my $date = shift;
- $date = DateTime::Format::ISO8601->new->parse_datetime(clense_ISO8601($date));
- return sprintf(
- "%0.2d:%0.2d:%0.2d %0.2d-%0.2d-%0.4d",
- $date->hour,
- $date->minute,
- $date->second,
- $date->day,
- $date->month,
- $date->year
- );
-}
-sub escape_xml {
- my $str = shift;
- $str =~ s/&/&/sog;
- $str =~ s/</</sog;
- $str =~ s/>/>/sog;
- return $str;
-}
-
-
-sub user_locale {
- my $user_id = shift;
- return OpenILS::Application::AppUtils->get_user_locale($user_id);
-}
-
1;
More information about the open-ils-commits
mailing list