in reply to Callback Design
Like I said, it's just me messing around. It would be an interesting way to getting to package globals, but it's more of me just playing around rather than offering it as a serious programming solution. It is BAD CODE.my $coderef = sub { my ($package) = caller; $package->global }; package Base; sub AUTOLOAD { no strict 'refs'; # Please note the complete lack of # Sanity checking here :) return ${ $AUTOLOAD } if $AUTOLOAD =~ /^.*::\w+$/; } package Foo; @ISA=('Base'); $global = 'in Foo'; print &$coderef; package Bar; @ISA=('Base'); $global = 'in Bar'; print &$coderef;
And yes, the dot star is there on purpose. It'll catch package names like Foo::bar::baz.
Overall, this sort of problem is reminiscent of the "variable variable" problem as is indicative of underlying design issues that should be addressed. Be very careful of treading on this thin ice.
Cheers,
Ovid
Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.
|
|---|