Good day esteemed friends,

I'm writing a new module that will be long running. This module will have a function that requires code from another one of my modules (which loads 115+ other modules and dependencies), but this function will only be called on extremely rare situations so I don't want to use it.

I've written some mock-up (working) test code, and I'm just looking to see if this is a sane thing to do, and/or feedback on alternative approaches.

use strict; use warnings; use Symbol qw(delete_package); my @pre_require = keys %INC; print "Modules pre-require: " . @pre_require . "\n"; require Devel::Examine::Subs; import Devel::Examine::Subs; my @post_require = keys %INC; # do something with imported module immediately after # getting the post-require %INC count ... print "Modules post-require: " . @post_require . "\n"; my $count = @post_require - @pre_require; print "Additional modules loaded: $count\n"; for my $file (@post_require){ if (! grep /$file/, @pre_require){ (my $module = $file ) =~ s/\//::/g; $module =~ s/\.pm$//; delete_package $module; delete $INC{$file}; } } __END__ Modules pre-require: 4 Modules post-require: 138 Additional modules loaded: 134 Module count post cleanup: 4

Thanks,

-stevieb


In reply to Is this a safe way to 'un'-require a module? by stevieb

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.