in reply to Dynamically Changing Packages w/out Eval
Some funny code I wrote yesterday (the technique can be probably used for your problem too):
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 });
This sets up overloaded operators for the namespace with the computed name $namespace.
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")
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Dynamically Changing Packages w/out Eval
by ikegami (Patriarch) on Aug 24, 2009 at 13:41 UTC | |
by betterworld (Curate) on Aug 24, 2009 at 14:13 UTC | |
by ikegami (Patriarch) on Aug 24, 2009 at 14:43 UTC | |
by betterworld (Curate) on Aug 24, 2009 at 19:54 UTC | |
by ikegami (Patriarch) on Aug 24, 2009 at 21:35 UTC | |
by Anonymous Monk on Aug 24, 2009 at 14:15 UTC |
In Section
Seekers of Perl Wisdom