Put custom code into its own package.
authorDavid E. Wheeler <david@justatheory.com>
Tue, 6 Nov 2012 19:05:58 +0000 (11:05 -0800)
committerDavid E. Wheeler <david@justatheory.com>
Tue, 6 Nov 2012 19:05:58 +0000 (11:05 -0800)
So that globals are not immediately available. Also set $_ to the same value
as the hash ref passed in.

Bucardo.pm

index 1c38d69c2201fad0c2fabdcae3b12a5810c3a7c8..951e887a4f88eea44c31339af15a43f1b316dc4c 100644 (file)
@@ -5639,7 +5639,10 @@ sub validate_sync {
         TRY: {
             local $@;
             local $_;
-            $c->{coderef} = eval qq{sub { $c->{src_code} } }; ## no critic (ProhibitStringyEval)
+            $c->{coderef} = eval qq{
+                package Bucardo::CustomCode;
+                sub { $c->{src_code} }
+            }; ## no critic (ProhibitStringyEval)
             if ($@) {
                 $self->glog(qq{Warning! Custom code $c->{id} ($c->{name}) for sync "$syncname" did not compile: $@}, LOG_WARN);
                 return 0;
@@ -7228,6 +7231,7 @@ sub run_ctl_custom_code {
 
     $self->{masterdbh}->{InactiveDestroy} = 1;
     $cc_sourcedbh->{InactiveDestroy} = 1;
+    local $_ = $input;
     $c->{coderef}->($input);
     $self->{masterdbh}->{InactiveDestroy} = 0;
     $cc_sourcedbh->{InactiveDestroy} = 0;
@@ -7686,6 +7690,7 @@ sub run_kid_custom_code {
     }
 
     ## Run the actual code!
+    local $_ = $info;
     $c->{coderef}->($info);
 
     $self->glog("Finished custom code $c->{id}", LOG_VERBOSE);