Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^3: How to redefine a modules private function?

by soonix (Canon)
on Mar 09, 2022 at 11:01 UTC ( [id://11141938]=note: print w/replies, xml ) Need Help??


in reply to Re^2: How to redefine a modules private function?
in thread How to redefine a modules private function?

Update: sorry, this is rubbish - see Re^5: How to redefine a modules private function?

Can't get AnyEvent installed ATM, but your little demo does work, if you don't "re"define it, but define it before you load the module:

Foo.pm as in your example

test2.pl
use warnings; use strict; use lib '.'; BEGIN { sub Foo::ONE () { 444 } sub Foo::TWO { 555 } sub Foo::THREE () { 666 } } use Foo; # _after_ your "re"definitions Foo::go; print "One=", Foo::ONE, ", Two=", Foo::TWO, ", Three=", Foo::THREE, "\ +n";

Replies are listed 'Best First'.
Re^4: How to redefine a modules private function?
by haukex (Archbishop) on Mar 09, 2022 at 13:25 UTC

    What output do you get? Because I get

    Constant subroutine ONE redefined at Foo.pm line 5. Subroutine TWO redefined at Foo.pm line 6. Constant subroutine THREE redefined at Foo.pm line 8. One=111, Two=222, Three=333 One=111, Two=222, Three=333

    which is what I would expect, since loading Foo.pm redefines the subs to the values that it has (111, 222, 333), not the values that we want (444, 555, 666).

      Yes, of course. Must be my beginning dementia. Either that or I got totally out of practice. I was a bit astonished that no one already came up with this, that I totally overlooked, which value is coming from the module and which from the script :-(

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2024-04-19 14:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found