Skip Menu |

This queue is for tickets about the Dist-Zilla-Plugin-Run CPAN distribution.

Report information
The Basics
Id: 105243
Status: resolved
Priority: 0/
Queue: Dist-Zilla-Plugin-Run

People
Owner: Nobody in particular
Requestors: VDB [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: 0.039



Subject: evaluating Perl code
It is a great idea, but implementation is not very good now. Run v0.038, file Runner.pm: sub _eval_cmd { my ( $self, $code, $params, $dry_run ) = @_; <...> $code = $self->build_formatter($params)->format($code); <...> my $sub = sub { eval $code }; $sub->($self); if ($@) { <...> } } 1. Variable $@ is not localized. It should be "local $@;" before eval. 2. User code sees all the local variables: $self, $code, $params, $dry_run. It has some drawbacks: if user code (accidentally) changes $self, it will break plugin and entire dzil: [Run::BeforeBuild] eval = undef $self; die; But if $self properly documented, it can be an advantage: instead of long explanations that shift operates on @ARGV, and user should use $_[0] to get reference to plugin object, you could simply document that within the user code $self variable contains reference to plugin object. Alternatively, you may want to set $plugin and $dist variables, like GenerateFile and GatherDir::Template plugins (TemplateFile plugin sets $dist too). Also, this feature can be used instead of %a, %d, %p and other placeholders. This is a Perl code, no need in introducing %x: in Perl code $^X works. Similarly, %t is not much shorter than $dist->is_trial, %v — $dist->version, etc. For convenience, you may provide variables $p, $v, etc — just create these variables before eval. It also will look more naturally in Perl code, than hashes %a, %d, %p. It will be also more portable. Imagine that someone used in his code variable %y: my %y = ...; In current version of Run it will work. If later you decide to introduce %y placeholder, it will break user code, while predefined $y variable will continue to work — user code will just ignore predefined value and declare own variable.
On 2015-06-15 10:08:27, VDB wrote: Show quoted text
> implementation is not very good now.
Gee thanks. Show quoted text
> 1. Variable $@ is not localized. It should be "local $@;" before eval.
Why is this important? We're running inside a dzil build, not inside something else that is capturing exceptions. Show quoted text
> 2. User code sees all the local variables: $self, $code, $params, > $dry_run.
I've removed these variables from scope in release 0.039. Show quoted text
> But if $self properly documented, it can be an advantage:
If you want to shift $_[0] into $self, and then access the zilla object directly, feel free. That's why the plugin object is being passed. Show quoted text
> instead of > long explanations that shift operates on @ARGV
@ARGV is used for command line arguments. There is no @ARGV in use here. Show quoted text
> Also, this feature can be used instead of %a, %d, %p and other > placeholders. This is a Perl code, no need in introducing %x: in Perl > code $^X works. Similarly, %t is not much shorter than $dist-
> >is_trial, %v — $dist->version, etc.
The placeholders are being used in order to make this option a closer parallel to the existing run_* options. You don't have to use them. Show quoted text
> It has some drawbacks: if user code (accidentally) changes > $self, it will break plugin and entire dzil:
Of course it will. What did you expect would happen? You're executing arbitrary code, so if that code dies, or breaks something, you get to keep both halves. I added a documentation note about the inherent security risks.