jaa has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks,
I want to temporarily re-bless an instance into a specialised child-class for the scope of a block. Is there any way to do this automatically? or do I have to bless and reverse bless as in this eg?
# is there any way to limit the scope of bless? sub doit { my $db = shift; die "not a database class: $db" unless $db->isa("Database"); my $original = ref($db); bless $db, "Database::Special"; $db->doSomethingSpecial(); bless $db, $original; return $db->doNormalStuff(); }
Regards & thanks,
Jeff
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: limiting the scope of bless
by ferreira (Chaplain) on Apr 25, 2007 at 10:58 UTC | |
by jaa (Friar) on Apr 25, 2007 at 11:10 UTC | |
by bunnyman (Hermit) on Apr 25, 2007 at 13:53 UTC | |
by aufflick (Deacon) on Apr 27, 2007 at 00:39 UTC | |
|
Re: limiting the scope of bless
by belden (Friar) on Apr 27, 2007 at 00:32 UTC | |
by jaa (Friar) on May 01, 2007 at 13:49 UTC |