I recently stumbled across DBM::Deep, which is very cool in itself, but moments ago it occurred to me that this could easily make a nice arbitrary shared data storage for Template templates. Yes, I said shared. Unlike MLDBM, this can be used safely with multiple processes. It's like magic. And, it's a single Pure-perl PM file, so you can install it on shared hosting solutions for CGI stuff.

Beware: Template considers this to be a blessed object, you can't call normal hash or array vmethods. However, you can call the export method on any part of the tree to get a normal unassociated data structure, which can then be used with normal vmethods.


UPDATE: I've just uploaded Template::Plugin::DBM::Deep to get at all of this directly from Template, rather than having to create the structure externally. Woo hoo.
Perl:
use DBM::Deep; use Template; my $t = Template->new(); # create engine my $db = DBM::Deep->new( file => "foo.db", locking => 1, autoflush => 1, ); # create storage ... $t->process($your_template, { db => $db });
In the template:
[% db.foo = { fred => 3 barney => 2 }; # make permanent addition db.foo.fred; # get "3" %]

In reply to Permanent shared storage for Template Toolkit templates by merlyn

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.