However this is a pretty nasty approach (I'm using string eval() for the love of ...). But if you're just attaching methods and attribs to a package in a fairly starightforward fashion you don't even need the package declarationmy $pkg = "Foo"; eval qq{ package $pkg; sub new { bless [], shift } }; print ref $pkg->new; __output__ Foo
Now you can have your dynamically created package just by fully qualifying the likes of subroutines and variables. So while it's possible to do what you want (this is Perl afterall) the question begs to be asked: why would you want to?my $pkg = "Foo"; { no strict 'refs'; *{"${pkg}::new"} = sub { bless [], shift }; } print ref $pkg->new; __output__ Foo
_________
broquaint
In reply to Re: constructing dynamic class definitions at compile time (from schema definition)
by broquaint
in thread constructing dynamic class definitions at compile time (from schema definition)
by sozinsky
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |