File Coverage

blib/lib/Devel/REPL/Plugin/ModuleAutoLoader.pm
Criterion Covered Total %
statement 12 12 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 16 16 100.0


line stmt bran cond sub pod time code
1             package Devel::REPL::Plugin::ModuleAutoLoader;
2             # ABSTRACT: Provide functionality to attmept to AutoLoad modules.
3              
4 1     1   12743 use strict;
  1         2  
  1         21  
5 1     1   3 use warnings;
  1         1  
  1         34  
6              
7             our $VERSION = '1.0';
8              
9 1     1   379 use Devel::REPL::Plugin;
  1         307441  
  1         3  
10 1     1   3847 use namespace::autoclean;
  1         1  
  1         4  
11              
12             around 'execute' => sub {
13             my ($orig, $_REPL, @args) = @_;
14              
15             my @command_result = $_REPL->$orig(@args);
16             return @command_result
17             if ref($command_result[0]) ne 'Devel::REPL::Error';
18              
19             my ($unloaded_module) = $command_result[0]->{message}
20             =~ /perhaps you forgot to load "([\w:]+)"/;
21              
22             if ($unloaded_module) {
23             eval "require $unloaded_module" or warn $@;
24             return $_REPL->$orig(@args);
25             }
26              
27             # If we didn't find a module to load, just return the Error.
28             return @command_result;
29             };
30              
31             1;
32              
33             =pod
34              
35             =head1 NAME
36              
37             Devel::REPL::Plugin::ModuleAutoLoader - Autoloader Plugin for Devel::REPL
38              
39             =head1 VERSION
40              
41             Version 1.0
42              
43             =head1 DESCRIPTION
44              
45             Plugin for Devel::REPL that attempts automagically load modules used in a
46             line of code, that have yet to be loaded.
47              
48             Just load this plugin either from the Devel::REPL shell, or within your repl.rc
49             file and it does the rest.
50              
51             =head2 HIC SUNT DRACONES
52              
53             While this plugin is handy for lazy developers such as myself, there is one
54             side effect that you should be aware of.
55              
56             If the code contains a module that needs to be loaded, that statement will be
57             evaluated twice, this is the design of the plugin and not a bug.
58              
59             So:
60              
61             $ my $foo = 1;
62             1
63             $ $foo++; my $DateTime->now();
64             2016-07-05T14:51:50
65             $ $foo
66             3 # <-- Not what you'd expect!
67              
68             Just something to be aware of. ;)
69              
70             =head1 AUTHOR
71              
72             James Ronan, C<< <james at ronanweb.co.uk> >>
73              
74             =head1 BUGS
75              
76             Please report any bugs or feature requests to C<bug-devel-repl-plugin-moduleautoloader at rt.cpan.org>, or through
77             the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Devel-REPL-Plugin-ModuleAutoLoader>. I will be notified, and then you'll
78             automatically be notified of progress on your bug as I make changes.
79              
80              
81             =head1 SUPPORT
82              
83             You can find documentation for this module with the perldoc command.
84              
85             perldoc Devel::REPL::Plugin::ModuleAutoLoader
86              
87              
88             You can also look for information at:
89              
90             =over 4
91              
92             =item * RT: CPAN's request tracker (report bugs here)
93              
94             L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Devel-REPL-Plugin-ModuleAutoLoader>
95              
96             =item * AnnoCPAN: Annotated CPAN documentation
97              
98             L<http://annocpan.org/dist/Devel-REPL-Plugin-ModuleAutoLoader>
99              
100             =item * CPAN Ratings
101              
102             L<http://cpanratings.perl.org/d/Devel-REPL-Plugin-ModuleAutoLoader>
103              
104             =item * Search CPAN
105              
106             L<http://search.cpan.org/dist/Devel-REPL-Plugin-ModuleAutoLoader/>
107              
108             =back
109              
110             The source code can be found on GitHub:
111             L<https://github.com/jamesronan/Devel-REPL-Plugin-ModuleAutoloader>
112              
113             =head1 LICENSE AND COPYRIGHT
114              
115             Copyright 2016 James Ronan.
116              
117             This program is released under the following license: perl_5
118              
119             =cut
120              
121             1; # End of Devel::REPL::Plugin::ModuleAutoLoader