Acme-SubstituteSubs

 view release on metacpan or  search on metacpan

lib/Acme/SubstituteSubs.pm  view on Meta::CPAN

    my $say_hi = Acme::SubstituteSubs->get('main::say_hi') or die;
    $say_hi =~ s/"hi/"hihi/;
    Acme::SubstituteSubs->set('main::say_hi', $say_hi) or die;
    say_hi();

    exec 'perl', $0;


=head1 DESCRIPTION

Replaces subroutine definitions in the source code, probably for code that edits
itself or lets its user edit it.

=head2 C<< Acme::SubstituteSubs->get($qualified_function_name) >>

Returns the text of the named function straight from the source file.
For the purposes of this module, all code comes from and goes to the top-level C<.pl> file
as indicated by F<FindBin>'s C<$RealScript> value.
Returns nothing if the sub is not found.

=head2 C<< Acme::SubstituteSubs->set($qualified_function_name, $replacement_code) >>

lib/Acme/SubstituteSubs.pm  view on Meta::CPAN

the new function placed after it.

If attempting to replace a function defined elsewhere than the top level C<.pl> file, such as in some module, 
the module won't be changed, but the code will instead be replicated into the main script.
The result is undefined when run from C<perl -e>.

C<die>s if it fails to write and replace the original source file.

=head2 C<< Acme::SubstituteSubs->list() >>

Lists C<namespace::function> combinations available for edit.

=head2 C<< Acme::SubstituteSubs->list_packages() >>

Lists packages defined in the source script.

=head1 TODO/BUGS

=item Needs a REPL plugin, so REPLs can call this when the user redefines a subroutine.

=item Parses the document again each time a method is called rather than caching it.  Bug.



( run in 0.471 second using v1.01-cache-2.11-cpan-de7293f3b23 )