[Rt-commit] rt branch, new-style-templates, updated. rt-3.8.8-231-gb6bd18b
Shawn Moore
sartak at bestpractical.com
Fri Jul 30 00:19:51 EDT 2010
The branch, new-style-templates has been updated
via b6bd18b1547d89e17a4438cbbb80e9ae66c025f1 (commit)
from a2e6f811fcf328efee9fbfedfa81a35d3efd7205 (commit)
Summary of changes:
lib/RT/Scrip_Overlay.pm | 29 +++++++++++++++++++++++++++++
share/html/Admin/Elements/EditScrip | 3 +++
2 files changed, 32 insertions(+), 0 deletions(-)
- Log -----------------------------------------------------------------
commit b6bd18b1547d89e17a4438cbbb80e9ae66c025f1
Author: Shawn M Moore <sartak at bestpractical.com>
Date: Fri Jul 30 00:21:39 2010 -0400
Compile checking for user-defined scrip code
diff --git a/lib/RT/Scrip_Overlay.pm b/lib/RT/Scrip_Overlay.pm
index 9b7fa8f..ccdd418 100755
--- a/lib/RT/Scrip_Overlay.pm
+++ b/lib/RT/Scrip_Overlay.pm
@@ -608,5 +608,34 @@ sub HasRight {
# }}}
+=head2 CompileCheck
+
+This routine compile-checks the custom prepare, commit, and is-applicable code
+to see if they are syntactically valid Perl. We eval them in a codeblock to
+avoid actually executing the code.
+
+If one of the fields has a compile error, only the first is reported.
+
+Returns an (ok, message) pair.
+
+=cut
+
+sub CompileCheck {
+ my $self = shift;
+
+ for my $method (qw/CustomPrepareCode CustomCommitCode CustomIsApplicableCode/) {
+ my $code = $self->$method;
+
+ do {
+ no strict 'vars';
+ eval "sub { $code }";
+ };
+ next if !$@;
+
+ my $error = $@;
+ return (0, $self->loc("Couldn't compile [_1] codeblock '[_2]': [_3]", $method, $code, $error));
+ }
+}
+
1;
diff --git a/share/html/Admin/Elements/EditScrip b/share/html/Admin/Elements/EditScrip
index 2bcf64d..f0a5ae1 100755
--- a/share/html/Admin/Elements/EditScrip
+++ b/share/html/Admin/Elements/EditScrip
@@ -149,6 +149,9 @@ unless ( $id ) {
my $min_lines = 10;
+my ($ok, $msg) = $scrip->CompileCheck;
+push @actions, $msg if !$ok;
+
</%init>
<%ARGS>
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list