note
betterworld
<p>Some funny code I wrote yesterday (the technique can be probably used for your problem too):</p>
<c>
use Symbol qw(qualify_to_ref);
use overload;
my $stashref = qualify_to_ref("${namespace}::");
package tmp;
local *tmp:: = *$stashref;
overload->import('+' => sub {
my $self = shift;
my ($other, $info) = @_;
# do some stuff
});
</c>
<p>This sets up overloaded operators for the namespace with the computed name <c>$namespace</c>.</p>
<p>Note that you cannot use "main" instead of "tmp", because the main namespace seems to be too read-only for this kind of hack (you'd get the error "Modification of read-only value attempted")</p>
771388
771388