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