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}

In reply to Re^5: What CODE typeglob slot is my anonymous sub in? by shmem
in thread What CODE typeglob slot is my anonymous sub in? by Ovid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.