Skip Menu |

This queue is for tickets about the Type-Tiny CPAN distribution.

Report information
The Basics
Id: 102457
Status: resolved
Priority: 0/
Queue: Type-Tiny

People
Owner: perl [...] toby.ink
Requestors: dagolden [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Document that compile needs to be called from within the subroutine
If compile is called outside the subroutine, any errors are reported from the place the coderef is called, not the caller's location. E.g. this won't be as expected: my $check = compile( Int ); sub foo { my ($int) = $check->(@_); } But this will do the right thing: my $check; sub foo { $check ||= compile( Int ); my ($int) = $check->(@_); }
Yes, this should be documented.
This can probably be fixed rather than just documented. I should be able to do it in 1.004.
It's caused by the fact that compile() sets a name for the compiled coderef, based on where it's called from. The exception object uses that name to skip over the right number of stack frames. If the name doesn't get set properly, it doesn't know how far to skip.
In the next release, you ought to be able to do this: my $check = compile( { subname => __PACKAGE__."::foo" }, Int ); sub foo { my ($int) = $check->(@_); } And that will hopefully fix things.
Documented in 1.004000.