From 30d7375bba8b179dedf1c2ca322d758e5330752d Mon Sep 17 00:00:00 2001 From: Stevan Little Date: Sun, 1 Sep 2013 13:27:33 -0400 Subject: twigils --- lib/Reply.pm | 22 ++++++------ lib/Reply/Config.pm | 10 +++--- lib/Reply/Plugin.pm | 4 +-- lib/Reply/Plugin/AutoRefresh.pm | 4 +-- lib/Reply/Plugin/CollapseStack.pm | 12 +++---- lib/Reply/Plugin/Colors.pm | 12 +++---- lib/Reply/Plugin/DataDump.pm | 8 ++--- lib/Reply/Plugin/Defaults.pm | 6 ++-- lib/Reply/Plugin/Editor.pm | 14 ++++---- lib/Reply/Plugin/FancyPrompt.pm | 12 +++---- lib/Reply/Plugin/Hints.pm | 18 +++++----- lib/Reply/Plugin/LexicalPersistence.pm | 6 ++-- lib/Reply/Plugin/Nopaste.pm | 44 +++++++++++------------ lib/Reply/Plugin/Packages.pm | 8 ++--- lib/Reply/Plugin/ReadLine.pm | 64 +++++++++++++++++----------------- lib/Reply/Plugin/ResultCache.pm | 12 +++---- lib/Reply/Plugin/Timer.pm | 4 +-- 17 files changed, 130 insertions(+), 130 deletions(-) diff --git a/lib/Reply.pm b/lib/Reply.pm index 4261109..6c4bd8f 100644 --- a/lib/Reply.pm +++ b/lib/Reply.pm @@ -80,8 +80,8 @@ An arrayref of additional plugins to load. =cut class Reply { - has $plugins = []; - has $_default_plugin = $_->_instantiate_plugin('Defaults'); + has $!plugins = []; + has $!_default_plugin = $_->_instantiate_plugin('Defaults'); submethod BUILD ($opts) { if (defined $opts->{config}) { @@ -170,7 +170,7 @@ requested to quit. method _load_plugin ($plugin, $opts) { $plugin = $self->_instantiate_plugin($plugin, $opts); - push @$plugins, $plugin; + push @{$!plugins}, $plugin; } method _instantiate_plugin ($plugin, $opts) { @@ -193,7 +193,7 @@ requested to quit. } method _plugins { - return (@$plugins, $_default_plugin); + return (@{$!plugins}, $!_default_plugin); } method _read { @@ -239,11 +239,11 @@ requested to quit. # XXX $self should be available in parameter defaults too $plugins //= [ $self->_plugins ]; - $plugins = [ grep { $_->can($method) } @$plugins ]; + $plugins = [ grep { $_->can($method) } @{$plugins} ]; - return @$args unless @$plugins; + return @$args unless @{$plugins}; - my $plugin = shift @$plugins; + my $plugin = shift @{$plugins}; my $next = sub { $self->_wrapped_plugin($method, [@_], $plugins) }; return $plugin->$method($next, @$args); @@ -253,9 +253,9 @@ requested to quit. # XXX $self should be available in parameter defaults too $plugins //= [ $self->_plugins ]; - $plugins = [ grep { $_->can($method) } @$plugins ]; + $plugins = [ grep { $_->can($method) } @{$plugins} ]; - for my $plugin (@$plugins) { + for my $plugin (@{$plugins}) { @$args = $plugin->$method(@$args); } @@ -266,11 +266,11 @@ requested to quit. # XXX $self should be available in parameter defaults too $plugins //= [ $self->_plugins ]; - $plugins = [ grep { $_->can($method) } @$plugins ]; + $plugins = [ grep { $_->can($method) } @{$plugins} ]; my @results; - for my $plugin (@$plugins) { + for my $plugin (@{$plugins}) { push @results, $plugin->$method(@$args); } diff --git a/lib/Reply/Config.pm b/lib/Reply/Config.pm index 233293e..bc84b02 100644 --- a/lib/Reply/Config.pm +++ b/lib/Reply/Config.pm @@ -40,12 +40,12 @@ be relative to the user's home directory, otherwise it will be used as-is. =cut class Reply::Config { - has $file = $_->_canonicalize_file('.replyrc'); - has $config = Config::INI::Reader::Ordered->new; + has $!file = $_->_canonicalize_file('.replyrc'); + has $!config = Config::INI::Reader::Ordered->new; submethod BUILD ($args) { if (defined $args->{file}) { - $file = $self->_canonicalize_file($args->{file}); + $!file = $self->_canonicalize_file($args->{file}); } } @@ -55,7 +55,7 @@ Returns the absolute path to the config file that is to be used. =cut - method file { $file } + method file { $!file } =method data @@ -63,7 +63,7 @@ Returns the loaded configuration data. =cut - method data { $config->read_file($file) } + method data { $!config->read_file($!file) } method _canonicalize_file ($filename) { return File::Spec->catfile( diff --git a/lib/Reply/Plugin.pm b/lib/Reply/Plugin.pm index c84d4b7..171fec4 100644 --- a/lib/Reply/Plugin.pm +++ b/lib/Reply/Plugin.pm @@ -171,7 +171,7 @@ messages you want to communicate. =cut class Reply::Plugin is closed, repr('HASH') { - has $publisher = die "publisher is required"; + has $!publisher = die "publisher is required"; =method publish ($name, @args) @@ -182,7 +182,7 @@ the parameters. Returns a list of everything that each plugin responded with. =cut method publish ($method, @args) { - $publisher->($method, @args); + $!publisher->($method, @args); } =method commands diff --git a/lib/Reply/Plugin/AutoRefresh.pm b/lib/Reply/Plugin/AutoRefresh.pm index 28daac5..f830997 100644 --- a/lib/Reply/Plugin/AutoRefresh.pm +++ b/lib/Reply/Plugin/AutoRefresh.pm @@ -30,10 +30,10 @@ modules correctly see the global override. =cut class Reply::Plugin::AutoRefresh extends Reply::Plugin { - has $track_require = 1; + has $!track_require = 1; submethod BUILD { - Class::Refresh->import(track_require => $track_require); + Class::Refresh->import(track_require => $!track_require); # so that when we load things after this plugin, they get a copy of # Module::Runtime which has the call to require() rebound to our diff --git a/lib/Reply/Plugin/CollapseStack.pm b/lib/Reply/Plugin/CollapseStack.pm index f18ff4a..d5f1e16 100644 --- a/lib/Reply/Plugin/CollapseStack.pm +++ b/lib/Reply/Plugin/CollapseStack.pm @@ -27,9 +27,9 @@ the C option. =cut class Reply::Plugin::CollapseStack extends Reply::Plugin { - has $num_lines = 1; + has $!num_lines = 1; - has $full_error; + has $!full_error; method compile ($next, @args) { local $SIG{__DIE__} = \&Carp::Always::_die; @@ -42,11 +42,11 @@ class Reply::Plugin::CollapseStack extends Reply::Plugin { } method mangle_error ($error) { - $full_error = $error; + $!full_error = $error; my @lines = split /\n/, $error; - if (@lines > $num_lines) { - splice @lines, $num_lines; + if (@lines > $!num_lines) { + splice @lines, $!num_lines; $error = join "\n", @lines, " (Run #stack to see the full trace)\n"; } @@ -56,7 +56,7 @@ class Reply::Plugin::CollapseStack extends Reply::Plugin { method command_stack { # XXX should use print_error here - print($full_error || "No stack to display.\n"); + print($!full_error || "No stack to display.\n"); return ''; } } diff --git a/lib/Reply/Plugin/Colors.pm b/lib/Reply/Plugin/Colors.pm index 56c145d..25a0cbf 100644 --- a/lib/Reply/Plugin/Colors.pm +++ b/lib/Reply/Plugin/Colors.pm @@ -33,9 +33,9 @@ C options. =cut class Reply::Plugin::Colors extends Reply::Plugin { - has $error_color = 'red'; - has $warning_color = 'yellow'; - has $result_color = 'green'; + has $!error_color = 'red'; + has $!warning_color = 'yellow'; + has $!result_color = 'green'; method compile ($next, @args) { local $SIG{__WARN__} = sub { $self->print_warn(@_) }; @@ -48,21 +48,21 @@ class Reply::Plugin::Colors extends Reply::Plugin { } method print_error ($next, $error) { - print color($error_color); + print color($!error_color); $next->($error); local $| = 1; print color('reset'); } method print_result ($next, @result) { - print color($result_color); + print color($!result_color); $next->(@result); local $| = 1; print color('reset'); } method print_warn ($warning) { - print color($warning_color); + print color($!warning_color); print $warning; local $| = 1; print color('reset'); diff --git a/lib/Reply/Plugin/DataDump.pm b/lib/Reply/Plugin/DataDump.pm index a2e90e2..d527925 100644 --- a/lib/Reply/Plugin/DataDump.pm +++ b/lib/Reply/Plugin/DataDump.pm @@ -24,8 +24,8 @@ value. =cut class Reply::Plugin::DataDump extends Reply::Plugin { - has $respect_stringification = 1; - has $filter = sub { + has $!respect_stringification = 1; + has $!filter = sub { my ($ctx, $ref) = @_; return unless $ctx->is_blessed; my $stringify = overload::Method($ref, '""'); @@ -36,11 +36,11 @@ class Reply::Plugin::DataDump extends Reply::Plugin { }; submethod BUILD { - undef $filter unless $respect_stringification; + undef $!filter unless $!respect_stringification; } method mangle_result (@result) { - return @result ? dumpf(@result, $filter) : (); + return @result ? dumpf(@result, $!filter) : (); } } diff --git a/lib/Reply/Plugin/Defaults.pm b/lib/Reply/Plugin/Defaults.pm index 7b595a9..7771531 100644 --- a/lib/Reply/Plugin/Defaults.pm +++ b/lib/Reply/Plugin/Defaults.pm @@ -24,7 +24,7 @@ BEGIN { PREFIX class Reply::Plugin::Defaults extends Reply::Plugin { - has $quit = 0; + has $!quit = 0; method prompt { "> " } @@ -63,12 +63,12 @@ class Reply::Plugin::Defaults extends Reply::Plugin { } method command_q { - $quit = 1; + $!quit = 1; return ''; } method loop ($continue) { - $continue = 0 if $quit; + $continue = 0 if $!quit; $continue; } } diff --git a/lib/Reply/Plugin/Editor.pm b/lib/Reply/Plugin/Editor.pm index 8f980cd..816e4fd 100644 --- a/lib/Reply/Plugin/Editor.pm +++ b/lib/Reply/Plugin/Editor.pm @@ -29,11 +29,11 @@ otherwise it will use the value of C<$ENV{VISUAL}> or C<$ENV{EDITOR}>. =cut class Reply::Plugin::Editor extends Reply::Plugin { - has $editor; - has $current_text = ''; + has $!editor; + has $!current_text = ''; submethod BUILD ($opts) { - $editor = Proc::InvokeEditor->new( + $!editor = Proc::InvokeEditor->new( (defined $opts->{editor} ? (editors => [ $opts->{editor} ]) : ()) @@ -53,7 +53,7 @@ class Reply::Plugin::Editor extends Reply::Plugin { ); } - my $current_text = do { + my $!current_text = do { local $/; if (open my $fh, '<', $line) { <$fh>; @@ -63,11 +63,11 @@ class Reply::Plugin::Editor extends Reply::Plugin { return ''; } }; - $text = $editor->edit($current_text, '.pl'); + $text = $!editor->edit($!current_text, '.pl'); } else { - $text = $editor->edit($current_text, '.pl'); - $current_text = $text; + $text = $!editor->edit($!current_text, '.pl'); + $!current_text = $text; } return $text; diff --git a/lib/Reply/Plugin/FancyPrompt.pm b/lib/Reply/Plugin/FancyPrompt.pm index c074bff..42c453b 100644 --- a/lib/Reply/Plugin/FancyPrompt.pm +++ b/lib/Reply/Plugin/FancyPrompt.pm @@ -19,17 +19,17 @@ current session. =cut class Reply::Plugin::FancyPrompt extends Reply::Plugin { - has $counter = 0; - has $prompted = 0; + has $!counter = 0; + has $!prompted = 0; method prompt ($next) { - $prompted = 1; - return $counter . $next->(); + $!prompted = 1; + return $!counter . $next->(); } method loop ($continue) { - $counter++ if $prompted; - $prompted = 0; + $!counter++ if $!prompted; + $!prompted = 0; $continue; } } diff --git a/lib/Reply/Plugin/Hints.pm b/lib/Reply/Plugin/Hints.pm index a944e40..4f4666d 100644 --- a/lib/Reply/Plugin/Hints.pm +++ b/lib/Reply/Plugin/Hints.pm @@ -30,9 +30,9 @@ lines (at least until C is given). =cut class Reply::Plugin::Hints extends Reply::Plugin { - has $hints = $default_hints; - has $hinthash = $default_hinthash; - has $warning_bits = $default_warning_bits; + has $!hints = $default_hints; + has $!hinthash = $default_hinthash; + has $!warning_bits = $default_warning_bits; method mangle_line ($line) { my $package = __PACKAGE__; @@ -56,15 +56,15 @@ LINE # XXX it'd be nice to avoid using globals here, but we can't use # eval_closure's environment parameter since we need to access the # information in a BEGIN block - our $HINTS = $hints; - our $HINTHASH = $hinthash; - our $WARNING_BITS = $warning_bits; + our $HINTS = $!hints; + our $HINTHASH = $!hinthash; + our $WARNING_BITS = $!warning_bits; my @result = $next->($line, %args); - $hints = $HINTS; - $hinthash = $HINTHASH; - $warning_bits = $WARNING_BITS; + $!hints = $HINTS; + $!hinthash = $HINTHASH; + $!warning_bits = $WARNING_BITS; return @result; } diff --git a/lib/Reply/Plugin/LexicalPersistence.pm b/lib/Reply/Plugin/LexicalPersistence.pm index 415f5a9..990fd70 100644 --- a/lib/Reply/Plugin/LexicalPersistence.pm +++ b/lib/Reply/Plugin/LexicalPersistence.pm @@ -21,7 +21,7 @@ then use C<$x> as expected in subsequent lines. =cut class Reply::Plugin::LexicalPersistence extends Reply::Plugin { - has $env = {}; + has $!env = {}; method compile ($next, $line, %args) { my ($code) = $next->($line, %args); @@ -29,12 +29,12 @@ class Reply::Plugin::LexicalPersistence extends Reply::Plugin { my $new_env = peek_sub($code); delete $new_env->{$_} for keys %{ closed_over($code) }; - $env = { %$env, %$new_env }; + $!env = { %{$!env}, %$new_env }; return $code; } - method lexical_environment { $env } + method lexical_environment { $!env } } 1; diff --git a/lib/Reply/Plugin/Nopaste.pm b/lib/Reply/Plugin/Nopaste.pm index 8ecf0e1..85106eb 100644 --- a/lib/Reply/Plugin/Nopaste.pm +++ b/lib/Reply/Plugin/Nopaste.pm @@ -28,43 +28,43 @@ like [DataDump], etc). =cut class Reply::Plugin::Nopaste extends Reply::Plugin { - has $history = ''; - has $service; + has $!history = ''; + has $!service; - has $prompt; - has $line; - has $result; + has $!prompt; + has $!line; + has $!result; method prompt ($next, @args) { - $prompt = $next->(@args); - return $prompt; + $!prompt = $next->(@args); + return $!prompt; } method read_line ($next, @args) { - $line = $next->(@args); - $line = "$line\n" if defined $line; - return $line; + $!line = $next->(@args); + $!line = "$!line\n" if defined $!line; + return $!line; } method print_error ($next, $error) { - $result = $error; + $!result = $error; $next->($error); } method print_result ($next, @result) { - $result = @result ? join('', @result) . "\n" : ''; + $!result = @result ? join('', @result) . "\n" : ''; $next->(@result); } method loop ($continue) { - $history .= "$prompt$line$result" - if defined $prompt - && defined $line - && defined $result; + $!history .= "$!prompt$!line$!result" + if defined $!prompt + && defined $!line + && defined $!result; - undef $prompt; - undef $line; - undef $result; + undef $!prompt; + undef $!line; + undef $!result; $continue; } @@ -73,11 +73,11 @@ class Reply::Plugin::Nopaste extends Reply::Plugin { $cmd_line = "Reply session" unless length $cmd_line; print App::Nopaste->nopaste( - text => $history, + text => $!history, desc => $cmd_line, lang => 'perl', - (defined $service - ? (services => [ $service ]) + (defined $!service + ? (services => [ $!service ]) : ()), ) . "\n"; diff --git a/lib/Reply/Plugin/Packages.pm b/lib/Reply/Plugin/Packages.pm index d2896d4..eccafa7 100644 --- a/lib/Reply/Plugin/Packages.pm +++ b/lib/Reply/Plugin/Packages.pm @@ -21,10 +21,10 @@ initial package to use when Reply starts up. =cut class Reply::Plugin::Packages extends Reply::Plugin { - has $package = 'main'; + has $!package = 'main'; submethod BUILD ($args) { - $package = $args->{default_package} + $!package = $args->{default_package} if defined $args->{default_package}; } @@ -45,12 +45,12 @@ LINE # XXX it'd be nice to avoid using globals here, but we can't use # eval_closure's environment parameter since we need to access the # information in a BEGIN block - $package = our $PACKAGE; + $!package = our $PACKAGE; return @result; } - method package { $package } + method package { $!package } } 1; diff --git a/lib/Reply/Plugin/ReadLine.pm b/lib/Reply/Plugin/ReadLine.pm index a33eaea..96531da 100644 --- a/lib/Reply/Plugin/ReadLine.pm +++ b/lib/Reply/Plugin/ReadLine.pm @@ -34,69 +34,69 @@ recommended if possible. =cut class Reply::Plugin::ReadLine extends Reply::Plugin { - has $term = Term::ReadLine->new('Reply'); - has $history_file = '.reply_history'; - has $history_length = -1; + has $!term = Term::ReadLine->new('Reply'); + has $!history_file = '.reply_history'; + has $!history_length = -1; # XXX these should be able to be lazy, but defaults can't see attributes # yet it seems - has $rl_gnu; - has $rl_perl5; - has $rl_caroline; + has $!rl_gnu; + has $!rl_perl5; + has $!rl_caroline; submethod BUILD ($opts) { - $rl_gnu = $term->ReadLine eq 'Term::ReadLine::Gnu'; - $rl_perl5 = $term->ReadLine eq 'Term::ReadLine::Perl5'; - $rl_caroline = $term->ReadLine eq 'Term::ReadLine::Caroline'; + $!rl_gnu = $!term->ReadLine eq 'Term::ReadLine::Gnu'; + $!rl_perl5 = $!term->ReadLine eq 'Term::ReadLine::Perl5'; + $!rl_caroline = $!term->ReadLine eq 'Term::ReadLine::Caroline'; - $history_file = File::Spec->catfile( - (File::Spec->file_name_is_absolute($history_file) + $!history_file = File::Spec->catfile( + (File::Spec->file_name_is_absolute($!history_file) ? () : (File::HomeDir->my_data)), - $history_file + $!history_file ); - if ($rl_perl5) { + if ($!rl_perl5) { # output compatible with Term::ReadLine::Gnu $readline::rl_scroll_nextline = 0; } - if ($rl_perl5 || $rl_gnu || $rl_caroline) { - $term->StifleHistory($history_length) - if $history_length >= 0; + if ($!rl_perl5 || $!rl_gnu || $!rl_caroline) { + $!term->StifleHistory($!history_length) + if $!history_length >= 0; } - if (open my $fh, '<', $history_file) { + if (open my $fh, '<', $!history_file) { for my $line (<$fh>) { chomp $line; - $term->addhistory($line); + $!term->addhistory($line); } } else { my $e = $!; - warn "Couldn't open $history_file for reading: $e" - if -e $history_file; + warn "Couldn't open $!history_file for reading: $e" + if -e $!history_file; } $self->_register_tab_complete; } method read_line ($next, $prompt) { - $term->readline($prompt); + $!term->readline($prompt); } submethod DEMOLISH { - return if $history_length == 0; - return unless $rl_gnu || $rl_perl5; - $term->WriteHistory($history_file) - or warn "Couldn't write history to $history_file"; + return if $!history_length == 0; + return unless $!rl_gnu || $!rl_perl5; + $!term->WriteHistory($!history_file) + or warn "Couldn't write history to $!history_file"; } method _register_tab_complete { weaken(my $weakself = $self); - if ($rl_gnu) { - $term->Attribs->{attempted_completion_function} = sub { + if ($!rl_gnu) { + $!term->Attribs->{attempted_completion_function} = sub { my ($text, $line, $start, $end) = @_; # discard everything after the cursor for completion purposes @@ -105,15 +105,15 @@ class Reply::Plugin::ReadLine extends Reply::Plugin { my @matches = $weakself->publish('tab_handler', $line); my $match_index = 0; - return $term->completion_matches($text, sub { + return $!term->completion_matches($text, sub { my ($text, $index) = @_; return $matches[$index]; }); }; } - if ($rl_perl5) { - $term->Attribs->{completion_function} = sub { + if ($!rl_perl5) { + $!term->Attribs->{completion_function} = sub { my ($text, $line, $start) = @_; my $end = $start + length($text); @@ -125,8 +125,8 @@ class Reply::Plugin::ReadLine extends Reply::Plugin { }; } - if ($rl_caroline) { - $term->caroline->completion_callback(sub { + if ($!rl_caroline) { + $!term->caroline->completion_callback(sub { my ($line) = @_; my @matches = $weakself->publish('tab_handler', $line); diff --git a/lib/Reply/Plugin/ResultCache.pm b/lib/Reply/Plugin/ResultCache.pm index 0407a68..9f9b68e 100644 --- a/lib/Reply/Plugin/ResultCache.pm +++ b/lib/Reply/Plugin/ResultCache.pm @@ -22,16 +22,16 @@ include an indication of where the value is stored, for later reference. =cut class Reply::Plugin::ResultCache extends Reply::Plugin { - has $results = []; - has $variable = 'res'; + has $!results = []; + has $!variable = 'res'; method execute ($next, @args) { my @res = $next->(@args); if (@res == 1) { - push @$results, $res[0]; + push @{$!results}, $res[0]; } elsif (@res > 1) { - push @$results, \@res; + push @{$!results}, \@res; } return @res; @@ -39,11 +39,11 @@ class Reply::Plugin::ResultCache extends Reply::Plugin { method mangle_result ($result) { return unless defined $result; - return '$' . $variable . '[' . $#$results . '] = ' . $result; + return '$' . $!variable . '[' . $#{$!results} . '] = ' . $result; } method lexical_environment { - return { "\@$variable" => [ @$results ] }; + return { "\@$!variable" => [ @{$!results} ] }; } } diff --git a/lib/Reply/Plugin/Timer.pm b/lib/Reply/Plugin/Timer.pm index bef91d7..07c620b 100644 --- a/lib/Reply/Plugin/Timer.pm +++ b/lib/Reply/Plugin/Timer.pm @@ -21,14 +21,14 @@ the default C is C<< 0.01 >> seconds. =cut class Reply::Plugin::Timer extends Reply::Plugin { - has $mintime = 0.01; + has $!mintime = 0.01; method execute ($next, @args) { my $t0 = [gettimeofday]; my $ret = $next->(@args); my $elapsed = tv_interval($t0); - if ($elapsed > $mintime) { + if ($elapsed > $!mintime) { if ($elapsed >= 1) { printf "Execution Time: %0.3fs\n", $elapsed } else { -- cgit v1.2.3