File Coverage

blib/lib/Devel/REPL/Plugin/FindVariable.pm
Criterion Covered Total %
statement 12 22 54.5
branch 0 14 0.0
condition 0 3 0.0
subroutine 4 5 80.0
pod 0 1 0.0
total 16 45 35.5


line stmt bran cond sub pod time code
1 2     2   17264 use strict;
  2         2  
  2         61  
2 2     2   7 use warnings;
  2         15  
  2         116  
3             package Devel::REPL::Plugin::FindVariable;
4             # ABSTRACT: Finds variables by name
5              
6             our $VERSION = '1.003028';
7              
8 2     2   8 use Devel::REPL::Plugin;
  2         3  
  2         11  
9 2     2   6087 use namespace::autoclean;
  2         3  
  2         15  
10              
11             sub find_variable {
12 0     0 0   my ($self, $name) = @_;
13              
14 0 0         return \$self if $name eq '$_REPL';
15              
16             # XXX: this code needs to live in LexEnv
17 0 0         if ($self->can('lexical_environment')) {
18             return \( $self->lexical_environment->get_context('_')->{$name} )
19 0 0         if exists $self->lexical_environment->get_context('_')->{$name};
20             }
21              
22 0 0         my $sigil = $name =~ s/^([\$\@\%\&\*])// ? $1 : '';
23              
24 0 0         my $default_package = $self->can('current_package')
25             ? $self->current_package
26             : 'main';
27 0 0         my $package = $name =~ s/^(.*)(::|')// ? $1 : $default_package;
28              
29 0           my $meta = Class::MOP::Class->initialize($package);
30              
31             # Class::MOP::Package::has_package_symbol method *requires* a sigil
32 0 0 0       return unless length($sigil) and $meta->has_package_symbol("$sigil$name");
33 0           $meta->get_package_symbol("$sigil$name");
34             }
35              
36             1;
37              
38             __END__
39              
40             =pod
41              
42             =encoding UTF-8
43              
44             =head1 NAME
45              
46             Devel::REPL::Plugin::FindVariable - Finds variables by name
47              
48             =head1 VERSION
49              
50             version 1.003028
51              
52             =head1 SUPPORT
53              
54             Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=Devel-REPL>
55             (or L<bug-Devel-REPL@rt.cpan.org|mailto:bug-Devel-REPL@rt.cpan.org>).
56              
57             There is also an irc channel available for users of this distribution, at
58             L<C<#devel> on C<irc.perl.org>|irc://irc.perl.org/#devel-repl>.
59              
60             =head1 AUTHOR
61              
62             Shawn M Moore, C<< <sartak at gmail dot com> >>
63              
64             =head1 COPYRIGHT AND LICENCE
65              
66             This software is copyright (c) 2007 by Matt S Trout - mst (at) shadowcatsystems.co.uk (L<http://www.shadowcatsystems.co.uk/>).
67              
68             This is free software; you can redistribute it and/or modify it under
69             the same terms as the Perl 5 programming language system itself.
70              
71             =cut