I'm dynamically generating subroutines and assigning them to actual subs:
my @types = qw( date integer text timestamp ); foreach my $type (@types) { my $function = uc $type; no strict 'refs'; *$function = sub { if ( looks_like_number( $_[0] ) ) { die "Datatype '$type' does not require a numeric length '$ +_[0]'"; } return { type => $type, @_ }; }; }
However, sometimes I need to alias those subroutines:
*TINYTEXT = \&TEXT;That cause a problem because the '$type' referred to in the error message should actually be the lower-cased name of the subroutine, not the original type that was generated. Both 'TINYTEXT(3)' and 'TEXT(3)' will generate an error message referring to 'text'.
I tried to use caller, but that doesn't work because it reports 'main::__ANON__' instead of which CODE slot in the typeglob that this anonymous sub is assigned to. Is there any way I can figure that out from within an anonymous sub?
(I can get around this in numerous ways by providing 'sub' to 'type' mappings or manually coding the aliased subroutines, but I'd much prefer to avoid the grunt work).
Cheers,
Ovid
New address of my CGI Course.
In reply to What CODE typeglob slot is my anonymous sub in? by Ovid
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |