Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: Aren't there code refs as well as function refs?

by dd-b (Monk)
on Mar 04, 2023 at 00:44 UTC ( [id://11150729] : note . print w/replies, xml ) Need Help??


in reply to Re: Aren't there code refs as well as function refs?
in thread Aren't there code refs as well as function refs?

It may well be useful; if it is useful, it is as evidence towards the hypothesis that things don't work the way I think they do.

There are a lot of places where anonymous blocks occur in magic being worked by packages. Here's an example from the perldoc for Test::Exception where the throws_ok function uses this:

throws_ok { read_file( 'unreadable' ) } qr/No file/, 'no file';

I'm wondering what throws_ok() receives, where, and how. Yes, I notice the missing comma; this is like a print statement where the first optional param (fd in that case) is not separated by a comma from the regular arguments.

Replies are listed 'Best First'.
Re^3: Aren't there code refs as well as function refs?
by LanX (Saint) on Mar 04, 2023 at 07:59 UTC
    It's obviously using a prototype, the missing comma is typical

    And looking into the sources proves it

    sub throws_ok (&$;$) { my ( $coderef, $expecting, $description ) = @_;

    See my other post for more

    Cheers Rolf
    (addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
    Wikisyntax for the Monastery

Re^3: Aren't there code refs as well as function refs?
by ikegami (Patriarch) on Mar 07, 2023 at 00:30 UTC
    The prototype of throw_ok is &$;$, so
    throws_ok { ... } ..., ...;
    is equivalent to
    &throws_ok( sub { ... }, scalar( ... ), scalar( ... ) );