From: Sartak Date: Mon, 26 May 2008 03:13:54 +0000 (+0000) Subject: FindVariable plugin, which returns a reference to a global variable by name X-Git-Tag: v1.003015~101 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e93892cd24b9c3a90f80dd4445043513b05211a1;p=p5sagit%2FDevel-REPL.git FindVariable plugin, which returns a reference to a global variable by name git-svn-id: http://dev.catalyst.perl.org/repos/bast/trunk/Devel-REPL@4408 bd8105ee-0ff8-0310-8827-fb3f25b6796d --- diff --git a/lib/Devel/REPL/Plugin/FindVariable.pm b/lib/Devel/REPL/Plugin/FindVariable.pm new file mode 100644 index 0000000..2b35755 --- /dev/null +++ b/lib/Devel/REPL/Plugin/FindVariable.pm @@ -0,0 +1,23 @@ +package Devel::REPL::Plugin::FindVariable; + +use Moose::Role; +use namespace::clean -except => [ 'meta' ]; + +sub find_variable { + my ($self, $name) = @_; + + my $sigil = $name =~ s/^([\$\@\%\&\*])// ? $1 : ''; + + my $default_package = $self->can('current_package') + ? $self->current_package + : 'main'; + my $package = $name =~ s/^(.*)(::|')// ? $1 : $default_package; + + my $meta = Class::MOP::Class->initialize($package); + + return unless $meta->has_package_symbol("$sigil$name"); + $meta->get_package_symbol("$sigil$name"); +} + +1; +