1package Reply::Plugin::LoadClass; 2our $AUTHORITY = 'cpan:DOY'; 3$Reply::Plugin::LoadClass::VERSION = '0.42'; 4use strict; 5use warnings; 6# ABSTRACT: attempts to load classes implicitly if possible 7 8use base 'Reply::Plugin'; 9 10use Module::Runtime 'use_package_optimistically'; 11use Try::Tiny; 12 13 14sub execute { 15 my $self = shift; 16 my ($next, @args) = @_; 17 18 try { 19 $next->(@args); 20 } 21 catch { 22 if (/^Can't locate object method "[^"]*" via package "([^"]*)"/) { 23 use_package_optimistically($1); 24 $next->(@args); 25 } 26 else { 27 die $_; 28 } 29 } 30} 31 321; 33 34__END__ 35 36=pod 37 38=encoding UTF-8 39 40=head1 NAME 41 42Reply::Plugin::LoadClass - attempts to load classes implicitly if possible 43 44=head1 VERSION 45 46version 0.42 47 48=head1 SYNOPSIS 49 50 ; .replyrc 51 [LoadClass] 52 53=head1 DESCRIPTION 54 55If executing a line of code fails due to a method not being defined on a 56package, this plugin will load the corresponding module and then try executing 57the line again. This simplifies common cases like running C<< DateTime->now >> 58at the prompt before loading L<DateTime> - this plugin will cause DateTime to 59be loaded implicitly. 60 61=head1 AUTHOR 62 63Jesse Luehrs <doy@tozt.net> 64 65=head1 COPYRIGHT AND LICENSE 66 67This software is Copyright (c) 2016 by Jesse Luehrs. 68 69This is free software, licensed under: 70 71 The MIT (X11) License 72 73=cut 74