There's an unwrap
method, but the way it seems I'm supposed to use
it isn't the way it should be used. It seems like it should either be a
standalone routine or a method in a different class. What am I missing?
It appears that it doesn't care what its invocant is as long as it
gets the right Routine::WrapHandle
thingy as an argument. In this
example, I wrap
a subroutine and get back a WrapHandle
:
sub add-two-numbers ( $n, $m ) { $n + $m }
sub do-some-stuff ( $n, $m, $o ) {
add-two-numbers( $n max $m, $m max $o );
}
put do-some-stuff( 5, 10, 15 );
# now I want to look into do-some-stuff to see what it's
# passing
my $wraphandle = &add-two-numbers.wrap: {
say "Arguments were (@_[])";
callwith( |@_ );
}
put do-some-stuff( 5, 10, 15 );
Then, I can create a different and unrelated routine and call unwrap
on that:
my &routine = sub { 1 };
&routine.unwrap( $wraphandle );
put do-some-stuff( 5, 10, 15 );
The invocant to unwrap
seems superfluous. Indeed, I can call it as a
class method and it still works:
Routine.unwrap( $wraphandle );
But, it seems this should either be a routine (since the invocant doesn't matter):
unwrap( $wraphandle ); # doesn't exist
Or a method on Routine::WrapHandle
since that's the source of the
behavior:
$wraphandle.unwrap; # but, this method doesn't exist in that class
So, what am I missing about this method?