in reply to Re: RFC: IPerl - Interactive Perl ( read-eval-print loop )
in thread RFC: IPerl - Interactive Perl ( read-eval-print loop )

Thanks for the feedback, people.

I'll more than likely just keep my implementation to myself and continue to improve on it. It's unlikely that it offers any additional features that would make it a more compelling solution than the debugger or some of the other scripts/one-liners mentioned here, and if and when I does, I'm sure it will be superseded by whatever perl6 ships with. :) It's still a fun bit of code to tinker with, though.

Anyways, I would like to show how I implemented a couple of the features with the intent of finding out if there's a better way. If this is falling out of the realm of a "meditation", please feel free to ignore or delete this node.

The first 'feature' is the ability to define variables with my() and have them continue to exist outside the scope of the eval block.

The module uses a command filtering system. Users can register new filters by way of a "mixin" module, or with their ~/.iperlrc file.

The "globalvars" mixin module turns top-level lexical variables into package globals by changing my() to our() before your code is executed. Kinda lame, huh? :) Anyways, the effect is that you can write code like this:

iperl> my $foo = "abc" = abc iperl> do { my $bar = "def" } = def iperl> print $foo abc = 1 iperl> print $bar Use of uninitialized variable in...

Is there a more sane way to do this? Is it possible to safely promote a lexical variable to a scope one level up? Or perhaps, to some form of sandbox scratchpad that won't pollute the module's table (which this currently does)?

The other feature that I'd like some feedback on is the "benchmark" mixin. It can be used to benchmark each statement that's executed.

iperl> use IPerl::Mixins::Benchmark iperl> benchmark_on() iperl> use time_consuming_module 4 wallclock secs ( 1.58 usr + 0.19 sys = 1.77 CPU) iperl>

The module uses Hook::LexWrap to register pre and post routines. The pre routine creates a timer, and the post routine creates a second and displays the diff between the two.

Hook::LexWrap seems to work well for this, but I'm wondering if there's a better way? My goal is to keep the additional features as unobtrusive as possible and to effectively keep them out of the base IPerl.pm module.