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


In reply to Bless a string by Sewi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.