Commit | Line | Data |
e93892cd |
1 | package Devel::REPL::Plugin::FindVariable; |
2 | |
6a5409bc |
3 | use Devel::REPL::Plugin; |
e2d0b019 |
4 | use namespace::sweep; |
5 | use Package::Stash; |
e93892cd |
6 | |
7 | sub find_variable { |
8 | my ($self, $name) = @_; |
9 | |
06df0767 |
10 | return \$self if $name eq '$_REPL'; |
11 | |
6d22063d |
12 | # XXX: this code needs to live in LexEnv |
13 | if ($self->can('lexical_environment')) { |
14 | return \( $self->lexical_environment->get_context('_')->{$name} ) |
15 | if exists $self->lexical_environment->get_context('_')->{$name}; |
16 | } |
17 | |
e93892cd |
18 | my $sigil = $name =~ s/^([\$\@\%\&\*])// ? $1 : ''; |
19 | |
20 | my $default_package = $self->can('current_package') |
21 | ? $self->current_package |
22 | : 'main'; |
23 | my $package = $name =~ s/^(.*)(::|')// ? $1 : $default_package; |
24 | |
e2d0b019 |
25 | my $meta = Package::Stash->new($package); |
e93892cd |
26 | |
e2d0b019 |
27 | # Package::Stash::has_symbol method *requires* a sigil |
28 | return unless length($sigil) and $meta->has_symbol("$sigil$name"); |
29 | $meta->get_symbol("$sigil$name"); |
e93892cd |
30 | } |
31 | |
32 | 1; |
33 | |
cfd1094b |
34 | __END__ |
35 | |
36 | =head1 NAME |
37 | |
38 | Devel::REPL::Plugin::FindVariable - Finds variables by name |
39 | |
30b459d4 |
40 | =head1 AUTHOR |
41 | |
42 | Shawn M Moore, C<< <sartak at gmail dot com> >> |
43 | |
cfd1094b |
44 | =cut |
45 | |