HTML-Template-Pro-0.9510/ 0000755 0000764 0000764 00000000000 12144122665 013360 5 ustar igor igor HTML-Template-Pro-0.9510/TODO 0000644 0000764 0000764 00000003566 11302530536 014055 0 ustar igor igor HTML-Template-Pro TODO.
=======================
1. A few wrappers for languages other then perl and mono
(php, java, maybe high-level C/glib and C++ wrappers)
to prove the API is designed good enough to fit a vast majority of languages.
2. query() support.
3. Parsing of variable contents as well,
allowing truly dynamic template generation.
Example:
$t->register_function( f1 => sub {
return $filename ? "" :
"some text"} );
Variants of proposed syntax:
This change will require the change of C library API.
It requires either callback for (add name/value pair to a current scope)
or built-in json-c or libjson
or both, as in case of assignments like
someVAR=someNativeLOOPorOBJECT.
something like scope
-2 for built-in json root
-1 for wrapper-dependent set root
0 for wrapper-dependent param root
Proscope: add is_scope_writeable flag.
5.
add Pro::Compat (Compat::Pro??)
1) Compat inherits most of its code from Pro
1) Compat is_a HTML::Template, HTML::Template::Expr.
2) use old param_to_lowercase
3) has default case_sensitive=0
4) has option html_template_strict_mode=1 (enables use of perl _find_file);
6.
add option
expr: logical should return one of args
7. C htmltmplpro C API:
add interface call
ABSTRACT_MAP* get_root_scope (param, int POS);
FLAGS can be user-provided SET scope, main root scope, case_transform flags etc.
8. Rewrite documentation - split C API documentation or merge perl and C docs.
Find a place to document template_root hack.
10. rewrite scanner using re2c
HTML-Template-Pro-0.9510/pstring.h 0000644 0000764 0000764 00000003040 11251467341 015215 0 ustar igor igor /*! \file pstring.h
* \brief string type.
*
* \author Igor Vlasenko
* \warning This header file should never be included directly.
* Include instead.
*/
#ifndef _PSTRING_H
#define _PSTRING_H 1
/** \struct PSTRING
\brief string type used in htmltmplpro.
\code
typedef struct PSTRING {
const char* begin;
const char* endnext;
} PSTRING;
\endcode
The string is delimited by two pointers, begin and endnext.
The length of the string is calculated as endnext - begin.
The empty string has begin == endnext.
\warning It is possible for empty string to have begin == endnext == NULL.
\warning Contents of the memory area, passed as PSTRING, should always be treated as const.
\warning Contents of the memory area, passed as PSTRING, can be destroyed after the callback function
completed. To be used afterwards the string content should be copied.
*/
typedef struct PSTRING {
const char* begin; /*!< pointer to begin of the string. */
const char* endnext; /*!< pointer to the byte next to the last char of the string. */
} PSTRING;
/** \struct MPSTRING
\brief Modifiable PSTRING.
\code
typedef struct MPSTRING {
char* begin;
char* endnext;
} PSTRING;
\endcode
The same as PSTING, but in non-constant memory.
*/
typedef struct MPSTRING {
char* begin; /*!< pointer to begin of the string. */
char* endnext; /*!< pointer to the byte next to the last char of the string. */
} MPSTRING;
#endif /* pstring.h */
HTML-Template-Pro-0.9510/pabidecl.h 0000644 0000764 0000764 00000002562 11237574706 015312 0 ustar igor igor /*! \file pabidecl.h
\brief calling conventions.
* APICALL and BACKCALL can be something like __stdcall or __cdecl (compiler-specific).
* APICALL set the calling convention for exported symbols.
* BACKCALL set the calling convention for callback pointers.
* By default, the code uses C standard (Cdecl) calling conventions.
* One can override the calling conventions by defining their own
* APICALL and BACKCALL macro.
*/
#ifndef _PABIDECL_H
#define _PABIDECL_H 1
#ifdef __cplusplus
#define TMPLPRO_EXTERN_C extern "C"
#else
#define TMPLPRO_EXTERN_C
#endif
#if defined( __WIN32__ ) || defined( _WIN32 ) || defined __CYGWIN__
# define TMPLPRO_HIDDEN_SYM
# if defined(HTMLTMPLPRO_STATIC)
# define TMPLPRO_EXPORT_SYM
# else
# if defined( htmltmplpro_EXPORTS ) || defined (DLL_EXPORT)
# define TMPLPRO_EXPORT_SYM __declspec(dllexport)
# else
# define TMPLPRO_EXPORT_SYM __declspec(dllimport)
# endif
# endif
#elif __GNUC__ >= 4
# define TMPLPRO_EXPORT_SYM __attribute__ ((visibility("default")))
# define TMPLPRO_HIDDEN_SYM __attribute__ ((visibility("hidden")))
#else
# define TMPLPRO_EXPORT_SYM
# define TMPLPRO_HIDDEN_SYM
#endif
#ifndef APICALL
#define APICALL
#endif
#ifndef BACKCALL
#define BACKCALL
#endif
#define TMPLPRO_API TMPLPRO_EXTERN_C TMPLPRO_EXPORT_SYM
#define API_IMPL TMPLPRO_EXPORT_SYM
#define TMPLPRO_LOCAL TMPLPRO_HIDDEN_SYM
#endif /* pabidecl.h */
HTML-Template-Pro-0.9510/ARTISTIC 0000644 0000764 0000764 00000013737 10724553105 014537 0 ustar igor igor
The "Artistic License"
Preamble
The intent of this document is to state the conditions under which a
Package may be copied, such that the Copyright Holder maintains some
semblance of artistic control over the development of the package,
while giving the users of the package the right to use and distribute
the Package in a more-or-less customary fashion, plus the right to make
reasonable modifications.
Definitions:
"Package" refers to the collection of files distributed by the
Copyright Holder, and derivatives of that collection of files
created through textual modification.
"Standard Version" refers to such a Package if it has not been
modified, or has been modified in accordance with the wishes
of the Copyright Holder as specified below.
"Copyright Holder" is whoever is named in the copyright or
copyrights for the package.
"You" is you, if you're thinking about copying or distributing
this Package.
"Reasonable copying fee" is whatever you can justify on the
basis of media cost, duplication charges, time of people involved,
and so on. (You will not be required to justify it to the
Copyright Holder, but only to the computing community at large
as a market that must bear the fee.)
"Freely Available" means that no fee is charged for the item
itself, though there may be fees involved in handling the item.
It also means that recipients of the item may redistribute it
under the same conditions they received it.
1. You may make and give away verbatim copies of the source form of the
Standard Version of this Package without restriction, provided that you
duplicate all of the original copyright notices and associated disclaimers.
2. You may apply bug fixes, portability fixes and other modifications
derived from the Public Domain or from the Copyright Holder. A Package
modified in such a way shall still be considered the Standard Version.
3. You may otherwise modify your copy of this Package in any way, provided
that you insert a prominent notice in each changed file stating how and
when you changed that file, and provided that you do at least ONE of the
following:
a) place your modifications in the Public Domain or otherwise make them
Freely Available, such as by posting said modifications to Usenet or
an equivalent medium, or placing the modifications on a major archive
site such as uunet.uu.net, or by allowing the Copyright Holder to include
your modifications in the Standard Version of the Package.
b) use the modified Package only within your corporation or organization.
c) rename any non-standard executables so the names do not conflict
with standard executables, which must also be provided, and provide
a separate manual page for each non-standard executable that clearly
documents how it differs from the Standard Version.
d) make other distribution arrangements with the Copyright Holder.
4. You may distribute the programs of this Package in object code or
executable form, provided that you do at least ONE of the following:
a) distribute a Standard Version of the executables and library files,
together with instructions (in the manual page or equivalent) on where
to get the Standard Version.
b) accompany the distribution with the machine-readable source of
the Package with your modifications.
c) give non-standard executables non-standard names, and clearly
document the differences in manual pages (or equivalent), together
with instructions on where to get the Standard Version.
d) make other distribution arrangements with the Copyright Holder.
5. You may charge a reasonable copying fee for any distribution of this
Package. You may charge any fee you choose for support of this
Package. You may not charge a fee for this Package itself. However,
you may distribute this Package in aggregate with other (possibly
commercial) programs as part of a larger (possibly commercial) software
distribution provided that you do not advertise this Package as a
product of your own. You may embed this Package's interpreter within
an executable of yours (by linking); this shall be construed as a mere
form of aggregation, provided that the complete Standard Version of the
interpreter is so embedded.
6. The scripts and library files supplied as input to or produced as
output from the programs of this Package do not automatically fall
under the copyright of this Package, but belong to whoever generated
them, and may be sold commercially, and may be aggregated with this
Package. If such scripts or library files are aggregated with this
Package via the so-called "undump" or "unexec" methods of producing a
binary executable image, then distribution of such an image shall
neither be construed as a distribution of this Package nor shall it
fall under the restrictions of Paragraphs 3 and 4, provided that you do
not represent such an executable image as a Standard Version of this
Package.
7. C subroutines (or comparably compiled subroutines in other
languages) supplied by you and linked into this Package in order to
emulate subroutines and variables of the language defined by this
Package shall not be considered part of this Package, but are the
equivalent of input as in Paragraph 6, provided these subroutines do
not change the language in any way that would cause it to fail the
regression tests for the language.
8. Aggregation of this Package with a commercial distribution is always
permitted provided that the use of this Package is embedded; that is,
when no overt attempt is made to make this Package's interfaces visible
to the end user of the commercial distribution. Such use shall not be
construed as a distribution of this Package.
9. The name of the Copyright Holder may not be used to endorse or promote
products derived from this software without specific prior written permission.
10. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
The End
HTML-Template-Pro-0.9510/builtin_findfile.inc 0000644 0000764 0000764 00000032152 11436234014 017357 0 ustar igor igor /*
* File: builtin_findfile.c
* Author: Igor Vlasenko
* Created: Tue Jul 14 22:47:11 2009
*/
#include /* for isalpha */
#include /* for getenv */
/* TODO: support CYGWIN
* see
* http://sourceware.org/autobook/autobook/autobook_249.html
*/
#if defined __CYGWIN32__ && !defined __CYGWIN__
/* For backwards compatibility with Cygwin b19 and
earlier, we define __CYGWIN__ here, so that
we can rely on checking just for that macro. */
# define __CYGWIN__ __CYGWIN32__
#endif
#if defined _WIN32 && !defined __CYGWIN__
/* Use Windows separators on all _WIN32 defining
environments, except Cygwin. */
# define DIR_SEPARATOR_CHAR '\\'
#endif
#if defined (DIR_SEPARATOR_CHAR)
# define IS_FILE_SEP(X) ((X=='/') || (X==DIR_SEPARATOR_CHAR))
#else
# define IS_FILE_SEP(X) (X=='/')
#endif
static int _ff_exists(const char* path) {
FILE *file_p = fopen(path, "r");
if (file_p) {
fclose(file_p);
if (debuglevel>=TMPL_LOG_DEBUG2) tmpl_log(TMPL_LOG_DEBUG2,"_ff_exists: found [%s]\n",path);
return 1;
}
if (debuglevel>=TMPL_LOG_DEBUG2) tmpl_log(TMPL_LOG_ERROR,"_ff_exists: not found [%s]\n",path);
return 0;
}
/* lame dirname implementation */
static PSTRING _ff_dirname(const char* path) {
PSTRING retval={(char*)path,(char*)path};
char c=0;
if (path!=NULL) retval.endnext += strlen(path);
else return retval;
while (retval.endnext > retval.begin && (c=*(--retval.endnext)) && ! IS_FILE_SEP(c));
/*fprintf(stderr,"built-in _ff_dirname: dir = %.*s\n",(int)(retval.endnext-retval.begin),retval.begin);*/
return retval;
}
/*
Windows Relative Paths
For functions that manipulate files, the file names can be relative to the current directory. A file name is relative to the current directory if it does not begin with one of the following:
* A UNC name of any format.
* A disk designator with a backslash, for example "C:\".
* A backslash, for example, "\directory").
*/
/* remember about \\?\ and \\?\UNC\ prefixes on WIN platform.
* see "File Names, Paths, and Namespaces"
* http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx
*/
int _ff_is_absolute(const char * filename) {
unsigned char c0 = *filename;
#if defined _WIN32 || defined __CYGWIN__
unsigned char c1;
unsigned char c2;
#endif
if ('\0' == c0) return 0;
/* \\?\ and \\?\UNC\ prefixes are included too */
if (IS_FILE_SEP(c0)) return 1;
#if defined _WIN32 || defined __CYGWIN__
c1 = *(++filename);
if ('\0' == c1) return 0;
c2 = *(++filename);
if (isalpha(c0) && ':'==c1 && IS_FILE_SEP(c2)) return 1;
#endif
return 0;
}
#if defined _WIN32 || defined __CYGWIN__
int _ff_is_win_fully_qualified_path(const char * filename) {
unsigned char c0 = *filename;
unsigned char c1;
unsigned char c2;
if ('\0' == c0) return 0;
c1 = *(++filename);
if ('\0' == c1) return 0;
c2 = *(++filename);
/* \\?\ and \\?\UNC\ prefixes are included too */
if (isalpha(c0) && ':'==c1 && IS_FILE_SEP(c2)) return 1;
if ('\\'==c0 && '\\'==c1 && '?'==c2 && '\\'==*filename) return 1;
return 0;
}
#endif
#define _ff_canonical_path(X) (X)
static MPSTRING _shift_back_pstring_at(MPSTRING buf, char* pos, long shift) {
if (pos >= buf.begin && (pos+shift) <=buf.endnext) {
buf.endnext -= shift;
while (pos1) && ('\\'==*pos && '\\'==*(pos+1))) pos += 2;
#endif
while (pos1) && isalpha((unsigned char) *pos) && ':'==*(pos+1)) {
pos += 2;
slash_begin += 2;
}
#endif
prev_slash_next = slash_begin;
while (pos leave one slash */
buf=_shift_back_pstring_at(buf, prev_slash_next, pos-prev_slash_next+3);
pos=prev_slash_next-1;/* 1 to compensate pos++ */
} else {
buf=_shift_back_pstring_at(buf, prev_slash_next, pos-prev_slash_next+4);
pos=prev_slash_next-2;/* 2 to compensate / and pos++ */
/* 2 to step back slashnext char and 'slash' char, if any */
if (prev_slash_next>slash_begin) prev_slash_next--;
if (prev_slash_next>slash_begin) prev_slash_next--;
}
/* old prev_slash_next now current, so we need to recalculate it */
/* first find a 'slash' char */
while (prev_slash_next>=slash_begin && !IS_FILE_SEP(*prev_slash_next)) prev_slash_next--;
if (prev_slash_next>slash_begin) prev_slash_next++;/* step next to slash */
} else {
prev_slash_next=pos+1;
}
}
pos++;
}
/* // <-- shift -1 */
buf=_filepath_remove_multiple_slashes(buf);
/* offset 0: if ./ shift -2 */
if ((buf.endnext-buf.begin)<2) return buf.begin;
pos = buf.begin;
if (('.'==*pos) && IS_FILE_SEP(*(pos+1))) buf=_shift_back_pstring_at(buf, pos, 2);
return buf.begin;
}
static MPSTRING _ff_add_pstr_to_buffer(MPSTRING buf, PSTRING pstr) {
MPSTRING ret = buf;
const char* s;
//tmpl_log(TMPL_LOG_ERROR,"_ff_add_pstr_to_buffer: called as [%p,%p]+[%p,%p]\n",buf.begin,buf.endnext, pstr.begin,pstr.endnext);
for (s=pstr.begin;sret.begin && IS_FILE_SEP(*(ret.endnext-1))) return ret;
#ifdef DIR_SEPARATOR_CHAR
*(ret.endnext++)=DIR_SEPARATOR_CHAR;
#else
*(ret.endnext++)='/';
#endif
return ret;
}
static MPSTRING _ff_add_0_to_buffer(MPSTRING buf) {
*(buf.endnext++)='\0';
return buf;
}
static const char* get_template_root(struct tmplpro_param* param) {
const char* retval = param->template_root;
if (NULL==retval) retval = getenv("HTML_TEMPLATE_ROOT");
return retval;
}
static const char* _find_file (struct tmplpro_param* param, const char* filename, PSTRING extra_dir) {
// TODO: finish it
const char* HTML_TEMPLATE_ROOT = get_template_root(param);
size_t HTML_TEMPLATE_ROOT_length=0;
size_t buffsize=0;
char** pathlist=param->path;
MPSTRING pbuf_begin, filepath;
if (param->debug >= TMPL_LOG_DEBUG2) {
tmpl_log(TMPL_LOG_DEBUG2,"built-in _find_file: looking for %s extra dir = %.*s\n",filename, (int)(extra_dir.endnext-extra_dir.begin),extra_dir.begin);
if (HTML_TEMPLATE_ROOT) tmpl_log(TMPL_LOG_DEBUG2,"built-in _find_file: HTML_TEMPLATE_ROOT = %s\n",HTML_TEMPLATE_ROOT);
}
/* first check for a full path */
if (_ff_is_absolute(filename) && _ff_exists(filename)) return _ff_canonical_path(filename);
#if defined _WIN32 || defined __CYGWIN__
/* no sense of prefixing C:\ or \\?\ */
if (_ff_is_win_fully_qualified_path(filename)) {
tmpl_log(TMPL_LOG_DEBUG2,"built-in _ff_is_win_fully_qualified_path: rejected %s: is_absolute=%d exists=%d\n",filename,_ff_is_absolute(filename),_ff_exists(filename));
return NULL;
}
#endif
if (HTML_TEMPLATE_ROOT!=NULL) HTML_TEMPLATE_ROOT_length=strlen(HTML_TEMPLATE_ROOT);
if (pathlist!=NULL) {
while (NULL!=*pathlist) {
size_t pathentrylen=strlen(*pathlist);
if (buffsizebuiltin_findfile_buffer, buffsize);
pbuf_begin.begin=pbuffer_string(¶m->builtin_findfile_buffer);
pbuf_begin.endnext=pbuf_begin.begin;
/* try the extra_path if one was specified */
if (extra_dir.begin!=NULL) {
filepath=_ff_add_pstr_to_buffer(pbuf_begin,extra_dir);
if (extra_dir.endnext-extra_dir.begin >0)
filepath=_ff_add_sep_to_buffer(filepath);
filepath=_ff_add_str_to_buffer(filepath,filename);
filepath=_ff_add_0_to_buffer(filepath);
if (_ff_exists(filepath.begin)) return _ff_canonical_path_from_buf(filepath);
}
/* try pre-prending HTML_Template_Root */
if (HTML_TEMPLATE_ROOT!=NULL) {
filepath=_ff_add_str_to_buffer(pbuf_begin,HTML_TEMPLATE_ROOT);
if (HTML_TEMPLATE_ROOT_length >0)
filepath=_ff_add_sep_to_buffer(filepath);
filepath=_ff_add_str_to_buffer(filepath,filename);
filepath=_ff_add_0_to_buffer(filepath);
if (_ff_exists(filepath.begin)) return _ff_canonical_path_from_buf(filepath);
}
/* try "path" option list.. */
pathlist=param->path;
if (pathlist!=NULL) {
while (NULL!=*pathlist) {
//tmpl_log(TMPL_LOG_ERROR,"try 'path' option list..: looking in [%s]\n",*pathlist);
filepath=_ff_add_str_to_buffer(pbuf_begin,*pathlist);
/* add separator only if *pathlist non-empty */
if (0!=**pathlist) filepath=_ff_add_sep_to_buffer(filepath);
filepath=_ff_add_str_to_buffer(filepath,filename);
filepath=_ff_add_0_to_buffer(filepath);
if (_ff_exists(filepath.begin)) return _ff_canonical_path_from_buf(filepath);
pathlist++;
}
}
/* try even a relative path from the current directory...*/
if (_ff_exists(filename)) return _ff_canonical_path(filename);
/* try "path" option list with HTML_TEMPLATE_ROOT prepended... */
if (HTML_TEMPLATE_ROOT!=NULL) {
pathlist=param->path;
if (pathlist!=NULL) {
while (NULL!=*pathlist) {
filepath=_ff_add_str_to_buffer(pbuf_begin,HTML_TEMPLATE_ROOT);
if (HTML_TEMPLATE_ROOT_length >0)
filepath=_ff_add_sep_to_buffer(filepath);
filepath=_ff_add_str_to_buffer(filepath,*pathlist);
/* add separator only if *pathlist non-empty */
if (0!=**pathlist) filepath=_ff_add_sep_to_buffer(filepath);
filepath=_ff_add_str_to_buffer(filepath,filename);
filepath=_ff_add_0_to_buffer(filepath);
if (_ff_exists(filepath.begin)) return _ff_canonical_path_from_buf(filepath);
pathlist++;
}
}
}
return NULL;
}
static const char* BACKCALL stub_find_file_func(ABSTRACT_FINDFILE* param,const char* filename, const char* last_visited_file) {
const char* filepath;
PSTRING extra_path ={NULL,NULL};
if (filename == last_visited_file) tmpl_log(TMPL_LOG_ERROR,"built-in find_file: internal error: buffer clash for %s\n",filename);
if (((struct tmplpro_param*)param)->debug>= TMPL_LOG_DEBUG)
tmpl_log(TMPL_LOG_DEBUG,"built-in find_file: looking for %s last_visited_file = %s\n",filename, last_visited_file);
// look for the included file...
if (last_visited_file!=NULL && ! ((struct tmplpro_param*) param)->search_path_on_include) {
extra_path = _ff_dirname(last_visited_file);
}
filepath = _find_file((struct tmplpro_param*)param,filename,extra_path);
if (filepath==NULL) {
char** path=((struct tmplpro_param*)param)->path;
const char* HTML_TEMPLATE_ROOT = get_template_root((struct tmplpro_param*)param);
tmpl_log(TMPL_LOG_ERROR,"built-in find_file: can't find file %s", filename);
if (NULL!=last_visited_file) tmpl_log(TMPL_LOG_ERROR," (included from %s)", last_visited_file);
if(HTML_TEMPLATE_ROOT!=NULL) {
tmpl_log(TMPL_LOG_ERROR," with HTML_TEMPLATE_ROOT = '%s'",HTML_TEMPLATE_ROOT);
}
if (NULL!=path) {
tmpl_log(TMPL_LOG_ERROR," with path = [");
while (NULL!=*path) {
tmpl_log(TMPL_LOG_ERROR," '%s'",*path);
path++;
}
tmpl_log(TMPL_LOG_ERROR," ]");
} else {
tmpl_log(TMPL_LOG_ERROR," with empty path list");
}
tmpl_log(TMPL_LOG_ERROR,"\n");
return NULL;
} else {
return filepath;
}
}
/*
* Local Variables:
* mode: c
* End:
*/
HTML-Template-Pro-0.9510/pstrutils.h 0000644 0000764 0000764 00000000731 11245553124 015602 0 ustar igor igor /* -*- c -*-
* File: pstring.h
* Author: Igor Vlasenko
* Created: Fri Jul 1 20:11:51 2005
*
* $Id$
*/
#ifndef _PSTRUTILS_H
#define _PSTRUTILS_H 1
#include "pbuffer.h"
static
PSTRING lowercase_pstring (pbuffer*, PSTRING);
static
int is_pstring_true (PSTRING s);
static
PSTRING escape_pstring (pbuffer* StrBuffer, PSTRING pstring, int escapeopt);
/*
static
void lowercase_pstring_inplace (PSTRING pstring);
*/
#endif /* pstrutils.h */
HTML-Template-Pro-0.9510/pabstract.h 0000644 0000764 0000764 00000044256 11255623456 015535 0 ustar igor igor /*! \file pabstract.h
\brief description of callbacks.
In order to interact with core library a wrapper should provide
some callback functions.
This file specifies which callbacks can be provided.
\author Igor Vlasenko
\warning This header file should never be included directly.
Include instead.
*/
#ifndef _PROABSTRACT_H
#define _PROABSTRACT_H 1
#include "pstring.h"
#include "pabidecl.h"
struct tmplpro_param;
struct exprval;
typedef void ABSTRACT_WRITER;
typedef void ABSTRACT_FINDFILE;
typedef void ABSTRACT_FILTER;
typedef void ABSTRACT_CALLER;
typedef void ABSTRACT_DATASTATE;
typedef void ABSTRACT_ARRAY;
typedef void ABSTRACT_MAP;
typedef void ABSTRACT_VALUE;
typedef void ABSTRACT_FUNCMAP;
typedef void ABSTRACT_ARGLIST;
typedef void ABSTRACT_USERFUNC;
typedef struct exprval ABSTRACT_EXPRVAL;
typedef void BACKCALL (*writer_functype) (ABSTRACT_WRITER*,const char* begin, const char* endnext);
typedef ABSTRACT_VALUE* BACKCALL (*get_ABSTRACT_VALUE_functype) (ABSTRACT_DATASTATE*, ABSTRACT_MAP*, PSTRING name);
typedef PSTRING BACKCALL (*ABSTRACT_VALUE2PSTRING_functype) (ABSTRACT_DATASTATE*, ABSTRACT_VALUE*);
/* optional */
typedef int BACKCALL (*is_ABSTRACT_VALUE_true_functype) (ABSTRACT_DATASTATE*, ABSTRACT_VALUE*);
typedef ABSTRACT_ARRAY* BACKCALL (*ABSTRACT_VALUE2ABSTRACT_ARRAY_functype) (ABSTRACT_DATASTATE*, ABSTRACT_VALUE*);
typedef int BACKCALL (*get_ABSTRACT_ARRAY_length_functype) (ABSTRACT_DATASTATE*, ABSTRACT_ARRAY*);
typedef ABSTRACT_MAP* BACKCALL (*get_ABSTRACT_MAP_functype) (ABSTRACT_DATASTATE*, ABSTRACT_ARRAY*,int);
/* optional notifier */
typedef void BACKCALL (*exit_loop_scope_functype) (ABSTRACT_DATASTATE*, ABSTRACT_ARRAY*);
typedef const char* BACKCALL (*find_file_functype) (ABSTRACT_FINDFILE*, const char* filename, const char* prevfilename);
/* optional; we can use wrapper to load file and apply its filters before running itself */
/* note that this function should allocate region 1 byte nore than the file size */
typedef PSTRING BACKCALL (*load_file_functype) (ABSTRACT_FILTER*, const char* filename);
typedef int BACKCALL (*unload_file_functype) (ABSTRACT_FILTER*, PSTRING memarea);
/* -------- Expr extension------------ */
/* those are needed for EXPR= extension */
typedef ABSTRACT_USERFUNC* BACKCALL (*is_expr_userfnc_functype) (ABSTRACT_FUNCMAP*, PSTRING name);
typedef ABSTRACT_ARGLIST* BACKCALL (*init_expr_arglist_functype) (ABSTRACT_CALLER*);
typedef void BACKCALL (*push_expr_arglist_functype) (ABSTRACT_ARGLIST*, ABSTRACT_EXPRVAL*);
typedef void BACKCALL (*free_expr_arglist_functype) (ABSTRACT_ARGLIST*);
typedef void BACKCALL (*call_expr_userfnc_functype) (ABSTRACT_CALLER*, ABSTRACT_ARGLIST*, ABSTRACT_USERFUNC*, ABSTRACT_EXPRVAL* return_value);
/* ------- end Expr extension -------- */
#endif /* _PROABSTRACT_H */
/** \typedef typedef void (*writer_functype) (ABSTRACT_WRITER*,const char* begin, const char* endnext);
\brief optional callback for writing or accumulating a piece of generated text.
\param begin, endnext - pointers to memory area containing the output string.
\param ABSTRACT_WRITER* - pointer stored by tmplpro_set_option_ext_writer_state() or NULL if nothing was stored.
Note that outpot string is NOT 0-terminated. Instead, 2 pointers are used, as in PSTRING.
This callback is called multiple times.
This callback is optional: if not provided, a built-in stub will output to STDOUT.
@see tmplpro_set_option_WriterFuncPtr
@see tmplpro_set_option_ext_writer_state
*/
/** \typedef typedef ABSTRACT_VALUE* (*get_ABSTRACT_VALUE_functype) (ABSTRACT_MAP*, PSTRING name);
\brief required callback to get a variable value.
\param PSTRING name - a name as in <TMPL_VAR NAME="var1">
\param ABSTRACT_MAP* pointer returned by callback of get_ABSTRACT_MAP_functype.
\return NULL if NAME not found or a non-null pointer to be passed to callback
of ABSTRACT_VALUE2PSTRING_functype or ABSTRACT_VALUE2ABSTRACT_ARRAY_functype.
@see tmplpro_set_option_GetAbstractValFuncPtr
*/
/** \typedef typedef PSTRING (*ABSTRACT_VALUE2PSTRING_functype) (ABSTRACT_VALUE*);
\brief required callback to transform into PSTRING a variable name passed to callback of get_ABSTRACT_VALUE_functype.
\param ABSTRACT_VALUE* optional pointer returned by callback of get_ABSTRACT_VALUE_functype.
\return PSTRING to a memory area. The memery area can be safely freed in the next call
to ABSTRACT_VALUE2PSTRING_functype.
@see tmplpro_set_option_AbstractVal2pstringFuncPtr
*/
/** \typedef typedef int (*is_ABSTRACT_VALUE_true_functype) (ABSTRACT_VALUE*);
\brief optional callback to fine-tune is ABSTRACT_VALUE* is true or false.
\param ABSTRACT_VALUE* optional pointer returned by callback of get_ABSTRACT_VALUE_functype.
\return 0(false) or 1(true).
By default a stub is used that guesses true or false according to PSTRING form of ABSTRACT_VALUE.
@see tmplpro_set_option_IsAbstractValTrueFuncPtr
*/
/** \typedef typedef ABSTRACT_ARRAY* (*ABSTRACT_VALUE2ABSTRACT_ARRAY_functype) (ABSTRACT_VALUE*);
\brief required callback to transform into ABSTRACT_ARRAY a variable name passed to callback of get_ABSTRACT_VALUE_functype.
\param ABSTRACT_VALUE* optional pointer returned by callback of get_ABSTRACT_VALUE_functype.
\return NULL if NAME can not be converted to ABSTRACT_ARRAY or a non-null pointer that will be passed
then to callbacks of get_ABSTRACT_ARRAY_length_functype and get_ABSTRACT_MAP_functype.
@see tmplpro_set_option_AbstractVal2abstractArrayFuncPtr
*/
/** \typedef typedef int (*get_ABSTRACT_ARRAY_length_functype) (ABSTRACT_ARRAY*);
\brief optional callback to specify a length of the loop.
\param ABSTRACT_ARRAY* optional pointer returned by callback of ABSTRACT_VALUE2ABSTRACT_ARRAY_functype.
\return the length of the loop or a special value of -1 that indicates that loop has an undefined length
(useful when one need to iterate over large number of records in database or lines in a file).
By default a stub is used that returns -1.
@see tmplpro_set_option_GetAbstractArrayLengthFuncPtr
*/
/** \typedef typedef ABSTRACT_MAP* (*get_ABSTRACT_MAP_functype) (ABSTRACT_ARRAY*,int n);
\brief required callback to transform into ABSTRACT_ARRAY a variable name passed to callback of get_ABSTRACT_VALUE_functype.
\param ABSTRACT_ARRAY* optional pointer returned by callback of ABSTRACT_VALUE2ABSTRACT_ARRAY_functype.
\param n - number of current loop iteration.
\return NULL if loop can no nore be iterated or a non-null pointer that will be passed
to callback of get_ABSTRACT_VALUE_functype.
@see tmplpro_set_option_GetAbstractMapFuncPtr
*/
/** \typedef typedef void (*end_loop_functype) (ABSTRACT_MAP* root_param_map, int newlevel);
\brief optional callback to notify a front-end that the current loop is exited.
\param ABSTRACT_MAP* optional pointer stored by tmplpro_set_option_root_param_map().
\param newlevel current depth of nested loops (0 means a root scope).
This callback is useful for front-end implementations which does not return pointers
to real objects. In that case the corresponding ABSTRACT_MAP*, ABSTRACT_ARRAY*, and ABSTRACT_VALUE*
pointers are fake non-null values, so instead of those pointers this callback can be used.
@see tmplpro_set_option_EndLoopFuncPtr
*/
/** \typedef typedef void (*select_loop_scope_functype) (ABSTRACT_MAP* root_param_map, int level);
\brief optional callback to select a loop.
\param ABSTRACT_MAP* optional pointer stored by tmplpro_set_option_root_param_map().
\param int level level at which a loop will be selected.
This callback is useful for front-end implementations which does not return pointers
to real objects. In that case the corresponding ABSTRACT_MAP*, ABSTRACT_ARRAY*, and ABSTRACT_VALUE*
pointers are fake non-null values, so instead of those pointers this callback can be used.
@see tmplpro_set_option_SelectLoopScopeFuncPtr
*/
/** \typedef typedef const char* (*find_file_functype) (ABSTRACT_FINDFILE*, const char* filename, const char* prevfilename);
\brief optional callback to fine-tune the algorythm of finding template file by name.
\param ABSTRACT_FINDFILE* optional pointer stored by tmplpro_set_option_ext_writer_state().
\param filename file to be found.
\param prevfilename fully qualified path to containing file, if any.
\return fully qualified path to a file to be loaded.
By default a stub is used (as of 0.82, with limited functionality).
@see tmplpro_set_option_FindFileFuncPtr
*/
/** \typedef typedef PSTRING (*load_file_functype) (ABSTRACT_FILTER*, const char* filename);
\brief optional callback to load and preprocess (filter) files.
Only called if filters option is true (set by tmplpro_set_option_filters() ).
\param ABSTRACT_FILTER* optional pointer stored by tmplpro_set_option_ext_filter_state().
\param filename fully qualified path to a file to be loaded
(as returned by callback of find_file_functype).
\return PSTRING of memory area loaded.
@see tmplpro_set_option_filters
@see tmplpro_set_option_LoadFileFuncPtr
*/
/** \typedef typedef int (*unload_file_functype) (ABSTRACT_FILTER*, PSTRING memarea);
\brief optional callback to free memory accuired by a callback of load_file_functype.
Only called if filters option is true (set by tmplpro_set_option_filters() ).
\param ABSTRACT_FILTER* optional pointer stored by tmplpro_set_option_ext_filter_state().
\param memarea pointers to loaded area
(as returned by callback of load_file_functype).
\return 0 on success, non-zero otherwise.
@see tmplpro_set_option_filters
@see tmplpro_set_option_UnloadFileFuncPtr
*/
/** \typedef typedef ABSTRACT_USERFUNC* (*is_expr_userfnc_functype) (ABSTRACT_FUNCMAP*, PSTRING name);
\brief optional callback for support of user-provided functions.
\param ABSTRACT_FUNCMAP* optional pointer stored by tmplpro_set_option_expr_func_map().
\param name name of function
\return NULL if there is no user function with such a name or non-null value to be passed
to callback of call_expr_userfnc_functype.
\warning if is_expr_userfnc_functype callback is set, then callbacks of
init_expr_arglist_functype, push_expr_arglist_functype, free_expr_arglist_functype
and call_expr_userfnc_functype also should be set.
@see tmplpro_set_option_IsExprUserfncFuncPtr
*/
/** \typedef typedef ABSTRACT_ARGLIST* (*init_expr_arglist_functype) (ABSTRACT_CALLER*);
\brief optional callback to initialize the list of arguments for a user-provided function.
Note that if function calls are nested, then the calls to a callbacks of
::init_expr_arglist_functype, ::push_expr_arglist_functype, ::free_expr_arglist_functype
will also be nested.
\param ABSTRACT_CALLER* optional pointer stored by tmplpro_set_option_ext_calluserfunc_state().
\return value to be passed to callbacks of push_expr_arglist_functype,
free_expr_arglist_functype and call_expr_userfnc_functype.
@see tmplpro_set_option_InitExprArglistFuncPtr
*/
/** \typedef typedef void (*free_expr_arglist_functype) (ABSTRACT_ARGLIST*);
\brief optional callback to release the list of arguments for a user-provided function.
Note that if function calls are nested, then the calls to a callbacks of
::init_expr_arglist_functype, ::push_expr_arglist_functype, ::free_expr_arglist_functype
will also be nested.
\param ABSTRACT_ARGLIST* optional pointer returned by callback of init_expr_arglist_functype.
@see tmplpro_set_option_FreeExprArglistFuncPtr
*/
/** \typedef typedef void (*push_expr_arglist_functype) (ABSTRACT_ARGLIST*, ABSTRACT_EXPRVAL*);
\brief optional callback to add new value to the list of arguments for a user-provided function.
Note that if function calls are nested, then the calls to a callbacks of
::init_expr_arglist_functype, ::push_expr_arglist_functype, ::free_expr_arglist_functype
will also be nested.
\param ABSTRACT_ARGLIST* optional pointer returned by callback of init_expr_arglist_functype.
\param ABSTRACT_EXPRVAL* pointer required by tmplpro_get_expr_* functions to retrieve the value
(a place the pushed value is stored).
A value to be added to the list of arguments for a user-provided function is not passed
as argument to a callback of push_expr_arglist_functype. Instead, a pointer to
struct tmplpro_param is passed, and the callback function should discover the value's type
using tmplpro_get_expr_type() function, and then should retrieve the value
using one of the functions
\li tmplpro_get_expr_as_int64()
\li tmplpro_get_expr_as_double()
\li tmplpro_get_expr_as_pstring()
@see tmplpro_set_option_PushExprArglistFuncPtr
*/
/** \typedef typedef void (*call_expr_userfnc_functype) (ABSTRACT_CALLER*, ABSTRACT_ARGLIST*, ABSTRACT_USERFUNC*, ABSTRACT_EXPRVAL*);
\brief optional callback to call a user-provided function with a current list of arguments.
\param ABSTRACT_CALLER* optional pointer stored by tmplpro_set_option_ext_calluserfunc_state().
\param ABSTRACT_ARGLIST* optional pointer returned by callback of init_expr_arglist_functype.
\param ABSTRACT_USERFUNC* optional pointer returned by callback of is_expr_userfnc_functype.
\param ABSTRACT_EXPRVAL* pointer required by tmplpro_set_expr_as_* functions
(a place the return value will be stored).
To return the result user function returned the callback of call_expr_userfnc_functype should
call one of the functions
\li tmplpro_set_expr_as_null()
\li tmplpro_set_expr_as_int64()
\li tmplpro_set_expr_as_double()
\li tmplpro_set_expr_as_string()
\li tmplpro_set_expr_as_pstring()
passing them the ABSTRACT_EXPRVAL* as argument.
@see tmplpro_set_option_CallExprUserfncFuncPtr
*/
/** \typedef typedef void ABSTRACT_WRITER
\brief optional pointer to be passed to a callback of ::writer_functype.
Optional pointer to store internal state for a callback of ::writer_functype.
If used, it should be stored beforehand with tmplpro_set_option_ext_writer_state().
@see tmplpro_set_option_ext_writer_state
*/
/** \typedef typedef void ABSTRACT_FINDFILE
\brief optional pointer to be passed to a callback of ::find_file_functype.
Optional pointer to store internal state for a callback of ::find_file_functype.
If used, it should be stored beforehand with tmplpro_set_option_ext_findfile_state().
@see tmplpro_set_option_ext_findfile_state
*/
/** \typedef typedef void ABSTRACT_FILTER
\brief optional pointer to be passed to a callback of ::load_file_functype / ::unload_file_functype.
Optional pointer to store internal state for a callback of ::load_file_functype / ::unload_file_functype.
If used, it should be stored beforehand with tmplpro_set_option_ext_filter_state().
@see tmplpro_set_option_ext_filter_state
*/
/** \typedef typedef void ABSTRACT_CALLER
\brief optional pointer to be passed to a callback of ::call_expr_userfnc_functype.
Optional pointer to store internal state for a callback of ::call_expr_userfnc_functype.
If used, it should be stored beforehand with tmplpro_set_option_ext_calluserfunc_state().
@see tmplpro_set_option_ext_calluserfunc_state
*/
/** \typedef typedef void ABSTRACT_DATASTATE
\brief optional pointer to be passed to data manipulation callbacks of
::get_ABSTRACT_VALUE_functype, ::ABSTRACT_VALUE2ABSTRACT_ARRAY_functype,
::get_ABSTRACT_ARRAY_length_functype, ::is_ABSTRACT_VALUE_true_functype,
::get_ABSTRACT_MAP_functype, exit_loop_scope_functype.
Optional pointer to store internal state for a callback of
::get_ABSTRACT_VALUE_functype, ::ABSTRACT_VALUE2ABSTRACT_ARRAY_functype,
::get_ABSTRACT_ARRAY_length_functype, ::is_ABSTRACT_VALUE_true_functype,
::get_ABSTRACT_MAP_functype, exit_loop_scope_functype.
If used, it should be stored beforehand with tmplpro_set_option_ext_data_state().
@see tmplpro_set_option_ext_data_state
*/
/** \typedef typedef void ABSTRACT_ARRAY
\brief optional pointer representing a loop.
It is returned from a callback of ::ABSTRACT_VALUE2ABSTRACT_ARRAY_functype
and is passed to callbacks of ::get_ABSTRACT_ARRAY_length_functype
and ::get_ABSTRACT_MAP_functype.
*/
/** \typedef typedef void ABSTRACT_MAP
\brief optional pointer representing a root scope or a loop scope.
Pointer for the loop scope is returned from a callback of ::get_ABSTRACT_MAP_functype.
Pointer of the root scope should be stored beforehead using tmplpro_set_option_root_param_map().
Both types of pointers are passed to callback of ::get_ABSTRACT_VALUE_functype.
Also, root scope pointer is passed to callbacks of ::end_loop_functype and
::select_loop_scope_functype.
@see tmplpro_set_option_root_param_map
*/
/** \typedef typedef void ABSTRACT_VALUE
\brief optional pointer representing an abstract value that can be converted to a sting or loop.
It is returned from callback of ::get_ABSTRACT_VALUE_functype and passed to
callbacks of ::ABSTRACT_VALUE2ABSTRACT_ARRAY_functype and ::ABSTRACT_VALUE2PSTRING_functype.
*/
/** \typedef typedef void ABSTRACT_FUNCMAP
\brief optional pointer to be passed to a callback of ::is_expr_userfnc_functype.
If used, it should be stored beforehand with tmplpro_set_option_expr_func_map().
@see tmplpro_set_option_expr_func_map
*/
/** \typedef typedef void ABSTRACT_ARGLIST
\brief optional pointer representing a list accumulating arguments to user function call.
It is returned from a callback of ::init_expr_arglist_functype
and is passed to callbacks of ::push_expr_arglist_functype, ::call_expr_userfnc_functype
and ::free_expr_arglist_functype.
*/
/** \typedef typedef void ABSTRACT_USERFUNC
\brief optional pointer representing user function.
It is returned from a callback of ::is_expr_userfnc_functype
and is passed to callback of ::call_expr_userfnc_functype.
*/
/** \typedef typedef void ABSTRACT_EXPRVAL
\brief optional pointer representing user function argument or return value.
It is passed to callbacks of ::push_expr_arglist_functype and ::call_expr_userfnc_functype.
*/
/*
* Local Variables:
* mode: c
* End:
*/
HTML-Template-Pro-0.9510/perl-HTML-Template-Pro.spec 0000644 0000764 0000764 00000017337 12144122203 020246 0 ustar igor igor #################### WARNING! ######################
# this spec file is for ALT Linux distro only. #
# other distro may have problems with rpm macro!!! #
####################################################
%define module HTML-Template-Pro
Name: perl-%module
Version: 0.9510
Release: alt1
Packager: Igor Yu. Vlasenko
Summary: Perl+C/XS module to produce HTML from HTML Template files.
Group: Development/Perl
License: LGPL2+ or Artistic
#Source: http://www.cpan.org/modules/by-module/HTML/%module-%version.tar.gz
Source: %module-%version.tar.gz
Url: http://sourceforge.net/projects/html-tmpl-pro/
# Automatically added by buildreq on Wed Nov 06 2002
BuildRequires: perl-devel pcre libpcre-devel perl-JSON perl-JSON-XS perl-Test-Pod
%description
HTML::Template::Pro is a fast lightweight C/Perl+XS reimplementation
of HTML::Template and HTML::Template::Expr. It is not intended
to be a complete replacement, but to be a fast implementation
of HTML::Template if you don't need quering, the extended facility
of HTML::Template.
Designed for heavy upload, resource limitations, abcence of mod_perl.
HTML::Template module attempts make using HTML templates simple and natural.
It extends standard HTML with a few new HTML-esque tags - ,
, , and . The file
written with HTML and these new tags is called a template. It is
usually saved separate from your script - possibly even created by
someone else! Using this module you fill in the values for the
variables, loops and branches declared in the template. This allows
you to seperate design - the HTML - from the data, which you generate
in the Perl script.
%prep
%setup -q -n %module-%version
%build
%perl_vendor_build
%install
%perl_vendor_install
%files
%doc README Changes README.ru FAQ TODO
%perl_vendor_archlib/*
#perl_vendor_man3dir/*
%changelog
* Mon May 13 2013 Igor Vlasenko 0.9510-alt1
- new version; see Changes
* Tue Feb 28 2012 Igor Vlasenko 0.9509-alt1
- new version; see Changes
* Mon Dec 26 2011 Igor Vlasenko 0.9508-alt1
- new version; see Changes
* Fri Dec 09 2011 Igor Vlasenko 0.9507-alt1
- new version; see Changes
* Wed Oct 19 2011 Alexey Tourbin 0.9506-alt2
- rebilt for perl-5.14
* Tue Oct 04 2011 Igor Vlasenko 0.9506-alt1
- new version; see Changes
* Fri Jul 01 2011 Igor Vlasenko 0.9505-alt1
- new version; see Changes
* Mon Nov 08 2010 Vladimir Lettiev 0.9504-alt1.1
- rebuilt with perl 5.12
* Tue Sep 28 2010 Igor Vlasenko 0.9504-alt1
- new version; see Changes
* Sat Aug 28 2010 Igor Vlasenko 0.9503-alt1
- new version; see Changes
* Thu Jun 17 2010 Igor Vlasenko 0.9502-alt1
- new version; see Changes
* Wed Jun 09 2010 Igor Vlasenko 0.9501-alt1
- new version; see Changes
* Fri May 21 2010 Igor Vlasenko 0.95-alt1
- new version; see Changes
* Tue Feb 16 2010 Igor Vlasenko 0.94-alt1
- new version; see Changes
* Sun Nov 15 2009 Igor Vlasenko 0.93-alt1
- new version; see Changes
* Tue Sep 29 2009 Igor Vlasenko 0.92-alt1
- new version; see Changes
* Tue Sep 22 2009 Igor Vlasenko 0.91-alt1
- new version; see Changes
* Sat Sep 12 2009 Igor Vlasenko 0.90-alt3
- release
* Fri Sep 11 2009 Igor Vlasenko 0.90-alt2
- rc2
* Mon Aug 31 2009 Igor Vlasenko 0.90-alt1
- rc1
* Sat Aug 29 2009 Igor Vlasenko 0.87-alt1
- new version; see Changes
* Sat Aug 22 2009 Igor Vlasenko 0.86-alt1
- new version; see Changes
* Sun Aug 09 2009 Igor Vlasenko 0.85-alt1
- new version; see Changes
* Fri Aug 07 2009 Igor Vlasenko 0.84-alt1
- new version; see Changes
* Wed Aug 05 2009 Igor Vlasenko 0.83-alt1
- new version; see Changes
* Wed Jul 29 2009 Igor Vlasenko 0.82-alt1
- new version; see Changes
* Tue Jul 28 2009 Igor Vlasenko 0.81-alt1
- new version; see Changes
* Thu Jul 23 2009 Igor Vlasenko 0.80-alt1
- new version; see Changes
* Tue Jul 21 2009 Igor Vlasenko 0.78-alt1
- new version; see Changes
* Sat Jul 11 2009 Igor Vlasenko 0.76-alt1
- new version; see Changes
* Wed Jul 01 2009 Igor Vlasenko 0.75-alt1
- new version; see Changes
* Fri Apr 03 2009 Igor Vlasenko 0.74-alt1
- new version; see Changes
* Thu Apr 02 2009 Igor Vlasenko 0.73-alt1
- new version; see Changes
* Thu Dec 18 2008 Igor Vlasenko 0.72-alt1
- new version; see Changes
* Sat Aug 16 2008 Igor Vlasenko 0.71-alt1
- new version; see Changes
* Thu Apr 03 2008 Igor Vlasenko 0.70-alt1
- new version; see Changes
* Thu Feb 28 2008 Igor Vlasenko 0.69-alt1
- new version; see Changes
* Tue Jan 08 2008 Igor Vlasenko 0.68-alt2
- fix for ix86
* Tue Jan 08 2008 Igor Vlasenko 0.68-alt1
- new version; see Changes
* Sun Dec 02 2007 Igor Vlasenko 0.67-alt1
- new version; see Changes
* Thu Oct 04 2007 Igor Vlasenko 0.66-alt1
- new version; see Changes
* Fri Jun 01 2007 Igor Vlasenko 0.65-alt1
- new version
* Tue Apr 18 2006 Igor Vlasenko 0.64-alt1
- new version
* Mon Apr 17 2006 Igor Vlasenko 0.63-alt1
- new version
* Tue Feb 21 2006 Igor Vlasenko 0.62-alt1
- new version
* Sat Feb 04 2006 Igor Vlasenko 0.61-alt1
- new version
* Thu Feb 02 2006 Igor Vlasenko 0.60-alt1
- new version
* Sun Jan 22 2006 Igor Vlasenko 0.59-alt1
- new version
* Fri Dec 02 2005 Igor Vlasenko 0.58-alt1
- new version
* Tue Nov 08 2005 Igor Vlasenko 0.57-alt1
- new version
* Tue Nov 01 2005 Igor Vlasenko 0.56-alt1
- new version
* Mon Oct 24 2005 Igor Vlasenko 0.55-alt1
- new version
* Mon Oct 17 2005 Igor Vlasenko 0.54-alt1
- new version
* Thu Oct 06 2005 Igor Vlasenko 0.53-alt1
- new version
* Fri Sep 30 2005 Igor Vlasenko 0.52-alt1
- new version
* Thu Sep 15 2005 Igor Vlasenko 0.51-alt1
- new version
* Thu Sep 01 2005 Igor Vlasenko 0.49-alt1
- new version
* Wed Aug 31 2005 Igor Vlasenko 0.48-alt1
- new version
* Wed Aug 31 2005 Igor Vlasenko 0.47-alt1
- new version
* Sat Aug 20 2005 Igor Vlasenko 0.46-alt1
- new version
* Fri Aug 19 2005 Igor Vlasenko 0.45-alt1
- new version
* Fri Aug 12 2005 Igor Vlasenko 0.44-alt1
- new version
* Thu Aug 04 2005 Igor Vlasenko 0.43-alt1
- new version
* Thu Aug 04 2005 Igor Vlasenko 0.42-alt1
- new version
* Tue Jul 26 2005 Igor Vlasenko 0.41-alt1
- new version
* Fri Jul 01 2005 Igor Vlasenko 0.40-alt1
- basic support for string comparing (HTML::Template::Expr)
* Thu Jun 22 2005 Igor Vlasenko 0.39-alt1
- new version
* Thu Jun 09 2005 Igor Vlasenko 0.38-alt1
- new version, basic support for HTML::Template::Expr
* Thu Jun 02 2005 Igor Vlasenko 0.37-alt1
- new version
* Mon May 23 2005 Igor Vlasenko 0.36-alt1
- new version
* Thu May 19 2005 Igor Vlasenko 0.35-alt1
- First build for Sisyphus.
* Sun May 15 2005 Igor Vlasenko 0.34-alt1.1
- First build for Daedalus.
HTML-Template-Pro-0.9510/pconst.h 0000644 0000764 0000764 00000000470 11436231734 015041 0 ustar igor igor #ifndef _PCONST_H
#define _PCONST_H 1
/* internal constants */
#define ERR_PRO_INVALID_ARGUMENT 1
#define ERR_PRO_FILE_NOT_FOUND 2
#define ERR_PRO_CANT_OPEN_FILE 3
#define ERR_PRO_TEMPLATE_SYNTAX_ERROR 4
#define ERR_PRO_NOT_ENOUGH_MEMORY 5
#endif /* pconst.h */
/*
* Local Variables:
* mode: c
* End:
*/
HTML-Template-Pro-0.9510/optint.h 0000644 0000764 0000764 00000000237 11300025002 015024 0 ustar igor igor #include "pparam.h"
extern TMPLPRO_LOCAL void _reset_int_options_set_nonzero_defaults(struct tmplpro_param* param);
/*
Local Variables:
mode: c
End:
*/
HTML-Template-Pro-0.9510/pstrutils.inc 0000644 0000764 0000764 00000013036 11676075413 016136 0 ustar igor igor /* -*- c -*-
* File: pstring.h
* Author: Igor Vlasenko
* Created: Fri Jul 1 20:11:51 2005
*
* $Id$
*/
#include
#include
#include
#include "pbuffer.h"
#include "pstring.h"
static
PSTRING
lowercase_pstring (pbuffer* pBuffer ,PSTRING pstring) {
const size_t size=pstring.endnext-pstring.begin;
char* buf=pbuffer_resize(pBuffer, size+1);
char* inbuf=buf;
const char* i=pstring.begin;
PSTRING retval;
while (i=buflen-MAX_ESCAPE_SEQ) {
buf=pbuffer_resize(StrBuffer, 2*(offset+MAX_ESCAPE_SEQ));
buflen=pbuffer_size(StrBuffer);
}
switch (curchar) {
/* straight from the CGI.pm bible. (HTML::Template) */
case '&' : bufdelta=5; strncpy(buf+offset, "&", bufdelta);break;
case '"' : bufdelta=6; strncpy(buf+offset, """,bufdelta);break;
case '>' : bufdelta=4; strncpy(buf+offset, ">", bufdelta);break;
case '<' : bufdelta=4; strncpy(buf+offset, "<", bufdelta);break;
case '\'': bufdelta=5; strncpy(buf+offset, "'", bufdelta);break;
default: *(buf+offset)=curchar;
}
offset+=bufdelta;
}
retval.begin=buf;
retval.endnext=buf+offset;
return retval;
}
static
PSTRING
jsencode_pstring (pbuffer* StrBuffer, PSTRING pstring) {
char* buf=pbuffer_resize(StrBuffer, pstring.endnext-pstring.begin+1+MAX_ESCAPE_SEQ);
const char* curpos=pstring.begin;
size_t offset=0;
size_t buflen=pbuffer_size(StrBuffer);
PSTRING retval;
while (curpos=buflen-MAX_ESCAPE_SEQ) {
buf=pbuffer_resize(StrBuffer, 2*(offset+MAX_ESCAPE_SEQ));
buflen=pbuffer_size(StrBuffer);
}
switch (curchar) {
case '\\' : bufdelta=6; strncpy(buf+offset, "\\u005c", bufdelta);break;
case '"' : bufdelta=6; strncpy(buf+offset, "\\u0022",bufdelta);break;
case '\'' : bufdelta=6; strncpy(buf+offset, "\\u0027",bufdelta);break;
case '\n' : bufdelta=6; strncpy(buf+offset, "\\u000a",bufdelta);break;
case '\r' : bufdelta=6; strncpy(buf+offset, "\\u000d",bufdelta);break;
case '>' : bufdelta=6; strncpy(buf+offset, "\\u003e;", bufdelta);break;
case '<' : bufdelta=6; strncpy(buf+offset, "\\u003c;", bufdelta);break;
case '&' : bufdelta=6; strncpy(buf+offset, "\\u0026;", bufdelta);break;
case '=' : bufdelta=6; strncpy(buf+offset, "\\u003d;", bufdelta);break;
case '-' : bufdelta=6; strncpy(buf+offset, "\\u002d;", bufdelta);break;
case ';' : bufdelta=6; strncpy(buf+offset, "\\u003b;", bufdelta);break;
case '+' : bufdelta=6; strncpy(buf+offset, "\\u002b;", bufdelta);break;
default: *(buf+offset)=curchar;
}
offset+=bufdelta;
}
retval.begin=buf;
retval.endnext=buf+offset;
return retval;
}
static
PSTRING
urlencode_pstring (pbuffer* StrBuffer, PSTRING pstring) {
char* buf=pbuffer_resize(StrBuffer, pstring.endnext-pstring.begin+1+MAX_ESCAPE_SEQ);
const char* curpos=pstring.begin;
size_t offset=0;
size_t buflen=pbuffer_size(StrBuffer);
PSTRING retval;
while (curpos=buflen-MAX_ESCAPE_SEQ) {
buf=pbuffer_resize(StrBuffer, 2*(offset+MAX_ESCAPE_SEQ));
buflen=pbuffer_size(StrBuffer);
}
/*
* # do the translation (RFC 2396 ^uric)
* s!([^a-zA-Z0-9_.\-])!sprintf('%%%02X', $_)
*/
if ((curchar>='a' && curchar<='z') ||
(curchar>='A' && curchar<='Z') ||
(curchar>='0' && curchar<='9') ||
curchar=='_' || curchar=='.' || curchar=='\\' || curchar=='-'
)
*(buf+offset)=curchar;
else {
bufdelta=3; sprintf(buf+offset,"%%%.2X",(int) curchar);
}
offset+=bufdelta;
}
retval.begin=buf;
retval.endnext=buf+offset;
return retval;
}
static
PSTRING
escape_pstring (pbuffer* strBuffer, PSTRING pstring, const int escapeopt) {
switch (escapeopt) {
case HTML_TEMPLATE_OPT_ESCAPE_HTML:
return htmlencode_pstring(strBuffer, pstring);
case HTML_TEMPLATE_OPT_ESCAPE_JS:
return jsencode_pstring(strBuffer, pstring);
case HTML_TEMPLATE_OPT_ESCAPE_URL:
return urlencode_pstring(strBuffer, pstring);
default : return pstring;
}
}
HTML-Template-Pro-0.9510/lib/ 0000755 0000764 0000764 00000000000 12144122665 014126 5 ustar igor igor HTML-Template-Pro-0.9510/lib/HTML/ 0000755 0000764 0000764 00000000000 12144122665 014672 5 ustar igor igor HTML-Template-Pro-0.9510/lib/HTML/Template/ 0000755 0000764 0000764 00000000000 12144122665 016445 5 ustar igor igor HTML-Template-Pro-0.9510/lib/HTML/Template/SYNTAX.pod 0000644 0000764 0000764 00000136543 11441152634 020211 0 ustar igor igor =head1 NAME
HTML::Template::SYNTAX - syntax of html template language for HTML::Template
=head1 SYNOPSIS
This help is only on syntax of html template files.
For perl interface of HTML::Template::Pro you should see
L.
First you make a template - this is just a normal HTML file with a few
extra tags, the simplest being
For example, test.tmpl:
Test Template
My Home Directory is
My Path is set to
Now define the value for HOME and PATH, for example,
in perl it will look like
$template->param(HOME => $ENV{HOME});
$template->param(PATH => $ENV{PATH});
and process the template. If all is well in the universe
this should show something like this in your browser:
My Home Directory is /home/some/directory
My Path is set to /bin;/usr/bin
=head1 DESCRIPTION
This module attempts to make using HTML templates simple and natural.
It extends standard HTML with a few new HTML-esque tags - ,
, , , and .
(HTML::Template::Pro also supports tag.)
The file written with HTML and these new tags is called a template.
It is usually saved separate from your script - possibly even created
by someone else! Using this module you fill in the values for the
variables, loops and branches declared in the template. This allows
you to separate design - the HTML - from the data, which you generate
in the Perl script.
This module is licensed under the (L)GPL or perl license.
See the LICENSE section below for more details.
=head1 TUTORIAL
If you're new to HTML::Template, I suggest you start with the
introductory article available on the HTML::Template website:
http://html-template.sourceforge.net
=head1 MOTIVATION
It is true that there are a number of packages out there to do HTML
templates. On the one hand you have things like HTML::Embperl which
allows you freely mix Perl with HTML. On the other hand lie
home-grown variable substitution solutions. Hopefully the module can
find a place between the two.
One advantage of this module over a full HTML::Embperl-esque solution
is that it enforces an important divide - design and programming. By
limiting the programmer to just using simple variables and loops in
the HTML, the template remains accessible to designers and other
non-perl people. The use of HTML-esque syntax goes further to make
the format understandable to others. In the future this similarity
could be used to extend existing HTML editors/analyzers to support
HTML::Template.
An advantage of this module over home-grown tag-replacement schemes is
the support for loops. In my work I am often called on to produce
tables of data in html. Producing them using simplistic HTML
templates results in CGIs containing lots of HTML since the HTML
itself cannot represent loops. The introduction of loop statements in
the HTML simplifies this situation considerably. The designer can
layout a single row and the programmer can fill it in as many times as
necessary - all they must agree on is the parameter names.
For all that, I think the best thing about this module is that it does
just one thing and it does it quickly and carefully. It doesn't try
to replace Perl and HTML, it just augments them to interact a little
better. And it's pretty fast.
=head1 THE TAGS
=head2 GENERAL TAG SYNTAX
A generic HTML::Template tag that is supported by HTML::Template::Pro
looks like . Tags are case-insensitve:
is acceptable.
Single quotes can be used,
quotes can be omitted,
and option name could be often guessed as in .
template tags could be decorated as html comments
Also, as HTML::Template::Pro extension (starting from version 0.90),
template tags could also be decorated as xml
See L.
=head2 TMPL_VAR
The tag is very simple. For each tag in the
template you call $template->param(PARAMETER_NAME => "VALUE"). When
the template is output the is replaced with the VALUE text
you specified. If you don't set a parameter it just gets skipped in
the output.
Optionally you can use the "ESCAPE=HTML" option in the tag to indicate
that you want the value to be HTML-escaped before being returned from
output (the old ESCAPE=1 syntax is still supported). This means that
the ", <, >, and & characters get translated into ", <, >
and & respectively. This is useful when you want to use a
TMPL_VAR in a context where those characters would cause trouble.
Example:
">
If you called C with a value like sam"my you'll get in trouble
with HTML's idea of a double-quote. On the other hand, if you use
ESCAPE=HTML, like this:
">
You'll get what you wanted no matter what value happens to be passed in for
param. You can also write ESCAPE="HTML", ESCAPE='HTML' and ESCAPE='1'.
"ESCAPE=0" and "ESCAPE=NONE" turn off escaping, which is the default
behavior.
There is also the "ESCAPE=URL" option which may be used for VARs that
populate a URL. It will do URL escaping, like replacing ' ' with '+'
and '/' with '%2F'.
There is also the "ESCAPE=JS" option which may be used for VARs that
need to be placed within a Javascript string. All \n, \r, ' and " characters
are escaped.
You can assign a default value to a variable with the DEFAULT
attribute. For example, this will output "the devil gave me a taco"
if the "who" variable is not set.
The gave me a taco.
=head2 TMPL_LOOP
...
The tag is a bit more complicated than . The
tag allows you to delimit a section of text and give it a
name. Inside this named loop you place s. Now you pass to
C a list (an array ref) of parameter assignments (hash refs) for
this loop. The loop iterates over the list and produces output from
the text block for each pass. Unset parameters are skipped. Here's
an example:
In the template:
Name:
Job:
In the script:
$template->param(EMPLOYEE_INFO => [
{ name => 'Sam', job => 'programmer' },
{ name => 'Steve', job => 'soda jerk' },
]
);
print $template->output();
The output in a browser:
Name: Sam
Job: programmer
Name: Steve
Job: soda jerk
As you can see above the takes a list of variable
assignments and then iterates over the loop body producing output.
Often you'll want to generate a 's contents
programmatically. Here's an example of how this can be done (many
other ways are possible!):
# a couple of arrays of data to put in a loop:
my @words = qw(I Am Cool);
my @numbers = qw(1 2 3);
my @loop_data = (); # initialize an array to hold your loop
while (@words and @numbers) {
my %row_data; # get a fresh hash for the row data
# fill in this row
$row_data{WORD} = shift @words;
$row_data{NUMBER} = shift @numbers;
# the crucial step - push a reference to this row into the loop!
push(@loop_data, \%row_data);
}
# finally, assign the loop data to the loop param, again with a
# reference:
$template->param(THIS_LOOP => \@loop_data);
The above example would work with a template like:
Word:
Number:
It would produce output like:
Word: I
Number: 1
Word: Am
Number: 2
Word: Cool
Number: 3
s within s are fine and work as you would
expect. If the syntax for the C call has you stumped, here's an
example of a param call with one nested loop:
$template->param(LOOP => [
{ name => 'Bobby',
nicknames => [
{ name => 'the big bad wolf' },
{ name => 'He-Man' },
],
},
],
);
Basically, each gets an array reference. Inside the array
are any number of hash references. These hashes contain the
name=>value pairs for a single pass over the loop template.
Inside a , the only variables that are usable are the ones
from the . The variables in the outer blocks are not
visible within a template loop. For the computer-science geeks among
you, a introduces a new scope much like a perl subroutine
call. If you want your variables to be global you can use
'global_vars' option to new() described below.
=head2 TMPL_INCLUDE
This tag includes a template directly into the current template at the
point where the tag is found. The included template contents are used
exactly as if its contents were physically included in the master
template.
The file specified can be an absolute path (beginning with a '/' under
Unix, for example). If it isn't absolute, the path to the enclosing
file is tried first. After that the path in the environment variable
HTML_TEMPLATE_ROOT is tried, if it exists. Next, the "path" option is
consulted, first as-is and then with HTML_TEMPLATE_ROOT prepended if
available. As a final attempt, the filename is passed to open()
directly. See below for more information on HTML_TEMPLATE_ROOT and
the "path" option to new().
As a protection against infinitly recursive includes, an arbitrary
limit of 10 levels deep is imposed. You can alter this limit with the
"max_includes" option. See the entry for the "max_includes" option
below for more details.
For the see L
for more details.
=head2 TMPL_IF
...
The tag allows you to include or not include a block of the
template based on the value of a given parameter name. If the
parameter is given a value that is true for Perl - like '1' - then the
block is included in the output. If it is not defined, or given a
false value - like '0' - then it is skipped. The parameters are
specified the same way as with TMPL_VAR.
Example Template:
Some text that only gets displayed if BOOL is true!
Now if you call $template->param(BOOL => 1) then the above block will
be included by output.
blocks can include any valid HTML::Template
construct - VARs and LOOPs and other IF/ELSE blocks. Note, however,
that intersecting a and a is invalid.
Not going to work:
If the name of a TMPL_LOOP is used in a TMPL_IF, the IF block will
output if the loop has at least one row. Example:
This will output if the loop is not empty.
....
WARNING: Much of the benefit of HTML::Template is in decoupling your
Perl and HTML. If you introduce numerous cases where you have
TMPL_IFs and matching Perl if()s, you will create a maintenance
problem in keeping the two synchronized. I suggest you adopt the
practice of only using TMPL_IF if you can do so without requiring a
matching if() in your Perl code.
=head2 TMPL_ELSIF
...
...
...
...
WARNING: TMPL_ELSIF is a HTML::Template::Pro extension! It is
not supported in HTML::Template (as of 2.9).
=head2 TMPL_ELSE
... ...
You can include an alternate block in your TMPL_IF block by using
TMPL_ELSE. NOTE: You still end the block with , not
!
Example:
Some text that is included only if BOOL is true
Some text that is included only if BOOL is false
=head2 TMPL_UNLESS
...
This tag is the opposite of . The block is output if the
CONTROL_PARAMETER is set false or not defined. You can use
with just as you can with .
Example:
Some text that is output only if BOOL is FALSE.
Some text that is output only if BOOL is TRUE.
If the name of a TMPL_LOOP is used in a TMPL_UNLESS, the UNLESS block
output if the loop has zero rows.
This will output if the loop is empty.
....
=head2 NOTES
HTML::Template's tags are meant to mimic normal HTML tags. However,
they are allowed to "break the rules". Something like:
is not really valid HTML, but it is a perfectly valid use and will
work as planned.
The "NAME=" in the tag is optional, although for extensibility's sake I
recommend using it. Example - "" is acceptable.
If you're a fanatic about valid HTML and would like your templates
to conform to valid HTML syntax, you may optionally type template tags
in the form of HTML comments. This may be of use to HTML authors who
would like to validate their templates' HTML syntax prior to
HTML::Template processing, or who use DTD-savvy editing tools.
In order to realize a dramatic savings in bandwidth, the standard
(non-comment) tags will be used throughout this documentation.
=head1 EXPR EXTENSION
This module supports an extension to HTML::Template which allows
expressions in the template syntax which was implemented in
HTML::Template::Expr. See L for details.
Expression support includes comparisons, math operations, string
operations and a mechanism to allow you add your own functions at
runtime. The basic syntax is:
I've got a lot of bananas.
This will output "I've got a lot of bananas" if you call:
$template->param(banana_count => 100);
In your script. s also work with expressions:
I'd like to have bananas.
This will output "I'd like to have 200 bananas." with the same param()
call as above.
=head1 BASIC SYNTAX
=head2 Variables
Variables are unquoted alphanumeric strings with the same restrictions
as variable names in HTML::Template. Their values are set through
param(), just like normal HTML::Template variables. For example,
these two lines are equivalent:
=head2 Emiliano Bruni extension to Expr
original HTML::Template allows almost arbitrary chars in parameter names,
but original HTML::Template::Expr (as to 0.04) allows variables in the
'EXPR' tag to be only m![A-Za-z_][A-Za-z0-9_]*!.
With this extension, arbitrary chars can be used in variable name inside
the 'EXPR' tag if bracketed in ${}, as, for example, EXPR="${foo.bar} eq 'a'".
Note that old bracketing into {} is considered obsolete, as it will clash
with JSON assignments like A = { "key" => "val" }.
COMPATIBILITY WARNING.
Currently, this extension is not present in HTML::Template::Expr (as of 0.04).
=head2 INCLUDE extension to Expr
With this extension, you can write something like
or , or even
SECURITY WARNING.
Using of this extension with untrasted values of variables is a
potential security leak (as in
with USER_INPUT='/etc/passwd').
Omit it unless you know what you are doing.
COMPATIBILITY WARNING.
Currently, this extension is not present in HTML::Template::Expr (as of 0.04).
=head2 Constants
Numbers are unquoted strings of numbers and may have a single "." to
indicate a floating point number. For example:
String constants must be enclosed in quotes, single or double. For example:
Note that the original parser of HTML::Template::Expr is currently (0.04)
rather simple, so if you need backward compatibility all compound
expressions must be parenthesized.
Backward compatible examples:
Nevertheless, in HTML::Template::Pro, you can safely write things like
with proper priority of operations.
Pattern in a regular expression must be enclosed with "/":
=head1 COMPARISON
Here's a list of supported comparison operators:
=over 4
=item * Numeric Comparisons
=over 4
=item * E
=item * E
=item * ==
=item * !=
=item * E=
=item * E=
=item * E=E
=back
=item * String Comparisons
=over 4
=item * gt
=item * lt
=item * eq
=item * ne
=item * ge
=item * le
=item * cmp
=back
=back
=head1 MATHEMATICS
The basic operators are supported:
=over 4
=item * +
=item * -
=item * *
=item * /
=item * %
=item * ^ (not supported in HTML::Template::Expr)
=back
There are also some mathy functions. See the FUNCTIONS section below.
=head1 LOGIC
Boolean logic is available:
=over 4
=item * && (synonym: and)
=item * || (synonym: or)
=back
=head1 REGULAR EXPRESSION SUPPORT
regexp support is added to HTML::Template::Expr and
HTML::Template::Pro by Stanislav Yadykin .
Currently it is not included in official distribution of HTML::Template::Expr.
Standard regexp syntax:
=over 4
=item * =~
=item * !~
=back
=head1 FUNCTIONS
The following functions are available to be used in expressions. See
perldoc perlfunc for details.
=over 4
=item * sprintf
=item * substr (2 and 3 arg versions only)
=item * lc
=item * lcfirst
=item * uc
=item * ucfirst
=item * length
=item * defined
=item * abs
=item * atan2
=item * cos
=item * exp
=item * hex
=item * int
=item * log
=item * oct
=item * rand
=item * sin
=item * sqrt
=item * srand
=back
All functions must be called using full parenthesis. For example,
this is a syntax error:
But this is good:
=head1 EXPR: DEFINING NEW FUNCTIONS
You may also define functions of your own.
See L for details.
=begin comment
=head1 METHODS
=head2 new()
Call new() to create a new Template object:
my $template = HTML::Template->new( filename => 'file.tmpl',
option => 'value'
);
You must call new() with at least one name => value pair specifying how
to access the template text. You can use C<< filename => 'file.tmpl' >>
to specify a filename to be opened as the template. Alternately you can
use:
my $t = HTML::Template->new( scalarref => $ref_to_template_text,
option => 'value'
);
and
my $t = HTML::Template->new( arrayref => $ref_to_array_of_lines ,
option => 'value'
);
These initialize the template from in-memory resources. In almost
every case you'll want to use the filename parameter. If you're
worried about all the disk access from reading a template file just
use mod_perl and the cache option detailed below.
You can also read the template from an already opened filehandle,
either traditionally as a glob or as a FileHandle:
my $t = HTML::Template->new( filehandle => *FH, option => 'value');
The four new() calling methods can also be accessed as below, if you
prefer.
my $t = HTML::Template->new_file('file.tmpl', option => 'value');
my $t = HTML::Template->new_scalar_ref($ref_to_template_text,
option => 'value');
my $t = HTML::Template->new_array_ref($ref_to_array_of_lines,
option => 'value');
my $t = HTML::Template->new_filehandle($fh,
option => 'value');
And as a final option, for those that might prefer it, you can call new as:
my $t = HTML::Template->new(type => 'filename',
source => 'file.tmpl');
Which works for all three of the source types.
If the environment variable HTML_TEMPLATE_ROOT is set and your
filename doesn't begin with /, then the path will be relative to the
value of $HTML_TEMPLATE_ROOT. Example - if the environment variable
HTML_TEMPLATE_ROOT is set to "/home/sam" and I call
HTML::Template->new() with filename set to "sam.tmpl", the
HTML::Template will try to open "/home/sam/sam.tmpl" to access the
template file. You can also affect the search path for files with the
"path" option to new() - see below for more information.
You can modify the Template object's behavior with new(). The options
are available:
=over 4
=item Error Detection Options
=over 4
=item *
die_on_bad_params - if set to 0 the module will let you call
$template->param(param_name => 'value') even if 'param_name' doesn't
exist in the template body. Defaults to 1.
=item *
strict - if set to 0 the module will allow things that look like they
might be TMPL_* tags to get by without dieing. Example:
Would normally cause an error, but if you call new with strict => 0,
HTML::Template will ignore it. Defaults to 1.
HTML::Template::Pro always use strict => 0.
=item *
vanguard_compatibility_mode - if set to 1 the module will expect to
see s that look like %NAME% in addition to the standard
syntax. Also sets die_on_bad_params => 0. If you're not at Vanguard
Media trying to use an old format template don't worry about this one.
Defaults to 0.
vanguard_compatibility_mode is not supported in HTML::Template::Pro.
=back
=item Caching Options
HTML::Template use many caching options such as
cache, shared_cache, double_cache, blind_cache, file_cache,
file_cache_dir, file_cache_dir_mode, double_file_cache
to cache preparsed html templates.
Since HTML::Template::Pro parses and outputs templates at once,
it silently ignores those options.
=back
=item Filesystem Options
=over 4
=item *
path - you can set this variable with a list of paths to search for
files specified with the "filename" option to new() and for files
included with the tag. This list is only consulted
when the filename is relative. The HTML_TEMPLATE_ROOT environment
variable is always tried first if it exists. Also, if
HTML_TEMPLATE_ROOT is set then an attempt will be made to prepend
HTML_TEMPLATE_ROOT onto paths in the path array. In the case of a
file, the path to the including file is also tried
before path is consulted.
Example:
my $template = HTML::Template->new( filename => 'file.tmpl',
path => [ '/path/to/templates',
'/alternate/path'
]
);
NOTE: the paths in the path list must be expressed as UNIX paths,
separated by the forward-slash character ('/').
=item *
search_path_on_include - if set to a true value the module will search
from the top of the array of paths specified by the path option on
every and use the first matching template found. The
normal behavior is to look only in the current directory for a
template to include. Defaults to 0.
=back
=item Debugging Options
=over 4
=item *
debug - if set to 1 the module will write random debugging information
to STDERR. Defaults to 0.
=item *
HTML::Template use many cache debug options such as
stack_debug, cache_debug, shared_cache_debug, memory_debug.
Since HTML::Template::Pro parses and outputs templates at once,
it silently ignores those options.
=back
=item Miscellaneous Options
=over 4
=item *
associate - this option allows you to inherit the parameter values
from other objects. The only requirement for the other object is that
it have a C method that works like HTML::Template's C. A
good candidate would be a CGI.pm query object. Example:
my $query = new CGI;
my $template = HTML::Template->new(filename => 'template.tmpl',
associate => $query);
Now, C<< $template->output() >> will act as though
$template->param('FormField', $cgi->param('FormField'));
had been specified for each key/value pair that would be provided by
the C<< $cgi->param() >> method. Parameters you set directly take
precedence over associated parameters.
You can specify multiple objects to associate by passing an anonymous
array to the associate option. They are searched for parameters in
the order they appear:
my $template = HTML::Template->new(filename => 'template.tmpl',
associate => [$query, $other_obj]);
The old associateCGI() call is still supported, but should be
considered obsolete.
NOTE: The parameter names are matched in a case-insensitve manner. If
you have two parameters in a CGI object like 'NAME' and 'Name' one
will be chosen randomly by associate. This behavior can be changed by
the following option.
=item *
case_sensitive - setting this option to true causes HTML::Template to
treat template variable names case-sensitively. The following example
would only set one parameter without the "case_sensitive" option:
my $template = HTML::Template->new(filename => 'template.tmpl',
case_sensitive => 1);
$template->param(
FieldA => 'foo',
fIELDa => 'bar',
);
This option defaults to off.
NOTE: with case_sensitive and loop_context_vars the special loop
variables are available in lower-case only.
=item *
loop_context_vars - when this parameter is set to true (it is false by
default) four loop context variables are made available inside a loop:
__first__, __last__, __inner__, __odd__. They can be used with
, and to control how a loop is
output.
In addition to the above, a __counter__ var is also made available
when loop context variables are turned on.
Example:
This only outputs on the first pass.
This outputs every other pass, on the odd passes.
This outputs every other pass, on the even passes.
This outputs on passes that are neither first nor last.
This is pass number .
This only outputs on the last pass.
One use of this feature is to provide a "separator" similar in effect
to the perl function join(). Example:
and , .
Would output (in a browser) something like:
Apples, Oranges, Brains, Toes, and Kiwi.
Given an appropriate C call, of course. NOTE: A loop with only
a single pass will get both __first__ and __last__ set to true, but
not __inner__.
=item *
no_includes - set this option to 1 to disallow the tag
in the template file. This can be used to make opening untrusted
templates B less dangerous. Defaults to 0.
=item *
max_includes - set this variable to determine the maximum depth that
includes can reach. Set to 10 by default. Including files to a depth
greater than this value causes an error message to be displayed. Set
to 0 to disable this protection.
=item *
global_vars - normally variables declared outside a loop are not
available inside a loop. This option makes s like global
variables in Perl - they have unlimited scope. This option also
affects and .
Example:
This is a normal variable: .
Here it is inside the loop:
Normally this wouldn't work as expected, since 's
value outside the loop is not available inside the loop.
The global_vars option also allows you to access the values of an
enclosing loop within an inner loop. For example, in this loop the
inner loop will have access to the value of OUTER_VAR in the correct
iteration:
OUTER:
INNER:
INSIDE OUT:
B: C is not C (which does not exist).
That means that loops you declare at one scope are not available
inside other loops even when C is on.
=item *
path_like_variable_scope - this option switches on a Shigeki Morimoto
extension to HTML::Template::Pro that allows access to variables that
are outside the current loop scope using path-like expressions.
Example:
{{{
}}}
=item *
filter - this option allows you to specify a filter for your template
files. A filter is a subroutine that will be called after
HTML::Template reads your template file but before it starts parsing
template tags.
In the most simple usage, you simply assign a code reference to the
filter parameter. This subroutine will recieve a single argument - a
reference to a string containing the template file text. Here is an
example that accepts templates with tags that look like "!!!ZAP_VAR
FOO!!!" and transforms them into HTML::Template tags:
my $filter = sub {
my $text_ref = shift;
$$text_ref =~ s/!!!ZAP_(.*?)!!!//g;
};
# open zap.tmpl using the above filter
my $template = HTML::Template->new(filename => 'zap.tmpl',
filter => $filter);
More complicated usages are possible. You can request that your
filter receieve the template text as an array of lines rather than as
a single scalar. To do that you need to specify your filter using a
hash-ref. In this form you specify the filter using the C key and
the desired argument format using the C key. The available
formats are C and C. Using the C format will incur
a performance penalty but may be more convenient in some situations.
my $template = HTML::Template->new(filename => 'zap.tmpl',
filter => { sub => $filter,
format => 'array' });
You may also have multiple filters. This allows simple filters to be
combined for more elaborate functionality. To do this you specify an
array of filters. The filters are applied in the order they are
specified.
my $template = HTML::Template->new(filename => 'zap.tmpl',
filter => [
{ sub => \&decompress,
format => 'scalar' },
{ sub => \&remove_spaces,
format => 'array' }
]);
The specified filters will be called for any TMPL_INCLUDEed files just
as they are for the main template file.
=item *
default_escape - Set this parameter to "HTML", "URL" or "JS" and
HTML::Template will apply the specified escaping to all variables
unless they declare a different escape in the template.
=back
=cut
=head2 param()
C can be called in a number of ways
1) To return a list of parameters in the template :
my @parameter_names = $self->param();
2) To return the value set to a param :
my $value = $self->param('PARAM');
3) To set the value of a parameter :
# For simple TMPL_VARs:
$self->param(PARAM => 'value');
# with a subroutine reference that gets called to get the value
# of the scalar. The sub will recieve the template object as a
# parameter.
$self->param(PARAM => sub { return 'value' });
# And TMPL_LOOPs:
$self->param(LOOP_PARAM =>
[
{ PARAM => VALUE_FOR_FIRST_PASS, ... },
{ PARAM => VALUE_FOR_SECOND_PASS, ... }
...
]
);
4) To set the value of a a number of parameters :
# For simple TMPL_VARs:
$self->param(PARAM => 'value',
PARAM2 => 'value'
);
# And with some TMPL_LOOPs:
$self->param(PARAM => 'value',
PARAM2 => 'value',
LOOP_PARAM =>
[
{ PARAM => VALUE_FOR_FIRST_PASS, ... },
{ PARAM => VALUE_FOR_SECOND_PASS, ... }
...
],
ANOTHER_LOOP_PARAM =>
[
{ PARAM => VALUE_FOR_FIRST_PASS, ... },
{ PARAM => VALUE_FOR_SECOND_PASS, ... }
...
]
);
5) To set the value of a a number of parameters using a hash-ref :
$self->param(
{
PARAM => 'value',
PARAM2 => 'value',
LOOP_PARAM =>
[
{ PARAM => VALUE_FOR_FIRST_PASS, ... },
{ PARAM => VALUE_FOR_SECOND_PASS, ... }
...
],
ANOTHER_LOOP_PARAM =>
[
{ PARAM => VALUE_FOR_FIRST_PASS, ... },
{ PARAM => VALUE_FOR_SECOND_PASS, ... }
...
]
}
);
=head2 clear_params()
Sets all the parameters to undef. Useful internally, if nowhere else!
=head2 output()
output() returns the final result of the template. In most situations
you'll want to print this, like:
print $template->output();
When output is called each occurrence of is
replaced with the value assigned to "name" via C. If a named
parameter is unset it is simply replaced with ''. are
evaluated once per parameter set, accumlating output on each pass.
Calling output() is guaranteed not to change the state of the
Template object, in case you were wondering. This property is mostly
important for the internal implementation of loops.
You may optionally supply a filehandle to print to automatically as
the template is generated. This may improve performance and lower
memory consumption. Example:
$template->output(print_to => *STDOUT);
The return value is undefined when using the C option.
=head2 query()
This method allow you to get information about the template structure.
It can be called in a number of ways. The simplest usage of query is
simply to check whether a parameter name exists in the template, using
the C option:
if ($template->query(name => 'foo')) {
# do something if a varaible of any type
# named FOO is in the template
}
This same usage returns the type of the parameter. The type is the
same as the tag minus the leading 'TMPL_'. So, for example, a
TMPL_VAR parameter returns 'VAR' from C.
if ($template->query(name => 'foo') eq 'VAR') {
# do something if FOO exists and is a TMPL_VAR
}
Note that the variables associated with TMPL_IFs and TMPL_UNLESSs will
be identified as 'VAR' unless they are also used in a TMPL_LOOP, in
which case they will return 'LOOP'.
C also allows you to get a list of parameters inside a loop
(and inside loops inside loops). Example loop:
And some query calls:
# returns 'LOOP'
$type = $template->query(name => 'EXAMPLE_LOOP');
# returns ('bop', 'bee', 'example_inner_loop')
@param_names = $template->query(loop => 'EXAMPLE_LOOP');
# both return 'VAR'
$type = $template->query(name => ['EXAMPLE_LOOP', 'BEE']);
$type = $template->query(name => ['EXAMPLE_LOOP', 'BOP']);
# and this one returns 'LOOP'
$type = $template->query(name => ['EXAMPLE_LOOP',
'EXAMPLE_INNER_LOOP']);
# and finally, this returns ('inner_bee', 'inner_bop')
@inner_param_names = $template->query(loop => ['EXAMPLE_LOOP',
'EXAMPLE_INNER_LOOP']);
# for non existent parameter names you get undef
# this returns undef.
$type = $template->query(name => 'DWEAZLE_ZAPPA');
# calling loop on a non-loop parameter name will cause an error.
# this dies:
$type = $template->query(loop => 'DWEAZLE_ZAPPA');
As you can see above the C option returns a list of parameter
names and both C and C take array refs in order to refer
to parameters inside loops. It is an error to use C with a
parameter that is not a loop.
Note that all the names are returned in lowercase and the types are
uppercase.
Just like C, C with no arguments returns all the
parameter names in the template at the top level.
=head1 FREQUENTLY ASKED QUESTIONS
In the interest of greater understanding I've started a FAQ section of
the perldocs. Please look in here before you send me email.
=over 4
=item 1
Q: Is there a place to go to discuss HTML::Template and/or get help?
A: There's a mailing-list for discussing HTML::Template at
html-template-users@lists.sourceforge.net. To join:
http://lists.sourceforge.net/lists/listinfo/html-template-users
If you just want to get email when new releases are available you can
join the announcements mailing-list here:
http://lists.sourceforge.net/lists/listinfo/html-template-announce
=item 2
Q: Is there a searchable archive for the mailing-list?
A: Yes, you can find an archive of the SourceForge list here:
http://www.geocrawler.com/lists/3/SourceForge/23294/0/
For an archive of the old vm.com list, setup by Sean P. Scanlon, see:
http://bluedot.net/mail/archive/
=item 3
Q: I want support for ! How about it?
A: Maybe. I definitely encourage people to discuss their ideas for
HTML::Template on the mailing list. Please be ready to explain to me
how the new tag fits in with HTML::Template's mission to provide a
fast, lightweight system for using HTML templates.
NOTE: Offering to program said addition and provide it in the form of
a patch to the most recent version of HTML::Template will definitely
have a softening effect on potential opponents!
=item 4
Q: I found a bug, can you fix it?
A: That depends. Did you send me the VERSION of HTML::Template, a test
script and a test template? If so, then almost certainly.
If you're feeling really adventurous, HTML::Template has a publically
available Subversion server. See below for more information in the PUBLIC
SUBVERSION SERVER section.
=item 5
Q: s from the main template aren't working inside a
! Why?
A: This is the intended behavior. introduces a separate
scope for s much like a subroutine call in Perl introduces a
separate scope for "my" variables.
If you want your s to be global you can set the
'global_vars' option when you call new(). See above for documentation
of the 'global_vars' new() option.
=item 6
Q: Why do you use /[Tt]/ instead of /t/i? It's so ugly!
A: Simple - the case-insensitive match switch is very inefficient.
According to _Mastering_Regular_Expressions_ from O'Reilly Press,
/[Tt]/ is faster and more space efficient than /t/i - by as much as
double against long strings. //i essentially does a lc() on the
string and keeps a temporary copy in memory.
When this changes, and it is in the 5.6 development series, I will
gladly use //i. Believe me, I realize [Tt] is hideously ugly.
=item 7
Q: How can I pre-load my templates using cache-mode and mod_perl?
A: Add something like this to your startup.pl:
use HTML::Template;
use File::Find;
print STDERR "Pre-loading HTML Templates...\n";
find(
sub {
return unless /\.tmpl$/;
HTML::Template->new(
filename => "$File::Find::dir/$_",
cache => 1,
);
},
'/path/to/templates',
'/another/path/to/templates/'
);
Note that you'll need to modify the "return unless" line to specify
the extension you use for your template files - I use .tmpl, as you
can see. You'll also need to specify the path to your template files.
One potential problem: the "/path/to/templates/" must be EXACTLY the
same path you use when you call HTML::Template->new(). Otherwise the
cache won't know they're the same file and will load a new copy -
instead getting a speed increase, you'll double your memory usage. To
find out if this is happening set cache_debug => 1 in your application
code and look for "CACHE MISS" messages in the logs.
=item 8
Q: What characters are allowed in TMPL_* NAMEs?
A: Numbers, letters, '.', '/', '+', '-' and '_'.
=item 9
Q: How can I execute a program from inside my template?
A: Short answer: you can't. Longer answer: you shouldn't since this
violates the fundamental concept behind HTML::Template - that design
and code should be seperate.
But, inevitably some people still want to do it. If that describes
you then you should take a look at
L. Using
HTML::Template::Expr it should be easy to write a run_program()
function. Then you can do awful stuff like:
Just, please, don't tell me about it. I'm feeling guilty enough just
for writing HTML::Template::Expr in the first place.
=item 10
Q: Can I get a copy of these docs in Japanese?
A: Yes you can. See Kawai Takanori's translation at:
http://member.nifty.ne.jp/hippo2000/perltips/html/template.htm
=item 11
Q: What's the best way to create a