Add CompletionDriver::Turtles
nothingmuch [Tue, 6 May 2008 02:06:01 +0000 (02:06 +0000)]
git-svn-id: http://dev.catalyst.perl.org/repos/bast/trunk/Devel-REPL@4340 bd8105ee-0ff8-0310-8827-fb3f25b6796d

lib/Devel/REPL/Plugin/CompletionDriver/Turtles.pm [new file with mode: 0644]

diff --git a/lib/Devel/REPL/Plugin/CompletionDriver/Turtles.pm b/lib/Devel/REPL/Plugin/CompletionDriver/Turtles.pm
new file mode 100644 (file)
index 0000000..940bbff
--- /dev/null
@@ -0,0 +1,41 @@
+#!/usr/bin/perl
+
+package Devel::REPL::Plugin::CompletionDriver::Turtles;
+use Devel::REPL::Plugin;
+
+with qw(
+  Devel::REPL::Plugin::Completion
+  Devel::REPL::Plugin::Turtles
+);
+
+around complete => sub {
+  my $orig = shift;
+  my ($self, $text, $document) = @_;
+
+  my $prefix = $self->default_command_prefix;
+  my $line_re = qr/^($prefix)(\w+)/;
+
+  my @orig = $self->$orig($text, $document);
+
+  if ( my ( $pre, $method ) = ( $text =~ $line_re ) ) {
+    my $filter = qr/^\Q$method/;
+    return (
+      @orig,
+      (
+        map { "$pre$_" }
+        grep { $_ =~ $filter }
+        map { /^expr?_command_(\w+)/ ? $1 : () }
+        map { $_->{name} }
+        $self->meta->compute_all_applicable_methods
+      ),
+    );
+  } else {
+    return @orig;
+  }
+};
+
+__PACKAGE__
+
+__END__
+
+