Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Prototypes required even after mocking a sub

by haukex (Archbishop)
on Sep 24, 2018 at 20:16 UTC ( [id://1222933]=note: print w/replies, xml ) Need Help??


in reply to Prototypes required even after mocking a sub

If you set the prototype of your mock sub before replacing the original one, that should get rid of the warning, try commenting out the set_prototype call in the following and you should get the "Prototype mismatch" warning back:

use warnings; use strict; use Scalar::Util qw/set_prototype/; sub foo ($$$) { print "foo(@_)\n" } foo(1,2,3); # prints "foo(1 2 3)" { my $name = "foo"; my $sub = sub { print "bar(@_)\n" }; set_prototype(\&$sub,prototype($name)); #use Devel::Peek; Dump($sub); no strict 'refs'; no warnings 'redefine'; *$name = $sub; } foo(4,5,6); # prints "bar(4 5 6)"

By the way, in the code you showed, you're disabling strict 'refs' for a fairly large block of code.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2024-04-25 23:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found