in reply to Re: Testing private methods a no-no?
in thread Testing private methods a no-no?

Hello shawnhcorey,

This is nice, but it’s probably cleaner to assign the subroutine reference to a lexical variable:

{ my $foo = sub { my ($n) = @_; print "foo($n)\n"; }; $foo->(1); # valid call } $foo->(2); # invalid call

This has the advantage of changing the invalid call from a runtime error into a compiletime error.

From Perl v5.18 on you can also use the experimental Lexical Subroutines feature.

Update: Fixed typo in the code snippet.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,