Template::Simple .04 and File::Slurp .16 are on cpan

Template::Simple .04 and File::Slurp .16 are on cpan

am 25.04.2011 10:12:16 von Uri Guttman

hi all,

normally i wouldn't announce module releases on the beginner's list but
i think this is appropriate.

i have released Template::Simple .04 to cpan. many times you see mention
of using templates to solve problems with replacing text with
values. there are many template modules and systems on cpan and it can
be hard to figure out which one to use. i have suggested
Template::Simple for several reasons:

* it is the simplest templater to learn and use
* it is the fastest rendering templater

the new release has a new cookbook script with many runnable examples
and documentation on how each one works. it also has compiled templates
which speeds up rendering. there is a benchmark script which compares
Template::Simple to Template::Teeny and the Template Toolkit.

the other module i have released to cpan is File::Slurp .16. this module
is a simple and fast way to read/write/modify entire files. we have seen
many newbies here who post code with poor calls to open (global handles,
no error checking, etc.). in many cases a single call to read_file will
do the job cleaner and faster. you can read the file into a scalar or
the lines into an array. there are other useful options too and other
subs. the newest one is also a commonly requested feature.
prepend_file() will write data to the beginning of a file.

finally, i am very proud of the code quality in those two modules. feel
free to look at them, ask me questions, flame the code, etc. i have no
issues with anything said about my code. if you find a bug or make a
useful request which i develop or use your code, i will credit you in
the Changes file (see that for all the recent changes and credits). my
personality is stable enough that i can handle critiques. i expect the
same from others but it seems that isn't always the case. a primary goal
of mine here and in my work is better code. you may not agree with my
code but i can always defend what i do with logic and experience. 35
years of coding with 18 years in perl lets me say that.

the modules do some very interesting things. one is a proper use of eval
string which i so violently shot down last week triggering the
interminable and useless recent flame war. in this case i am generating
perl code to render a template faster (the compiled template feature). i
even developed 2 other techniques which didn't use eval (see, i tried
NOT TO USE IT FIRST!!!). but the eval version was the fastest by a good
margin so it made its way into the module. it was chosen for that reason
and not by default. if you want template stuff, use a templater (see
above!) and not eval string. if i see it used again for such simple
stuff, i will again attempt to shoot it down as it is EVIL AND
DANGEROUS. i can use it since i know when not to use it. it is a last
resort solution, never the first choice. you can do anything with eval
string which doesn't mean you have to do everything with it.

have fun with the modules.

uri

--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: Template::Simple .04 and File::Slurp .16 are on cpan

am 25.04.2011 16:46:40 von Chap Harrison

On Apr 25, 2011, at 3:12 AM, Uri Guttman wrote:

> finally, i am very proud of the code quality in those two modules. =
feel
> free to look at them, ask me questions, flame the code, etc. i have no
> issues with anything said about my code.=20

I'm an "advanced beginner" and I'm embarrassed to say that, although =
I've read the Synopsis and Description in the module documentation, and =
searched perldoc, I can't figure out what a 'template' is or what its =
purpose is, in the context of Perl. =20

Also, the synopsis for Template::Simple included the following:

# this is data that will be used to render that template the keys
# are mapped to the chunk names (START & END markups) in the
# template the row is an array reference so multiple rows will be
# rendered usually the data tree is generated by code instead of
# being pure data.

Is this properly punctuated? I can't parse this sentence/paragraph.

I'm not saying that an introduction to templates belongs in the module =
documentation, but can you (or somebody else) tell me what, generically, =
a "Template" module is for?

Chap



--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: Template::Simple .04 and File::Slurp .16 are on cpan

am 25.04.2011 17:12:15 von Jim Gibson

At 9:46 AM -0500 4/25/11, Chap Harrison wrote:
>
>
>I'm not saying that an introduction to templates belongs in the
>module documentation, but can you (or somebody else) tell me what,
>generically, a "Template" module is for?

A Template is a method for generating files with dynamic content. In
this context, a template module takes a template file that has some
special formatting information in it and a set of data supplied by
the caller. The module reads the file and, using the suppled data,
replaces the special formatting with the data. For example, you could
generate a form letter with somebody's name and address using a
template. The special formatting information can be very simple, such
as simple variables, or more complex with conditionals and loops.

This is a common technique for generating web pages using data from a database.

Wikipedia is not much help here:


--
Jim Gibson
Jim@Gibson.org

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: Template::Simple .04 and File::Slurp .16 are on cpan

am 25.04.2011 17:59:46 von Uri Guttman

>>>>> "CH" == Chap Harrison writes:

CH> On Apr 25, 2011, at 3:12 AM, Uri Guttman wrote:
>> finally, i am very proud of the code quality in those two modules. feel
>> free to look at them, ask me questions, flame the code, etc. i have no
>> issues with anything said about my code.

CH> I'm an "advanced beginner" and I'm embarrassed to say that,
CH> although I've read the Synopsis and Description in the module
CH> documentation, and searched perldoc, I can't figure out what a
CH> 'template' is or what its purpose is, in the context of Perl.

the classic example of a template is a form letter. the body is the same
but you have a list of addresses, names, etc that you fill into spots to
generate each unique letter. many web pages and other documents are
built with templating. php is ALL templating but it embeds code inside
the templates (as some templating modules do).

CH> Also, the synopsis for Template::Simple included the following:

CH> # this is data that will be used to render that template the keys
CH> # are mapped to the chunk names (START & END markups) in the
CH> # template the row is an array reference so multiple rows will be
CH> # rendered usually the data tree is generated by code instead of
CH> # being pure data.

CH> Is this properly punctuated? I can't parse this
CH> sentence/paragraph.

yes, it is missing a period or more. read the extras/cookbook.pl for
many runnable examples which should help.


CH> I'm not saying that an introduction to templates belongs in the
CH> module documentation, but can you (or somebody else) tell me what,
CH> generically, a "Template" module is for?

web pages are the most popular use but templates can be used anytime you
need text with variations. in perl sprintf is effectively a template and
even a double quoted string with interpolated variables can be called a
template. the problem with a string is that you can't read the template
from an outside source as it is code and that required the evil string
eval (which i shot down when posted for a solution to that very
problem). another real world template is the boilerplate in contracts
and legal documents. they have the document written out and fill in all
the blank parts. it is a very common concept and well worth knowing how
to do it in perl.

i ran into needing them many years ago and slowly developed my own
module as it was simpler than anything i saw. it evolved from a single
line with an s/// call and a hash of keys/values to a 37 line sub that
did most of what i needed. later i created a proper module with OO,
tests, docs, etc. which is what i have and use now.

uri

--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: Template::Simple .04 and File::Slurp .16 are on cpan

am 25.04.2011 18:52:13 von Chap Harrison

On Apr 25, 2011, at 10:59 AM, Uri Guttman wrote:

> another real world template is the boilerplate in contracts
> and legal documents. they have the document written out and fill in =
all
> the blank parts. it is a very common concept and well worth knowing =
how
> to do it in perl.

I'm fully on board now - thanks. I've had occasion to generate dynamic =
web pages and have rolled my own crude templating methods, so I get the =
nature of the problem.

> read the extras/cookbook.pl for
> many runnable examples which should help.

Yes - much easier to read :-)

This will be very useful to me and I appreciate not only knowing about =
it, but having it as an example of high quality Perl as well.

Chap


--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: Template::Simple .04 and File::Slurp .16 are on cpan

am 25.04.2011 19:04:34 von Uri Guttman

>>>>> "CH" == Chap Harrison writes:

CH> On Apr 25, 2011, at 10:59 AM, Uri Guttman wrote:
>> another real world template is the boilerplate in contracts
>> and legal documents. they have the document written out and fill in all
>> the blank parts. it is a very common concept and well worth knowing how
>> to do it in perl.

CH> I'm fully on board now - thanks. I've had occasion to generate
CH> dynamic web pages and have rolled my own crude templating methods,
CH> so I get the nature of the problem.

that is the whole problem. simple templating is very simple. as i said,
a s/// and a hash does much of what most templating needs. but it grows
quickly when you want repeated sections or nesting and other
things. then a well designed template module is needed and you don't
want to reinvent them. i can reinvent things because i know my version
offers something different and maybe better. my experience tells me
that. when i see a newbie rolling their own module or writing crazy code
when good ones exist, that is a red flag.

>> read the extras/cookbook.pl for
>> many runnable examples which should help.

CH> Yes - much easier to read :-)

CH> This will be very useful to me and I appreciate not only knowing
CH> about it, but having it as an example of high quality Perl as
CH> well.

that is what i am here to do as well as yell about not using eval
string! :)

thanx,

uri

--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/