[Bast-commits] r4408 - trunk/Devel-REPL/lib/Devel/REPL/Plugin
Sartak at dev.catalyst.perl.org
Sartak at dev.catalyst.perl.org
Mon May 26 04:13:55 BST 2008
Author: Sartak
Date: 2008-05-26 04:13:54 +0100 (Mon, 26 May 2008)
New Revision: 4408
Added:
trunk/Devel-REPL/lib/Devel/REPL/Plugin/FindVariable.pm
Log:
FindVariable plugin, which returns a reference to a global variable by name
Added: trunk/Devel-REPL/lib/Devel/REPL/Plugin/FindVariable.pm
===================================================================
--- trunk/Devel-REPL/lib/Devel/REPL/Plugin/FindVariable.pm (rev 0)
+++ trunk/Devel-REPL/lib/Devel/REPL/Plugin/FindVariable.pm 2008-05-26 03:13:54 UTC (rev 4408)
@@ -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;
+
More information about the Bast-commits
mailing list