Sewi has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks,
I know that the following usage of Perl is not suggested and may cause trouble because things are not like they look. It's a very special usage case and I won't ever use this for new designs.
We're using a selfmade template module to load, modify and output templates:
my $template = Project::Template::load($filename); $template = Project::Template::replace($template, \%substitution_value +s);
I'ld like to allow template functions to be used on the template variable itself like
$template->replace(\%substitution_values);
for fewer typing and less error risks.
I know how to handle this on the sub/method side, but I can't replace $template (currently containing HTML source) by bless {}, __PACKAGE__ as some source parts still modify $template's contents in place.
MongoDB::OID is using a blessed scalar for it's self-generated IDs. It's a plain scalar when being print'ed but is blessed on MongoDB::OID when Dumper()ed or ref()ed.
MongoDB is using C for building these ID objects and I clearly don't like them because it took me hours until I noticed that they were blessed. My usage case is only being used by a small team of developers and it would be clearly documentated.
Is it possible to bless a scalar value using pure Perl? bless $string, __PACKAGE__; doesn't work (Can't bless a non-reference).
Thanks,
Sewi
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Bless a string
by moritz (Cardinal) on Dec 01, 2011 at 09:48 UTC | |
by Sewi (Friar) on Dec 01, 2011 at 11:29 UTC | |
by moritz (Cardinal) on Dec 01, 2011 at 12:57 UTC | |
by Eliya (Vicar) on Dec 01, 2011 at 12:49 UTC | |
|
Re: Bless a string
by roboticus (Chancellor) on Dec 01, 2011 at 11:42 UTC | |
|
Re: Bless a string
by pemungkah (Priest) on Dec 02, 2011 at 00:48 UTC |