Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re^2: Use cases for 'sub Pckg::func { }' ?

by bliako (Prior)
on Jul 31, 2020 at 23:23 UTC ( #11120163=note: print w/replies, xml ) Need Help??

in reply to Re: Use cases for 'sub Pckg::func { }' ?
in thread Use cases for 'sub Pckg::func { }' ?

jo37 you are guilty of monkey patching eueueueueueueu, sirens howling, you find yourself in a Cave. It's the cellar where the King keeps his barrels of wine. To the northeast there is the red door. Below there is a trap door. Oooopppss sorry, that was the punishment for acting over a distance. Let's go again monkey-patchers. Resume... You are in the trolls cave. To the north there is the heavy rock door. Thorin enters. He is laughing...

bw, bliako

  • Comment on Re^2: Use cases for 'sub Pckg::func { }' ?

Replies are listed 'Best First'.
Re^3: Use cases for 'sub Pckg::func { }' ?
by Tux (Abbot) on Aug 01, 2020 at 09:14 UTC

    I find a few reasons to not oppose to this (considered evil) path:

    1. Using a module that is not maintained and nobody took over, several patches were proposed but nobody uploaded a fixed version.
      Of course you can apply the patches locally before you install it, but that is no guarantee it is also fixed on other systems.
      It is way more reliable to overrule the faulty sub or make a new one foced into the faulty package thereby making sure it works.
    2. The package owner/maint has explicitely said *not* to add the requested/required functionality (they might even have documented so), so adding the desired method by forcing it into the package is relatively safe. (problematic would only be a new maintainer who disagrees with the refusal and putting it in later anyway)
    3. When working in supporting a module that is evolving, adding methods that are not yet implemented or have been removed, all guarded by version checks is a very fine way to make your module work for the end-users regardless of the changes in the underlying module(s). I do this very regularly. (example)
    4. Overruling CORE::GLOBAL functions in test files to provide stubs.

    Enjoy, Have FUN! H.Merijn
Re^3: Use cases for 'sub Pckg::func { }' ?
by jo37 (Friar) on Aug 01, 2020 at 07:02 UTC

    I confess.

    But seriously, why would I be punished for such:

    #!/usr/bin/perl use strict; use warnings; use LinkedList::Single; sub format_node_data { my ($id, $name) = @{$_[0]}; "[id:$id, name:$name]"; } sub LinkedList::Single::print { my $list = (shift)->clone; for ($list->head; $list->has_next; $list->next) { print format_node_data($list->node_data), " -> "; } print format_node_data($list->node_data), "\n"; } my $list = LinkedList::Single->new([1, 'foo'], [2, 'bar'], [3, 'baz']) +; $list->print; __DATA__ [id:1, name:foo] -> [id:2, name:bar] -> [id:3, name:baz]



Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11120163]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2020-11-27 12:11 GMT
Find Nodes?
    Voting Booth?

    No recent polls found