From e5a7afe08c7dcad0245ca97eb1394bb5221960cd Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Thu, 27 Jun 2013 18:58:14 -0400 Subject: update docs --- lib/Reply/Plugin.pm | 63 ++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 17 deletions(-) (limited to 'lib/Reply/Plugin.pm') diff --git a/lib/Reply/Plugin.pm b/lib/Reply/Plugin.pm index c0746d1..ed3efbb 100644 --- a/lib/Reply/Plugin.pm +++ b/lib/Reply/Plugin.pm @@ -77,23 +77,7 @@ Compiles the string of Perl code into a coderef. Takes the line of code as a string and a hash of extra parameters, and returns the coderef to be executed. The default implementation uses L to compile the given string. -The extra parameters can be anything that C supports, as well as -these additional parameters: - -=over 4 - -=item package - -The package to use to evaluate the code within. Defaults to C
. - -=item environments - -A hashref of additional lexical environments to be merged with the main lexical -environment in the C key. This allows plugins to ensure that their -extra additions to the lexical scope remain visible, even if other plugins -change what "the current lexical scope" means. - -=back +The hash of extra parameters is passed directly to C. =item execute @@ -135,6 +119,43 @@ should terminate. =back +Reply plugins can also communicate among each other via a pub/sub mechanism. By +calling the C method, all plugins which respond to the given message +(implement a method of the given name) will have that method called with the +given arguments, and all of the responses will be collected and returned. Some +messages used by the default plugins are: + +=over 4 + +=item tab_handler ($line) + +Plugins can publish this message when they want to attempt tab completion. +Plugins that respond to this message should return a list of potential +completions of the line which is passed in. + +=item lexical_environment ($name, $env) + +Plugins which wish to modify the lexical environment should do so by publishing +this message. This will register it with the repl itself, as well as allowing +other plugins which introspect the lexical environment to see it. + +There can be more than one lexical environment, which are all merged together +when the line is evaluated. C is the primary environment (typically +corresponding to the user's code). All other environments should typically have +unique names, and are used to add additonal variables to the environment that +won't be overridden if a plugin decides to replace the default environment. + +=item package ($name) + +Plugins which wish to modify the currently active package should do so by +publishing this message. This will register it with the repl itself, as well as +allowing other plugins which introspect the current package to see it. + +=back + +Your plugins, however, are not limited to these messages - you can use whatever +messages you want to communicate. + =cut sub new { @@ -148,6 +169,14 @@ sub new { }, $class; } +=method publish ($name, @args) + +Publish a message to other plugins which respond to it. All loaded plugins +which implement a method named C<$name> will have it called with C<@args> as +the parameters. Returns a list of everything that each plugin responded with. + +=cut + sub publish { my $self = shift; -- cgit v1.2.3-54-g00ecf