in reply to Re^3: Defining a subroutine in another package
in thread Defining a subroutine in another package
All typeglobs do is associate the seven things that can be named with global names. Think of them as hashes that can only hold six keys -- SCALAR, ARRAY, HASH, CODE, IO, FORMAT. These are called slots, and you can get at the content of a glob by using the slot name as you would a hash key. The global (non-lexical) $foo, @foo, %foo, *foo, and &foo can all live within the typeglob *foo. Internally, anything that tries to use something with the name 'foo' will be resolved to use one of those things. Perl grabs the appropriate glob (resolving package names as necessary), then grabs the requested item from the appropriate glob slot.
Again, these are all things that have global and not lexical names.
You can copy typeglobs and assign to them. If you assign it a reference to something, it'll automatically populate (or overwrite) the appropriate slot. That's how Exporter works:
*{$package . '::mynewsub'} = \&mynewsub;
|
|---|