in reply to Re: Embed a template in perl file
in thread Embed a template in perl file

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!

Replies are listed 'Best First'.
Re^3: Embed a template in perl file
by graff (Chancellor) on Jan 08, 2012 at 23:36 UTC
    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.

Re^3: Embed a template in perl file
by Anonymous Monk on Jan 09, 2012 at 09:51 UTC

    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;