in reply to Re^4: Can't Reference a Sub by Variable when using Strict
in thread Can't Reference a Sub by Variable when using Strict
Try exporting symbols from one package to another like Exporter for example.The code below demonstrates a very simple exporting mechanism within the confines of strict
One might point out that the code in Symbol doesn't use strictures, but much of this could quite easily be done within its confines, however the code would necessarily be more verbose. If someone can find code that they believe can't be done within strictures then I shall quite happily rise to the occassion :)use strict; use warnings; use warnings::register; use Symbol 'qualify_to_ref'; sub import { my $cur = shift; my $dest = caller; for my $g (grep $cur->can($_), @_) { warnings::warnif("sub '$g' already exists in $dest") and next if $dest->can($g); my($dest, $src) = map qualify_to_ref("$_\::$g"), $dest, $cur; *$dest = *$src; } }
_________
broquaint
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Can't Reference a Sub by Variable when using Strict
by tachyon (Chancellor) on Oct 04, 2004 at 12:24 UTC | |
by broquaint (Abbot) on Oct 04, 2004 at 14:10 UTC |