set_prototype#

set_prototype($code, $prototype) - sets the prototype of the subroutine given by the $code reference, or deletes it if $prototype is undef.

Returns the $code reference itself, so calls can be chained. The code reference comes FIRST and the prototype second; Sub::Util spells the same operation with the arguments the other way round.

set_prototype \&foo, '$$';

The &$ prototype makes the first argument a \&name or sub {...} and a call with fewer than two arguments a compile-time error. Called with & to bypass the prototype, a missing prototype argument deletes the prototype, and a first argument that is not a reference to a subroutine croaks with set_prototype: not a subroutine reference (set_prototype: not a reference when it is no reference at all).