From 3e19fb26f62ce9fa02e417c015f6668989d1eaad Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Wed, 7 Aug 2013 22:28:04 -0400 Subject: convert all of the plugins --- lib/Reply/Plugin/Defaults.pm | 105 ++++++++++++++++--------------------------- 1 file changed, 39 insertions(+), 66 deletions(-) (limited to 'lib/Reply/Plugin/Defaults.pm') diff --git a/lib/Reply/Plugin/Defaults.pm b/lib/Reply/Plugin/Defaults.pm index e7874e3..7b595a9 100644 --- a/lib/Reply/Plugin/Defaults.pm +++ b/lib/Reply/Plugin/Defaults.pm @@ -1,4 +1,4 @@ -package Reply::Plugin::Defaults; +package main; # XXX Eval::Closure imposes its own hints on things that are eval'ed at the # moment, but this may be fixed in the future @@ -11,29 +11,10 @@ BEGIN { use strict; use warnings; -use base 'Reply::Plugin'; +use mop; use Eval::Closure 0.11; -sub new { - my $class = shift; - - my $self = $class->SUPER::new(@_); - $self->{quit} = 0; - - return $self; -} - -sub prompt { "> " } - -sub read_line { - my $self = shift; - my ($next, $prompt) = @_; - - print $prompt; - return scalar ; -} - (my $PREFIX = <<'PREFIX') =~ s/__PACKAGE__/__PACKAGE__/ge; BEGIN { $^H = $__PACKAGE__::default_hints; @@ -42,62 +23,54 @@ BEGIN { } PREFIX -sub compile { - my $self = shift; - my ($next, $line, %args) = @_; +class Reply::Plugin::Defaults extends Reply::Plugin { + has $quit = 0; - my $env = { map { %$_ } $self->publish('lexical_environment') }; - my $package = ($self->publish('package'))[-1]; + method prompt { "> " } - my $prefix = "package $package;\n$PREFIX"; + method read_line ($next, $prompt) { + print $prompt; + return scalar ; + } - my $code = eval_closure( - source => "sub {\n$prefix;\n$line\n}", - terse_error => 1, - alias => 1, - environment => $env, - %args, - ); + method compile ($next, $line, %args) { + my $env = { map { %$_ } $self->publish('lexical_environment') }; + my $package = ($self->publish('package'))[-1]; - return $code; -} - -sub execute { - my $self = shift; - my ($next, $code, @args) = @_; - - return $code->(@args); -} + my $prefix = "package $package;\n$PREFIX"; -sub print_error { - my $self = shift; - my ($next, $error) = @_; + my $code = eval_closure( + source => "sub {\n$prefix;\n$line\n}", + terse_error => 1, + alias => 1, + environment => $env, + %args, + ); - print $error - if defined $error; -} - -sub print_result { - my $self = shift; - my ($next, @result) = @_; + return $code; + } - print @result, "\n" - if @result; -} + method execute ($next, $code, @args) { + return $code->(@args); + } -sub command_q { - my $self = shift; - $self->{quit} = 1; - return ''; -} + method print_error ($next, $error) { + print $error if defined $error; + } -sub loop { - my $self = shift; - my ($continue) = @_; + method print_result ($next, @result) { + print @result, "\n" if @result; + } - $continue = 0 if $self->{quit}; + method command_q { + $quit = 1; + return ''; + } - return $continue; + method loop ($continue) { + $continue = 0 if $quit; + $continue; + } } =begin Pod::Coverage -- cgit v1.2.3-54-g00ecf