in reply to Re^4: What CODE typeglob slot is my anonymous sub in?
in thread What CODE typeglob slot is my anonymous sub in?

update: proper link "Gives me ideas for this" since http://use.perl.org is on hiatus.

Ah, now. What you ask for is a subroutine that knows its dispatching word. Something like...
#!/usr/bin/perl use strict; use warnings; use Devel::Peek; my @types = qw( text ); foreach my $type (@types) { my $function = uc $type; my $type_sub; no strict 'refs'; $type_sub = \&$function; *$type = sub { warn "subtype: ",shift,"\n"; warn "args: @_\n"; warn "typeglob slot: ",Devel::Peek::CvGV($type_sub),"\n"; }; *$function = sub { &{$type}($function,@_); }; } sub alias { my ($target, $source) = @_; no strict 'refs'; *$target = sub { \&{lc $source}(lc $target,@_) }; } alias("TINYTEXT","TEXT"); TINYTEXT(3); *text = sub { warn "wuff! @_\n" }; TINYTEXT("which spake the blue_cowdawg."); __END__ subtype: tinytext args: 3 typeglob slot: *main::TEXT Subroutine main::text redefined at ovid.pl line 36. wuff! tinytext which spake the blue_cowdawg.

Sort of "reverse curry" :-)

You have lowercase subs which you enrich with the alias name, and wrap those into the uppercase sub. While the outer sub remains the same, you can massage the inner sub and have it changed for all aliases. While not a solution for Y, it's a solution for X :-)

Well, you could overload the assignment operator, for typeglob assignments, also...

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}