in reply to Re^2: Best practice for handling subroutines that are conditionally loaded?
in thread Best practice for handling subroutines that are conditionally loaded?

Either unsprinkle them or generate the empty function stubs automatically inside a BEGIN block.¹

Having code all over the place calling "Schrödinger" functions doesn't strike me as a good design decision.

The next maintainer might lock you in a box with randomly activated poison. ;)

Update

¹) something like BEGIN { *{$_} = sub {} for @imports }

NB: you can reuse @imports for your use if to keep it DRY

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

Replies are listed 'Best First'.
Re^4: Best practice for handling subroutines that are conditionally loaded?
by nysus (Parson) on Mar 08, 2024 at 15:28 UTC

    These are modules for my own use that are in alpha or beta stages and undergo frequent changes. Sprinkling and unsprinkling in debug code sucks. This way I can just leave it in for a few months. After the module matures enough, and surely if I'm going to share it, I would then "unsprinkle" these calls.

    $PM = "Perl Monk's";
    $MC = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar Parson";
    $nysus = $PM . ' ' . $MC;
    Click here if you love Perl Monks

Re^4: Best practice for handling subroutines that are conditionally loaded? (Updated)
by nysus (Parson) on Mar 08, 2024 at 16:03 UTC

    Your snippet is pretty slick. But I could not get it to work when loaded from an outside module so I could avoid boilerplate. You can see my comment below for the solution I ended up implementing. Thanks for your help with this and suggestions.

    $PM = "Perl Monk's";
    $MC = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar Parson";
    $nysus = $PM . ' ' . $MC;
    Click here if you love Perl Monks