| 1 | package Reply::Plugin::AutoRefresh; | ||
| 2 | our $AUTHORITY = 'cpan:DOY'; | ||
| 3 | $Reply::Plugin::AutoRefresh::VERSION = '0.42'; | ||
| 4 | use strict; | ||
| 5 | use warnings; | ||
| 6 | # ABSTRACT: automatically refreshes the external code you use | ||
| 7 | |||
| 8 | use base 'Reply::Plugin'; | ||
| 9 | use Class::Refresh 0.05 (); | ||
| 10 | |||
| 11 | |||
| 12 | sub new { | ||
| 13 | my $class = shift; | ||
| 14 | my %opts = @_; | ||
| 15 | |||
| 16 | $opts{track_require} = 1 | ||
| 17 | unless defined $opts{track_require}; | ||
| 18 | |||
| 19 | Class::Refresh->import(track_require => $opts{track_require}); | ||
| 20 | |||
| 21 | # so that when we load things after this plugin, they get a copy of | ||
| 22 | # Module::Runtime which has the call to require() rebound to our overridden | ||
| 23 | # copy. if this plugin is loaded first, these should be the only | ||
| 24 | # modules loaded so far which load arbitrary user-specified modules. | ||
| 25 | Class::Refresh->refresh_module('Module::Runtime'); | ||
| 26 | Class::Refresh->refresh_module('base'); | ||
| 27 | |||
| 28 | return $class->SUPER::new(@_); | ||
| 29 | } | ||
| 30 | |||
| 31 | sub compile { | ||
| 32 | my $self = shift; | ||
| 33 | my ($next, @args) = @_; | ||
| 34 | |||
| 35 | Class::Refresh->refresh; | ||
| 36 | $next->(@args); | ||
| 37 | } | ||
| 38 | |||
| 39 | 1; | ||
| 40 | |||
| 41 | __END__ |