in reply to Refresh a Module

LanX presented this topic at the Frankfurt Perl Workshop last Sunday and we discussed it. The main point I find missing is, that the redefinitions can only affect code, and not data. This makes the whole thing a non-starter for me, since for example reloading a class/object package will only do what I want if I don't declare new accessors and don't restructure my existing object tree:

my $info = My::Config->new( Load( 'config.yaml' )); # in My::Config package My::Config 0.01 { use Moo 2; has 'include_files' => ( is => 'lazy', default => sub { [] }, ); }; # After update: # in My::Config package My::Config 0.01 { use Moo 2; has 'plugins' => ( is => 'lazy', default => sub { [] }, ); has 'include_templates' => ( is => 'lazy', default => sub { [] }, ); };

If the above happens, you will still have an object $info that looks like:

$info = { include_files => [], };

... but the other code will never access the old data.

I can imagine cases where I want both, blowing away the old data, and keeping the old data, and I think there is no good "automatic" way of determining what I want in each case.

In limited situations, for example where programmer-users are allowed to rewrite some plugin code that gets hot-reloaded, and that plugin code is required to act in a functional way, that is, having no state of its own, reloading a module can still work.

Replies are listed 'Best First'.
Re^2: Refresh a Module
by LanX (Saint) on Oct 01, 2024 at 14:11 UTC
    I'm not using Moo(se) but this looks like you are changing the interface after reload.

    Obviously (for me) you must respect the contract, when replacing code in a live system.

    Regarding data, there is a reason why languages like Haskell require their functions to be "pure", i.e. to have no side effects or inner states.

    Regarding Perl modules, a reload would need to handle not only functions, but also with package variables being used outside the module and/or lexical closure variables carrying state.

    I could think of a solution with a proxy module shadowing all this, but this l also depends on the concrete requirements.

    And practicality is different for development and production scenarios..

    Last but not least, I can't really comment on OO frameworks. If their inner workings make it impossible to make data persistent, there is not much which can be done.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery