Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Embed a template in perl file

by graff (Chancellor)
on Jan 07, 2012 at 04:28 UTC ( #946714=note: print w/ replies, xml ) Need Help??


in reply to Embed a template in perl file

I would like to "embed" them directly into the perl code.

And what sort of benefit do you expect to get from doing it this way? What is it about your existing setup (using a separate "templates" directory to store templates) that you think needs to be "fixed"? (How is it "broken" in your opinion?)


Comment on Re: Embed a template in perl file
Re^2: Embed a template in perl file
by whedglon (Initiate) on Jan 07, 2012 at 05:38 UTC
    Hi All, Thanks for the comments, I'll give those two options a shot.

    A bit more background: I release the application to users as a .exe file (using PAR::packer). My user base is less computer savvy and they tend to change the template files if they have access to them. The solution would be much cleaner (and safer) if I could "hide" the templates from users by wrapping them up into the perl file.

    Thanks again!

      Ah. So you want to be the benevolent dictator who stifles creative liberty in order to protect users from themselves -- you'd rather not allow them to make all those horrible mistakes that they certainly can't help making when they dare to presume that they can improve on your work and/or make your code more suitable to their individual needs... (I'm joking, of course, but only because your reasoning is kind of amusing.)

      UPDATE: Just one point to clarify my motivation in poking fun at your plan: In order to make modifications harder for end-users, it's normally true that you end up making it harder in general. If you feel that the benefit of centralized control will justify the cost of the added maintenance load, have at it.

      My user base is less computer savvy and they tend to change the template files if they have access to them.

      If they're smart enough to find the templates, I say they are computer savvy :D

      Any what

      #!/usr/bin/perl -- use strict; use warnings; use Data::Dump qw' pp '; use File::Slurp qw' read_file '; use autodie qw' chdir open '; chdir 'templates directory'; open my($fh), '>:raw', 'MahTemplates.pl'; select $fh; print '%templates = (', "\n"; for my $file ( glob '*.xml' ){ print dd( $file, scalar read_file( $file, { binmode => ':raw' } ) ), "\n"; } print "\n);\n"; close $fh;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://946714]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2014-09-19 17:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (143 votes), past polls