HTML-Template-Compiled-1.003000755001750001750 012712112457 14637 5ustar00tinatina000000000000README100644001750001750 62512712112457 15563 0ustar00tinatina000000000000HTML-Template-Compiled-1.003 This archive contains the distribution HTML-Template-Compiled, version 1.003: Template System Compiles HTML::Template files to Perl code This software is copyright (c) 2015 by Tina Müller. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. This README file was generated by Dist::Zilla::Plugin::Readme v5.043. Changes100644001750001750 4735312712112457 16247 0ustar00tinatina000000000000HTML-Template-Compiled-1.003Revision history for Perl module HTML::Template::Compiled. 1.003 2016-05-03 14:06:00 - Bugfix: prevent unexpected Data::Dumper config to mess with the output (github issue #10 bittrine++) - Fixed typos (github PR #9 zhouzhen1++) - Storable >= 2.05 (CODE refs) - fixed issue with parallel testing 1.002 Sun Jul 26 01:43:26 CEST 2015 - Regular release, see developer versions 1.001_002 Tue Jul 21 20:48:37 CEST 2015 - Bugfix: Issues with global_vars #6, #7 (rpv-tomsk++) - Changed to Dist::Zilla 1.001_001 Tue May 21 00:50:22 CEST 2013 - New option: optimize - Minor optimization 1.001 Sat May 4 12:49:44 CEST 2013 - Regular release, see developer versions for changes 1.000_006 Fri Jan 25 22:57:24 CET 2013 - Minor optimizations for file cache - Remove ::Plugin::DHTML (own distribution) 1.000_004 Thu Jan 10 00:29:59 CET 2013 - New features: added options warnings and line_info 1.000_003 Mon Dec 31 19:05:54 CET 2012 - fix test 1.000_002 Sat Dec 1 21:06:57 CET 2012 - make parallel testing possible - remove ::Plugin::NumberFormat (has its own distribution now) 1.000_001 Tue Nov 27 19:55:00 CET 2012 - Minor optimizations - New Feature: attribute sortby for TMPL_EACH 1.000 Tue Nov 13 20:45:44 CET 2012 - regular release 0.99_001 Sat Aug 4 17:32:03 CEST 2012 - Bugfix: reloading changed includes didn't always work 0.99 Mon Jul 2 21:48:39 CEST 2012 - fixed tests (deprecation in perl 5.17 and Data::TreeDumper prereq) - also see developer version changes 0.98_003 Sun Jun 10 19:25:15 CEST 2012 - removed test cache directory from distribution - added some modules to recommends 0.98_002 Wed Jun 6 20:43:05 CEST 2012 - Workaround for using var names with dollars: local $HTML::Template::Compiled::Compiler::DISABLE_NEW_ALIAS = 1; 0.98_001 Mon Jun 4 23:53:45 CEST 2012 - require perl 5.8.1 - Hotfix for include_var and file caching 0.98 Mon Jun 4 18:18:40 CEST 2012 - IMPORTANT: Change: use aliases (alias=..., SET_VAR) via $aliasname. USE_VARS will be removed in the future. Old alias syntax still works for now. 0.97_006 Sun Jun 3 19:26:50 CEST 2012 - new plugin HTML::Template::Compiled::Plugin::NumberFormat 0.97_005 Sat Jun 2 12:47:06 CEST 2012 - New feature: option cache_debug - New feature: TMPL_WRAPPER - Another bugfix for search_path_on_include 0.97_004 Sun May 20 18:38:32 CEST 2012 - Change: Implemented searching the path and search_path_on_include like in HTML::Template (finally) and add an additional value. PLEASE TEST! - Improved file cache performance - Bugfix: old bug with invalid tags in noparse, verbatim, comment - Remove old Storable workaround (0.94_002) 0.97_001 Thu May 17 14:54:30 CEST 2012 - fix HTML::Template::Compiled::Classic: allow every character in template var names (RT 70676) - New option expire_time instead of global HTML::Template::Compiled->ExpireTime - Added loop context vars __even__, __outer__ - Change: removed documentation of class methods ->CaseSensitive, ->SearchPathOnInclude, ->UseQuery - will be deprecated - Added strict option 0.97 Tue May 8 19:19:00 CEST 2012 - regular release, see changes from dev version below 0.96_005 Sun May 6 16:24:54 CEST 2012 - fix t/25_expr.t number of skip tests 0.96_004 Sat May 5 15:56:27 CEST 2012 - Minor bugfix USE_VARS, module version numbers - Bugfix caching: under certain circumstances some template includes were not added to memory cache and reloaded from file cache very time 0.96_003 Fri May 4 17:09:19 CEST 2012 - Improved Feature: expressions like .path.to.hash{var} 0.96_002 Sun Apr 22 19:23:33 CEST 2012 - Changed/New feature: chomp whitespaces globally or in tags - New feature: SET_VAR (and USE_VARS) 0.96_001 Sat Apr 21 23:17:59 CEST 2012 - New feature: allow expressions like .path.to.hash{var} - Bugfix: allow more than two binary operands in H::T::C::Expr 0.96 Mon Nov 21 20:37:22 CET 2011 - fixed 05_filter.t - fixed t/01_HTML-Template-Compiled.t (problems when test takes longer then cache expiration) 0.95_003 Sat Nov 12 15:12:02 CET 2011 - Bugfix: Reload includes of includes (required change of caching mechanism - please report any issues if you have problems with caching) - New Escape: 'IJSON' - Deprecated the use options 'speed', 'compatible' and 'short' 0.95_002 Mon Oct 31 21:00:51 CET 2011 - HTML::Template Compatibility: lowercase instead of uppercase parameters when case_sensitive 0 0.95_001 Sun Aug 28 19:02:00 CEST 2011 - Bugfix: escape=js escapes backslash now (RT 66463) - Bugfix: H::T::C::Classic ignored case_sensitive (RT 70412) - Added Template::AutoFilter to bench.pl 0.95 Wed Apr 27 20:48:13 CEST 2011 - Just moving developer release to regular release 0.94_002 Thu Aug 19 23:43:41 CEST 2010 - Fix for 5.12: ignore Storable fatal error abour regexp items. thanks to Daniel Tašov for the hint. just a workaround for now 0.94_001 Wed Sep 16 19:41:01 CEST 2009 - Fix memory leak when compiling Thanks to Henrik Tougaard 0.94 Thu Sep 10 19:55:04 CEST 2009 - Fix test 0.93_003 - remove HTML::Entities dependency 0.93_002 Fri Aug 21 14:47:09 CEST 2009 - Bugfix: Expressions were only activated when using default tagstyle; using tagstyle would overwrite use_expression option - New feaure: in TMPL_LOOP and TMPL_EACH you can set context="list" This is necessary if you call a method that returns a list instead of array- or hashref 0.93_001 Sun Jul 12 17:03:16 CEST 2009 - Bugfix: single quoted attributes did not allow double quotes in content http://rt.cpan.org/Public/Bug/Display.html?id=43591 - Bugfix: global vars weren't fetched correctly if case_sensitive off http://rt.cpan.org/Public/Bug/Display.html?id=43591 - Bugfix: add missing package line http://rt.cpan.org/Public/Bug/Display.html?id=45081 - Bugfix: added md5sum of paths to cache key so different templates with the same name are found http://rt.cpan.org/Public/Bug/Display.html?id=28606 - Bugfix: expressions didn't work in every tag 0.93 Mon Nov 3 20:03:07 CET 2008 - New Feature: sort-Attribute for TMPL_EACH - Change: Allow TMPL_LOOP over an overloaded @{} object (and TMPL_EACH over %{}) - Bugfix: closing IF_DEFINED was not recognized http://rt.cpan.org/Ticket/Display.html?id=40341 0.92_001 Sun Aug 10 18:53:48 CEST 2008 - Bugfix: ESCAPE didn't work always correctly since 0.92 0.92 Sat Jul 26 13:02:28 CEST 2008 - Change: code in TMPL_WITH is now only executed if the var is defined - New Feature: Option no_includes like in HTML::Template - For changes since 0.91 see 0.91_001, 0.91_002, 0.91_003 0.91_003 Mon Jun 16 23:03:46 CEST 2008 - New feature: Debug compiled code (see method debug_code) - Bufix: __last__ and __inner__ in included templates (thanks to Henrik Tougaard for the patch) - Bugfix: Ternary operator didn't produce correct syntax always (also thanks to Henrik Tougaard) - New feature: Expressions like in HTML::Template::Expr 0.91_002 - Bugfix: option objects - Bugfix: object plugins 0.91_001 - Bugfix: TMPL_IF_DEFINED without TMPL_ELSE http://rt.cpan.org/Public/Bug/Display.html?id=33383 - New feature: filename debugging (option debug_file) - New feature: option objects (strict, nostrict, 0) 0.91 Thu Jan 24 21:50:20 CET 2008 - Fixed tests: utf8 problems with perl 5.8.[0-7] - Change: open_mode without leading '<' 0.90 Thu Nov 15 00:39:35 CET 2007 - New Feature: use objects as plugins - New Feature: option open_mode (e.g. '<:utf8') (thanks to Moritz Lenz and Chris Hagglund) - Fixed tests: permission problems on Win32 0.89 Mon Oct 29 21:50:40 CET 2007 - New Feature: BREAK attribute for loops (see docs) - Bugfix: utf8 in scalarrefs (thanks to Chris Hagglund) - Experimental feature: chomp newlines before/after tags. See docs. 0.88 Mon Sep 10 22:05:44 CEST 2007 - Bugfix: file-caching and Storable need B::Deparse >= 0.61. Checking for proper version now. - Fix: broken test - Bugfix: avoid warnings when using html escape - Bugfix: using more than one plugin http://rt.cpan.org/Ticket/Display.html?id=28764 - Bugfix Plugin::XMLEscape: use numeric entities 0.87 Mon Jul 30 22:46:31 CEST 2007 - Change: file-caching now stores as Storable. If you get problems with file-caching please report and set $HTML::Template::Compiled::Storable to 0 as a workaround. - Change: escape=HTML now only escapes '"&<> http://rt.cpan.org/Public/Bug/Display.html?id=27446 - Change: allow every character for TMPL_* NAMEs http://rt.cpan.org/Ticket/Display.html?id=28094 - Bugfix: ALIAS did only work for simple varnames http://rt.cpan.org/Ticket/Display.html?id=28430 - Change: in future versions you should use file_cache and file_cache_dir like in HTML::Template 0.86 Mon Jun 11 22:38:04 CEST 2007 - Experimental Feature: use Storable for filecaching (set $HTML::Template::Compiled::Storable to 1 if you want to test it. It should be 1.5-2 times as fast as normal filecaching) - Fix: a test didn't skip if necessary - utf8 in templates (you probably need Encode (and thus 5.8) for that) - Fix: recursive includes didn't really work because of compile-time instead of runtime check 0.85 Sun Apr 15 16:15:22 CEST 2007 - New Feature: JOIN attribute for loop-tag - Fix: uri_escape_utf8 for parameters in utf8 - Fix for DBIx::Class objects ('can' method doesn't work here like expected) - Fix: Allow <%= array_of_arrays[0][0] %> - New Feature: get count of array elements <%= array# %> 0.84 Sun Feb 11 15:43:38 CET 2007 - Bugfix: includes in var includes didn't expire cache - Bugfix: tagstyle and use_perl weren't correctly passed to includes when using filecache - Bugfix: plugins weren't safed in file cache 0.83 Tue Nov 28 22:59:06 CET 2006 - Added Feature: TMPL_EACH - Added missing plugin feature 0.82 Mon Nov 6 21:25:23 CET 2006 - Added: shorter plugins (omit the HTML::Template::Compiled::Plugin) - Added Feature: TMPL_INCLUDE_STRING - Added Feature: TMPL_PERL for including perl-code 0.81 Fri Nov 3 22:48:05 CET 2006 - Minor change in plugin code 0.80 Sun Oct 15 16:39:02 CEST 2006 - Bugfix: characters like '-' in lead to compilation errors - Bugfix: accessing array elements like didn't work 0.79 Sat Oct 7 20:36:55 CEST 2006 - Change: instead of you must now use query(name => ['FOO', 'BAR']) - Bugfix: query() now also reports included vars like H::T does 0.78 Wed Oct 4 21:22:09 CEST 2006 - Bugfix: endless loop when using file cache - Bugfix: correctly use cache attribute with filecache 0.77 Mon Oct 2 18:35:52 CEST 2006 - fixed META.yaml (was broken by E::MakeMaker) 0.76 Mon Oct 2 18:15:29 CEST 2006 - Change: HTC::Classic: TMPL_IF arrayref will be true if arrayref contains elements - Change: __odd__, __first__, __count__ and __index__ work in TMPL_WHILE - Bugfix: path attribute - Change: deprecate option dumper (use plugin instead) 0.75 Thu Sep 14 22:42:19 CEST 2006 - Bugfix of bug in 0.74: search_path_on_include didn't work 0.74 Wed Sep 13 20:51:04 CEST 2006 - Internal Changes - Security fix: Escape dangerous characters in template - Change: default for search_path_on_include is now 0 like in H::T - added examples/objects.pl 0.73 Sat Aug 26 16:07:57 CEST 2006 - Bugfix: in 0.72 only __first__ worked, but not __FIRST__ - Change: query() now also reports INCLUDE_VARs - New feature: __index__ loop variable - New feature: Plugins for escape-attribute 0.72 Fri Aug 18 22:16:35 CEST 2006 - Documentation: Debugging and Escaping functions are now documented in HTML::Template::Compiled::Utils (Mark Stosberg) - Change: Remove deprecated TMPL_IF DEFINED - Change: HTC will die if you use wrong syntax in tags (like H::T) - Bugfix: HTML::Template::Compiled::Lazy and query() - Bugfix: loop variables should survive different template files 0.71 Thu Jul 13 20:54:44 CEST 2006 - Change: dropped TMPL_LOOP_CONTEXT (not really useful) - Bug Fix: Filters didn't work correctly when used with file caching - Change: deprecate options method_call, deref and formatter_path. You must use inheritance now instead 0.70 Wed Jul 5 21:12:05 CEST 2006 - Bug Fix: php-tag style wasn't parsed - New Feature: lazy loading with HTML::Template::Compiled::Lazy - various documentation fixes - use ALIAS with TMPL_WHILE 0.69 Sun Jul 2 19:45:35 CEST 2006 - Bug Fix: Includes didn't work always correctly in scalarref - Bug Fix: Allow 'absolute' filenames that are relative to attribute path - Bug Fix: Empty path didn't work properly - Bug Fix: make inheritance possible - Change: new class HTML::Template::Compiled::Classic for features that can't be used with HTML::Template::Compiled features at the same time 0.68 Wed Jun 21 20:38:05 CEST 2006 - New Feature: ESCAPE=JS was still missing - Bug Fix: parameters stayed in memory cache - Documentation fix 0.67 Wed Jun 7 22:19:05 CEST 2006 - Bug Fix: stack for global_vars wrong when using if-tag http://rt.cpan.org/Ticket/Display.html?id=19662 - Bug Fix: preloading did not recompile outdated templates - Change: undefined files via TMPL_INCLUDE_VAR don't let script die - Change: Deprecated setting global variables directly, they must be changed by class-methods: $ENABLE_SUB => EnableSub(bool) $CASE_SENSITIVE_DEFAULT => CaseSensitive(bool) $SEARCHPATH => SearchPathOnInclude(bool) $DEFAULT_QUERY => UseQuery(bool) $NEW_CHECK => ExpireTime(seconds) - Documentation: explain case_sensitive and use_query better http://rt.cpan.org/Public/Bug/Display.html?id=19686 0.66 Sun Jun 4 03:49:58 CEST 2006 - Bug Fix: global_vars didn't work correctly with file-caching - Bug Fix: there was no output when last characters in template are a tag. - Bug Fix: calling param(%emptyhash) caused error-message 0.65 Fri Jun 2 10:10:06 CEST 2006 - Bug Fix: Documentation error broke pod 0.64 Thu Jun 1 23:54:32 CEST 2006 - Bug Fix: undefined filename and INCLUDE_VAR - New Feature: alias - Change: TMPL_IF DEFINED deprecated - Change: TMPL_INCLUDE VAR from deprecated to forbidden - New Feature: Define your own tagstyles 0.63 Sat Apr 29 02:39:30 CEST 2006 - Bug Fix: info for query() got lost with file caching - New Feature: TMPL_WHILE - Bug Fix: __vars__ when not using loop_context_vars - Bug Fix: TMPL_CASE wasn't rendered correctly since 0.61 0.62 Wed Apr 26 23:36:13 CEST 2006 - New Feature: added method precompile - New Feature: implemented query() (from HTML::Template) 0.61 Sat Apr 22 19:34:32 CEST 2006 - Bug Fix: global_vars and variables that are never set http://rt.cpan.org/Public/Bug/Display.html?id=17851 - Change: allow CASE default in a list of other strings - Bug Fix: weird endless loop when using wrong tags 0.60 Sun Feb 26 18:46:07 CET 2006 - Clarified docs for TMPL_WITH to explain interaction with global_vars - New Feature: TMPL_VERBATIM - Bug Fix: error when double TMPL_ELSE - New feature: global_vars => 2 0.59 Tue Jan 3 19:40:46 CET 2006 - $UNTAINT - All the "new_" constructor shortcuts were added from HTML::Template, with tests for each. Also, the type/source option syntax to new() is now supported. Tests were added for all these, which were generally missing from the HTML::Template test suite. - Bug Fix: Code and Tests were were added to make sure that calls to param() accumulate data, like HTML::Template works. - Bug Fix: embedded newlines - New Feature: new 'default_escape' option for compatibility with HTML::Template 2.8 - Added query() tests from HTML::Template suite. (Currently TODO) - Change: use dot notation for mehtod calls and dereference - Change: literal dots in var names work now; you can't use -> for method calling any more, just use the dot 0.58 Sun Dec 11 23:20:35 CET 2005 - fixed test with html entities - use H::T::C speed => 1 - tmpl_include_var - TMPL_LOOP_CONTEXT 0.57 Wed Dec 7 15:54:05 CET 2005 - tmpl_comment doesn't output - tmpl_noparse does, though - various pod- and test-fixes 0.56 Wed Dec 7 01:46:21 CET 2005 - some include and scalarref issues fixed - - , 0.55 Wed Nov 23 22:36:58 CET 2005 - search_path_on_include 0.54 Wed Nov 23 21:21:49 CET 2005 - fixed path issues - better handling of unbalanced tags 0.53 Thu Oct 6 22:12:53 CEST 2005 - fixed another issue with filter - bugfix preload 0.52 Mon Oct 3 18:34:19 CEST 2005 - bugfix with nonexistant templates and deep recursion - bugfix path and filecache - bugfix with filter (subrefs) - added tmpl_if defined 0.51 Mon Oct 3 00:43:31 CEST 2005 - clear_filecache - fixed tmpl_elsif, line_numbers - preload 0.50 Sat Oct 1 01:16:09 CEST 2005 - added formatter - added global_vars 0.49 Sun Sep 25 23:04:38 CEST 2005 - fixed 05_out_fh.t - dynamic includes 0.48 Tue Sep 20 23:54:56 CEST 2005 - compatible via use statement 0.47 Tue Sep 20 00:43:37 CEST 2005 - output($fh) - filter 0.46 Sat Sep 17 17:01:01 CEST 2005 - minor internal issues - enable subref vars - fixed __odd__ - recursive include limit, thanks sam 0.45 Fri Sep 16 00:20:07 CEST 2005 - param("var") 0.44 Thu Sep 8 20:56:53 CEST 2005 - arrayref 0.43 Wed Sep 7 21:11:28 CEST 2005 - scalarref - filehandle 0.42 Fri Sep 2 01:51:14 CEST 2005 - add: HTML::Template::Compiled::Plugin::DHTML 0.41 Sat Aug 27 12:07:08 CEST 2005 - test failed because of missing cache dir 0.40 Sat Aug 27 03:05:00 CEST 2005 - more internal changes 0.39 Mon Aug 22 22:27:52 CEST 2005 - bug with caching fixed 0.38 Mon Aug 22 21:02:30 CEST 2005 - __counter__ now correct - more internal changes 0.37 Mon Aug 22 00:31:58 CEST 2005 - case_insensitive removed, use only case_sensitive - internal changes 0.36 Sun Aug 21 03:41:45 CEST 2005 - newlines in tags - ESCAPE=DUMP, chaining ESCAPE - DEFAULT=... - option dumper 0.34 Fri Aug 19 19:58:56 CEST 2005 - minor bugs, removed debugging statement 0.32 Thu Aug 18 23:52:33 CEST 2005 - fixed caching bug 0.31 Thu Aug 18 22:48:22 CEST 2005 - better object syntax 0.30 Mon Aug 15 01:55:29 CEST 2005 - some internal optimizations - case_insensitive for those who want it 0.29 Sun Aug 14 22:51:30 CEST 2005 - examples directory with bechmark of 4 template modules 0.28 Fri Aug 12 23:32:44 CEST 2005 - case insensitive TMPL_* 0.27 Thu Aug 4 00:06:34 CEST 2005 - added <%tag%> feature 0.26 Thu Jul 28 22:11:48 CEST 2005 - some docs - fixed regex and objects 0.25 Wed Jul 27 23:18:06 CEST 2005 - undefstring userdefined - fixed TMPL_IF method 0.24 Wed Jul 20 20:57:00 CEST 2005 - fixed 0.23 Mon Jul 18 00:03:08 CEST 2005 - first step for rendering objects, documentation will follow. (yes, promised =) 0.22 Sun Jul 17 19:15:22 CEST 2005 - bugfix TMPL_INCLUDE 0.21 Fri Jul 1 21:48:51 CEST 2005 - fixed ESCAPE=HTML|URI - implemented 0.20 Sun Jun 26 18:04:11 CEST 2005 - Errors for wrong balanced tags 0.19 Sun Jun 26 15:02:37 CEST 2005 - bugfix NAME=ONE.TWO - TMPL_WITH - Dumper 0.18 Sun Jun 26 12:36:15 CEST 2005 - small bugfixes for older perl versions - typos - TMPL_ELSIF 0.17 Mon Jun 20 23:30:43 CEST 2005 - small bugfixes, warnings - doc 0.16 Mon May 16 15:42:07 CEST 2005 - TMPL_WITH - bugfix with .root 0.15 Mon May 16 15:18:42 CEST 2005 - bugfix 0.14 Mon May 16 14:27:31 CEST 2005 - bug in caching removed - TMPL_VAR .root - TMPL_VAR key.path.with.numbers.23 0.13 Mon May 2 23:49:08 CEST 2005 - clear_cache() 0.12 Mon May 2 22:18:35 CEST 2005 - remove warnings 0.10 Mon Apr 18 22:06:10 CEST 2005 - HTML_TEMPLATE_ROOT - caching - loop_context_vars 0.09 Fri Apr 15 00:31:23 CEST 2005 - - caching improved (expire) 0.06 Sat Feb 26 00:45:31 CET 2005 - ESCAPE=HTML 0.05 Sat Feb 26 00:31:21 CET 2005 - TMPL_INCLUDE 0.04 Fri Feb 25 00:29:44 CET 2005 - caching improved 0.03 Thu Feb 24 23:17:10 CET 2005 - Quote Handling (NAME="var") 0.02 Tue Feb 22 01:18:23 CET 2005 - fixed bugs, caching half implemented 0.01 Sun Feb 20 17:44:07 2005 - original version; created by h2xs 1.23 with options -AX -n HTML::Template::Compiled LICENSE100644001750001750 4365512712112457 15762 0ustar00tinatina000000000000HTML-Template-Compiled-1.003This software is copyright (c) 2015 by Tina Müller. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2015 by Tina Müller. This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2015 by Tina Müller. This is free software, licensed under: The Artistic License 1.0 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. - "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 ftp.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) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting 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. 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 whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. 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 dist.ini100644001750001750 42212712112457 16342 0ustar00tinatina000000000000HTML-Template-Compiled-1.003name = HTML-Template-Compiled author = Tina Müller license = Perl_5 copyright_holder = Tina Müller copyright_year = 2015 version = 1.003 [@Basic] [AutoPrereqs] [Prereqs] Storable = 2.05 [Repository] [OverridePkgVersion] [MetaProvides::Package] META.yml100644001750001750 764012712112457 16200 0ustar00tinatina000000000000HTML-Template-Compiled-1.003--- abstract: 'Template System Compiles HTML::Template files to Perl code' author: - 'Tina Müller ' build_requires: File::Copy: '0' Test::More: '0' lib: '0' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 0 generated_by: 'Dist::Zilla version 5.043, CPAN::Meta::Converter version 2.150005' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: HTML-Template-Compiled provides: HTML::Template::Compiled: file: lib/HTML/Template/Compiled.pm version: '1.003' HTML::Template::Compiled::Classic: file: lib/HTML/Template/Compiled/Classic.pm version: '1.003' HTML::Template::Compiled::Compiler: file: lib/HTML/Template/Compiled/Compiler.pm version: '1.003' HTML::Template::Compiled::Compiler::Classic: file: lib/HTML/Template/Compiled/Compiler/Classic.pm version: '1.003' HTML::Template::Compiled::Exception: file: lib/HTML/Template/Compiled/Exception.pm version: '1.003' HTML::Template::Compiled::Expr: file: lib/HTML/Template/Compiled/Expr.pm version: '1.003' HTML::Template::Compiled::Expression: file: lib/HTML/Template/Compiled/Expression.pm version: '1.003' HTML::Template::Compiled::Expression::Conditional: file: lib/HTML/Template/Compiled/Expression.pm version: '1.003' HTML::Template::Compiled::Expression::Defined: file: lib/HTML/Template/Compiled/Expression/Expressions.pm version: '1.003' HTML::Template::Compiled::Expression::Elsif: file: lib/HTML/Template/Compiled/Expression.pm version: '1.003' HTML::Template::Compiled::Expression::Expressions: file: lib/HTML/Template/Compiled/Expression/Expressions.pm version: '1.003' HTML::Template::Compiled::Expression::Function: file: lib/HTML/Template/Compiled/Expression.pm version: '1.003' HTML::Template::Compiled::Expression::Literal: file: lib/HTML/Template/Compiled/Expression/Expressions.pm version: '1.003' HTML::Template::Compiled::Expression::Method: file: lib/HTML/Template/Compiled/Expression.pm version: '1.003' HTML::Template::Compiled::Expression::SubrefCall: file: lib/HTML/Template/Compiled/Expression.pm version: '1.003' HTML::Template::Compiled::Expression::Ternary: file: lib/HTML/Template/Compiled/Expression/Expressions.pm version: '1.003' HTML::Template::Compiled::Filter: file: lib/HTML/Template/Compiled/Filter.pm version: '1.003' HTML::Template::Compiled::Formatter: file: lib/HTML/Template/Compiled/Formatter.pm version: '1.003' HTML::Template::Compiled::Lazy: file: lib/HTML/Template/Compiled/Lazy.pm version: '1.003' HTML::Template::Compiled::Parser: file: lib/HTML/Template/Compiled/Parser.pm version: '1.003' HTML::Template::Compiled::Plugin::XMLEscape: file: lib/HTML/Template/Compiled/Plugin/XMLEscape.pm version: '1.003' HTML::Template::Compiled::Token: file: lib/HTML/Template/Compiled/Token.pm version: '1.003' HTML::Template::Compiled::Token::Text: file: lib/HTML/Template/Compiled/Token.pm version: '1.003' HTML::Template::Compiled::Token::close: file: lib/HTML/Template/Compiled/Token.pm version: '1.003' HTML::Template::Compiled::Token::open: file: lib/HTML/Template/Compiled/Token.pm version: '1.003' HTML::Template::Compiled::Token::single: file: lib/HTML/Template/Compiled/Token.pm version: '1.003' HTML::Template::Compiled::Utils: file: lib/HTML/Template/Compiled/Utils.pm version: '1.003' requires: B::Deparse: '0' Carp: '0' Data::Dumper: '0' Digest::MD5: '0' Encode: '0' Exporter: '0' Fcntl: '0' File::Basename: '0' File::Spec: '0' HTML::Entities: '0' Parse::RecDescent: '0' Scalar::Util: '0' Storable: '2.05' URI::Escape: '0' base: '0' constant: '0' overload: '0' strict: '0' vars: '0' warnings: '0' resources: repository: git://github.com/perlpunk/HTML-Template-Compiled.git version: '1.003' MANIFEST100644001750001750 524312712112457 16055 0ustar00tinatina000000000000HTML-Template-Compiled-1.003# This file was automatically generated by Dist::Zilla::Plugin::Manifest v5.043. Changes LICENSE MANIFEST MANIFEST.SKIP META.yml Makefile.PL README dist.ini examples/bench.pl examples/bench_mem.pl examples/included.htc examples/included.htcc examples/included.tst examples/included.tt examples/included.xslate examples/objects.html examples/objects.pl examples/test.htc examples/test.htc.20 examples/test.htcc examples/test.tst examples/test.tt examples/test.xslate lib/HTML/Template/Compiled.pm lib/HTML/Template/Compiled/Classic.pm lib/HTML/Template/Compiled/Compiler.pm lib/HTML/Template/Compiled/Compiler/Classic.pm lib/HTML/Template/Compiled/Exception.pm lib/HTML/Template/Compiled/Expr.pm lib/HTML/Template/Compiled/Expression.pm lib/HTML/Template/Compiled/Expression/Expressions.pm lib/HTML/Template/Compiled/Filter.pm lib/HTML/Template/Compiled/Formatter.pm lib/HTML/Template/Compiled/Lazy.pm lib/HTML/Template/Compiled/Parser.pm lib/HTML/Template/Compiled/Plugin/XMLEscape.pm lib/HTML/Template/Compiled/Reference.pod lib/HTML/Template/Compiled/Token.pm lib/HTML/Template/Compiled/Utils.pm t/01_HTML-Template-Compiled.t t/03_param.t t/04_out_fh.t t/05_filter.t t/06_dyn_include.t t/07_formatter.t t/08_global_vars.t t/09_wrong.t t/10_if_else.t t/12_path.t t/13_loop.t t/14_scalarref.t t/15_comment.t t/16_switch.t t/17_escape.t t/18_objects.t t/19_query.t t/20_precompile.t t/21_while.t t/22_pod.t t/23_tagstyles.t t/24_pod_cover.t t/26_expr.t t/27_chomp.t t/28_perl.t t/29_encoding.t t/30_arrays.t t/31_recurse.t t/32_compile_plugin.t t/33_plugins.t t/34_loop_context_vars.t t/35_debug.t t/36_default.t t/37_with.t t/38_vars.t t/39_line_info.t t/40_data_dumper.t t/HTC_Plugin.pm t/HTC_Utils.pm t/new_shortcuts.t t/templates/dyn_include.htc t/templates/dyn_included1.htc t/templates/dyn_included2.htc t/templates/file_debug.html t/templates/filter.htc t/templates/filter_included.htc t/templates/formatter.htc t/templates/include.html t/templates/include_perl.htc t/templates/include_w_global.htc t/templates/line_info1.html t/templates/loop_included.tmpl t/templates/out_fh.htc t/templates/precompiled1.tmpl t/templates/query-include.tmpl t/templates/query-include2.tmpl t/templates/query-test.tmpl t/templates/query-test2.tmpl t/templates/recurse.html t/templates/simple.tmpl t/templates/songs.html t/templates/subdir/a/file1.html t/templates/subdir/a/file2.html t/templates/subdir/a/path.html t/templates/subdir/a/path2.html t/templates/subdir/a/path2_inc.html t/templates/subdir/b.html t/templates/subdir/file_debug.html t/templates/subdir2/dummy.tmpl t/templates/user_template.html t/templates/var_include.html t/templates/wrapped.html t/templates/wrapper.html t/templates/wrapper2.html t/templates/wrong.html t000755001750001750 012712112457 15023 5ustar00tinatina000000000000HTML-Template-Compiled-1.00322_pod.t100644001750001750 31312712112457 16412 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/tuse strict; use Test::More; eval "use Test::Pod 1.00"; plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; my @poddirs = qw( examples lib ); all_pod_files_ok( all_pod_files( @poddirs ) ); 28_perl.t100644001750001750 163012712112457 16623 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/tuse warnings; use strict; use lib 't'; use Test::More tests => 2; use_ok('HTML::Template::Compiled'); use HTC_Utils qw($cache $tdir &cdir); { my $text = <<'EOM'; [%perl __OUT__ "template: __HTC__"; my $test = __ROOT__->{foo}; __OUT__ $test; %] [%loop loop%] [%perl __OUT__ __INDEX__ . ": " . __CURRENT__->{a}; %] [%/loop loop%] [%include include_perl.htc %] EOM HTML::Template::Compiled->ExpireTime(0); my $htc = HTML::Template::Compiled->new( scalarref => \$text, use_perl => 1, path => $tdir, debug => 0, tagstyle => [qw(-classic -comment +asp +tt)], cache => 0, search_path_on_include => 1, ); $htc->param( foo => 23, loop => [{ a => 'A' },{ a => 'B' }], ); my $out = $htc->output; #print "out: $out\n"; cmp_ok($out, '=~', qr{template: HTML::Template::Compiled.*23.*0: A.*1: B}s, "perl-tag"); } 38_vars.t100644001750001750 164412712112457 16642 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/t use Test::More tests => 3; BEGIN { use_ok('HTML::Template::Compiled') }; use lib 't'; use HTC_Utils qw($cache $tdir &cdir); { my $htc = HTML::Template::Compiled->new( scalarref => \<<'EOM', <%set_var FOO value=.root.foo %> <%= FOO %> <%include var_include.html %> EOM debug => 0, loop_context_vars => 1, path => $tdir, ); $htc->param( root => { foo => 23, }, ); my $out = $htc->output; $out =~ s/\s+//g; cmp_ok($out, "eq", "2323", "set_var, use_vars"); #print "out: $out\n"; } { eval { my $htc = HTML::Template::Compiled->new( scalarref => \<<'EOM', <%set_var name="foo bar" value=.root %> EOM debug => 0, loop_context_vars => 1, path => $tdir, ); }; my $error = $@; # warn __PACKAGE__.':'.__LINE__.": $error\n"; cmp_ok($error, "=~", ".*Syntax error in .*", "invalid set_var"); } 13_loop.t100644001750001750 1022312712112457 16642 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/tuse Test::More tests => 10; BEGIN { use_ok('HTML::Template::Compiled') }; use lib 't'; use HTC_Utils qw($tdir &cdir &create_cache &remove_cache); my $cache_dir = "cache13"; $cache_dir = create_cache($cache_dir); for my $new_alias (0,1) { local $HTML::Template::Compiled::Compiler::DISABLE_NEW_ALIAS = 1 unless ($new_alias); my $htc = HTML::Template::Compiled->new( scalarref => \<<"EOM", EOM debug => 0, loop_context_vars => 1, cache => 0, ); my $array = []; my $array2 = []; if ($new_alias) { $array = [qw(a b c)]; $array2 = [{ foo => 'a' }, { foo => 'b' }, { foo => 'c' }]; } else { $array = [{ '$iterator' => 'a' }, { '$iterator' => 'b' }, { '$iterator' => 'c' }]; $array2 = [{ '$iterator' => { foo => 'a' } }, { '$iterator' => { foo => 'b' } }, { '$iterator' => { foo => 'c' } }]; } $htc->param( array => $array, array2 => $array2, ); my $out = $htc->output; $out =~ s/\s+//g; if ($new_alias) { cmp_ok($out, "eq", "aabbccaabbcc", "tmpl_loop array alias=iterator"); } else { cmp_ok($out, "=~", qr{HASH\(.*\)aHASH\(.*\)bHASH\(.*\)cabc}, "tmpl_loop array alias=iterator"); } #print "out: $out\n"; } my $text1 = <<'EOM'; | (outer:) (even:) EOM for (0,1) { my $htc = HTML::Template::Compiled->new( scalarref => \$text1, debug => 0, loop_context_vars => $_, ); $htc->param(array => [ {x=>"a","__counter__"=>"A","__outer__"=>"OUTER"}, {x=>"b","__counter__"=>"B","__even__"=>"EVEN"}, {x=>"c","__counter__"=>"C",}, {x=>"d","__counter__"=>"D",,"__even__"=>"EVEN"}, {x=>"e","__counter__"=>"E","__outer__"=>"OUTER"}, ]); my $out = $htc->output; $out =~ s/\s+//g; my $exp; if ($_ == 1) { $exp = "|(outer:1)1a|(even:1)2b|3c|(even:1)4d|(outer:1)5e"; } else { $exp = "|(outer:OUTER)Aa|(even:EVEN)Bb|Cc|(even:EVEN)Dd|(outer:OUTER)Ee"; } #print "($out)($exp)\n"; cmp_ok($out, "eq", $exp, "loop context"); } { my $htc = HTML::Template::Compiled->new( scalarref => \<<%= _ %><%/loop list %> EOM debug => 0, ); $htc->param( list => [qw(a b c)] ); my $out = $htc->output; $out =~ s/^\s+//; $out =~ s/\s+\z//; #print $out, $/; cmp_ok($out, 'eq','a, b, c', "loop join attribute"); } { my $htc = HTML::Template::Compiled->new( scalarref => \<<%= _ %><%if __break__%>.<%/if %><%/loop list %> EOM debug => 0, loop_context_vars => 1, ); $htc->param( list => [qw(a b c d e f g h)] ); my $out = $htc->output; $out =~ s/^\s+//; $out =~ s/\s+\z//; #print $out, $/; cmp_ok($out, 'eq','abc.def.gh', "loop break attribute"); } { my $htc = HTML::Template::Compiled->new( scalarref => \<<'EOM', <%loop list %> <%include loop_included.tmpl %> <%/loop list %> EOM debug => 0, loop_context_vars => 1, path => $tdir, ); $htc->param( list => [qw(a b c d e f g h)] ); my $out = $htc->output; $out =~ s/\s+/ /g; #print $out, $/; cmp_ok($out, 'eq',' 0 1 2 3 4 5 6 7 h ', "loop context vars in include"); } for (0, 1) { my $htc = HTML::Template::Compiled->new( scalarref => \<<'EOM', <%loop foo.list %> <%= a %> <%/loop foo.list %> EOM debug => 0, loop_context_vars => 1, path => $tdir, cache => 0, file_cache => 1, file_cache_dir => $cache_dir, ); $htc->param( foo => { list => [{a => 1},{a => 2},{a => 3}], }, ); my $out = $htc->output; $out =~ s/\s+/ /g; #print $out, $/; cmp_ok($out, 'eq',' 1 2 3 ', "loop " . ($_ ? "after" : "before") . " caching"); } HTML::Template::Compiled->clear_filecache($cache_dir); remove_cache($cache_dir); 12_path.t100644001750001750 420612712112457 16610 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/t# Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl HTML-Template-Compiled.t' use Test::More tests => 5; BEGIN { use_ok('HTML::Template::Compiled') }; use File::Spec (); use lib 't'; use HTC_Utils qw($tdir); eval { my $htc = HTML::Template::Compiled->new( path => [ File::Spec->catfile(qw(t templates_foo)), $tdir, ], filename => File::Spec->catfile(qw(a file1.html)), search_path_on_include => 0, #debug => 1, ); }; print "err: $@\n" unless $ENV{HARNESS_ACTIVE}; my $f = File::Spec->catfile(qw/ a file1.html /); cmp_ok($@, '=~', qr{'\Q$f\E' not found}, "search_path_on_include off"); my $htc = HTML::Template::Compiled->new( path => ["$tdir/subdir", "$tdir/subdir2"], filename => File::Spec->catfile(qw(a file1.html)), search_path_on_include => 1, #debug => 1, ); my $out = $htc->output; $out =~ tr/\r\n//d; ok( $out =~ m{Template t/templates/subdir/a/file1.htmlTemplate t/templates/subdir/a/file2.html}, "include form current dir" ); { # local $TODO = "path not yet correctly implemented"; my $out = ''; eval { my $htc = HTML::Template::Compiled->new( path => File::Spec->catfile(qw(t templates)), filename => 'subdir/a/path.html', search_path_on_include => 1, ); $out = $htc->output; #warn __PACKAGE__.':'.__LINE__.$".Data::Dumper->Dump([\$out], ['out']); }; #warn __PACKAGE__.':'.__LINE__.": error? $@\n"; cmp_ok($out, '=~', 'this is t/templates/subdir/b.html', 'search path option on include'); } { my $out = ''; eval { my $htc = HTML::Template::Compiled->new( path => File::Spec->catfile(qw(t templates)), filename => 'subdir/a/path2.html', search_path_on_include => 2, ); $out = $htc->output; # warn __PACKAGE__.':'.__LINE__.$".Data::Dumper->Dump([\$out], ['out']); }; # warn __PACKAGE__.':'.__LINE__.": error? $@\n"; cmp_ok($out, '=~', qr{this is t/templates/subdir/b.html.*this is templates/subdir/a/path2_inc.html}s, 'search current path and path option on include'); } 37_with.t100644001750001750 126712712112457 16642 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/t# Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl HTML-Template-Compiled.t' use Test::More tests => 2; BEGIN { use_ok('HTML::Template::Compiled') }; { my $htc = HTML::Template::Compiled->new( scalarref => \<<'EOM', <%with foo.bar %> bar:<%= _[0] %> <%/with foo.bar %> <%with foo.baz %> baz:<%= _[0] %> <%/with foo.baz %> EOM debug => 0, ); $htc->param( foo => { bar => [qw/ this and that /], }, ); my $out = $htc->output; $out =~ s/\s+//g; #print $out, $/; cmp_ok($out, "eq", "bar:this", "global_vars and unset variable"); } 26_expr.t100644001750001750 1035412712112457 16660 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/tuse warnings; use strict; use lib 't'; use constant TESTS => 28; use Test::More tests => TESTS + 1; eval { require Parse::RecDescent; }; my $prd = $@ ? 0 : 1; use_ok('HTML::Template::Compiled'); use HTC_Utils qw($cache $tdir &cdir); sub HT_Utils::list { my @a = qw/ a b c /; return @a } sub HT_Utils::each { my %a = ( a => 1, b => 2 ); return %a } SKIP: { skip "No Parse::RecDescent installed", TESTS unless $prd; use_ok('HTML::Template::Compiled::Expr'); my $htc; eval { $htc = HTML::Template::Compiled->new( scalarref => \<<'EOM', [%= expr="(foo.count < 4) && ( foo.count > 2)" %] EOM use_expressions => 0, tagstyle => [qw/ -classic -comment -asp +tt /], loop_context_vars => 1, ); }; my $error = $@; #warn __PACKAGE__.':'.__LINE__.": $@\n"; cmp_ok($error, '=~', qr/\QSyntax error in tag/, "No expressions allowed"); my @tests = ( [ q#[%= expr="(foo.count < 4) && ( foo.count > 2)" %]#, 1], [ q#[%= expr="(foo.count > 4) && ( foo.count % 2)" %]#, ''], [ q#[%= expr="lcfirst( .string )" %]#, 'aBC'], [ q#[%if expr="lcfirst( .string ) eq 'aBC'" %]23[%/if %]#, '23'], [ q#[%if expr="'string\'' eq 'string\''" %]23[%/if %]#, '23'], [ q#[%= expr="object.param('foo', .foo.count )" %]#, '424242'], [ q#[%if expr="0" %]zero[%elsif expr="foo.count < 4" %]< 4[%/if %]#, '< 4'], [ q#[%loop expr="list_object.list" context="list" %][%= _ %][%/loop %]#, 'abc'], [ q#[%each expr="list_object.each" context="list" %]k:[%= __key__ %] [%/each %]#, 'k:a k:b '], [ q#[%= expr=".foo{.name}" %]#, '3'], [ q#[%= expr=".foo{'count'}" %]#, '3'], [ q#[%= expr=".columns[.numbers[1]]" %]#, 'founded'], [ q#[%= expr=".a{'b'}{'c'}" %]#, 'd'], [ q#[%= expr=".bands[.numbers[1]]{'name'}" %]#, 'deine lakaien'], [ q#[%with name %][%= expr=".foo{_}" %][%/with %]#, '3'], [ q#[%= expr="'foo'.(2+5)" %]#, 'foo7'], [ q#[%= expr=".foo{('count'.2)}" %]#, '22'], [ q#[%= expr="3 * 4 / 2 + 7" %]#, '13'], [ q#[%= expr="('2' . '5' ) / 5" %]#, '5'], [ q#[%= expr="('2' . '4' ) % 20" %]#, '4'], [ q#[%= expr=".foobar" default="default value" %]#, 'default value'], [ q#[%loop list %][%= expr=".foo{_}" %] [%/loop %]#, 'foo a foo b foo c foo d '], [ q#[%loop list alias=item %][%= expr=".foo{$item}" %] [%/loop %]#, 'foo a foo b foo c foo d '], [ q#[%loop bands alias=band %][%= expr="$band{'name'}" %] [%/loop %]#, 'bauhaus deine lakaien '], [ q#[%loop bands %][%= expr="_{'name'}" %] [%/loop %]#, 'bauhaus deine lakaien '], [ q#[%loop bands alias=band %] [%= __counter__ %]. [%loop .columns alias=column %] [%= column %]: [%= expr="$band{column}" %] [%/loop %] [%/loop %]#, '1. name: bauhaus founded: 1978 2. name: deine lakaien founded: 1985 '], ); for my $i (0 .. $#tests) { my $test = $tests[$i]; my ($tmpl, $exp) = @$test; $tmpl =~ tr/\r\n//d; my $htc = HTML::Template::Compiled->new( scalarref => \$tmpl, use_expressions => 1, debug => 0, tagstyle => [qw/ -classic -comment -asp +tt /], loop_context_vars => 1, ); my $list_object = bless {}, 'HT_Utils'; $htc->param( foo => { count => '3', count1 => '21', count2 => '22', count3 => '23', a => 'foo a', b => 'foo b', c => 'foo c', d => 'foo d', }, object => bless ({ foo => 42 }, 'HTC::DUMMY'), string => 'ABC', list_object => $list_object, name => 'count', list => [qw/ a b c d /], bands => [ { name => 'bauhaus', founded => 1978 }, { name => 'deine lakaien', founded => 1985 }, ], columns => [qw/ name founded /], numbers => [0,1], a => { b => { c => 'd' } }, ); my $out = $htc->output; #print "out: $out\n"; cmp_ok($out, 'eq', $exp, "Expressions $i $tmpl"); } } sub HTC::DUMMY::param { return $_[0]->{ $_[1] } x $_[2] } Makefile.PL100644001750001750 360012712112457 16671 0ustar00tinatina000000000000HTML-Template-Compiled-1.003# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v5.043. use strict; use warnings; use ExtUtils::MakeMaker; my %WriteMakefileArgs = ( "ABSTRACT" => "Template System Compiles HTML::Template files to Perl code", "AUTHOR" => "Tina M\x{fc}ller ", "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => 0 }, "DISTNAME" => "HTML-Template-Compiled", "LICENSE" => "perl", "NAME" => "HTML::Template::Compiled", "PREREQ_PM" => { "B::Deparse" => 0, "Carp" => 0, "Data::Dumper" => 0, "Digest::MD5" => 0, "Encode" => 0, "Exporter" => 0, "Fcntl" => 0, "File::Basename" => 0, "File::Spec" => 0, "HTML::Entities" => 0, "Parse::RecDescent" => 0, "Scalar::Util" => 0, "Storable" => "2.05", "URI::Escape" => 0, "base" => 0, "constant" => 0, "overload" => 0, "strict" => 0, "vars" => 0, "warnings" => 0 }, "TEST_REQUIRES" => { "File::Copy" => 0, "Test::More" => 0, "lib" => 0 }, "VERSION" => "1.003", "test" => { "TESTS" => "t/*.t" } ); my %FallbackPrereqs = ( "B::Deparse" => 0, "Carp" => 0, "Data::Dumper" => 0, "Digest::MD5" => 0, "Encode" => 0, "Exporter" => 0, "Fcntl" => 0, "File::Basename" => 0, "File::Copy" => 0, "File::Spec" => 0, "HTML::Entities" => 0, "Parse::RecDescent" => 0, "Scalar::Util" => 0, "Storable" => "2.05", "Test::More" => 0, "URI::Escape" => 0, "base" => 0, "constant" => 0, "lib" => 0, "overload" => 0, "strict" => 0, "vars" => 0, "warnings" => 0 ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { delete $WriteMakefileArgs{TEST_REQUIRES}; delete $WriteMakefileArgs{BUILD_REQUIRES}; $WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs; } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); 35_debug.t100644001750001750 670012712112457 16750 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/tuse warnings; use strict; use lib 't'; use Test::More tests => 9; use_ok('HTML::Template::Compiled'); use HTC_Utils qw($tdir &cdir &create_cache &remove_cache); my $cache_dir = "cache35"; $cache_dir = create_cache($cache_dir); sub HTML::Template::Compiled::Test::bar { return $_[0]->[0] } sub HTML::Template::Compiled::Test::baz { return $_[0]->[1] } local $HTML::Template::Compiled::DEBUG = 0; { local $HTML::Template::Compiled::DEBUG = 1; my $htc = HTML::Template::Compiled->new( scalarref => \<<'EOM', <%= /foo.bar %> <%= /foo.boo %> <%= /foo.baz %> EOM debug => 0, ); my $obj = bless [23, 24], 'HTML::Template::Compiled::Test'; $htc->param(foo => $obj); my $out; eval { $out = $htc->output; }; ok($@, "Exception"); if ($@) { #warn __PACKAGE__.':'.__LINE__.": $@\n"; my $msg = $htc->debug_code; my $msg_html = $htc->debug_code(1);; #print $msg, $/; #print $msg_html, $/; cmp_ok($msg, '=~', qr/ ERROR line (\d+)/, 'Error message'); } else { ok(0, 'Exception'); } } { my %exp = ( mc => { 0 => { count => { 1 => '### HTML::Template::Compiled Cache Debug ### FILE CACHE MISS: simple.tmpl', 2 => '### HTML::Template::Compiled Cache Debug ### FILE CACHE HIT: simple.tmpl', }, }, 1 => { count => { 1 => '### HTML::Template::Compiled Cache Debug ### MEM CACHE MISS: simple.tmpl', 2 => '### HTML::Template::Compiled Cache Debug ### MEM CACHE HIT: simple.tmpl', }, }, 2 => { count => { 1 => '### HTML::Template::Compiled Cache Debug ### MEM CACHE MISS: simple.tmpl' . '### HTML::Template::Compiled Cache Debug ### FILE CACHE MISS: simple.tmpl', 2 => '### HTML::Template::Compiled Cache Debug ### MEM CACHE HIT: simple.tmpl', }, }, }, ); for my $mc (0, 1, 2) { my $memcache = 0; my $file_cache = 1; my $file_cache_dir = $cache_dir; if ($mc == 1) { $memcache = 1; $file_cache = 0; $file_cache_dir = ''; } elsif ($mc == 2) { $memcache = 1; } my %args = ( filename => "simple.tmpl", path => $tdir, cache => $memcache, file_cache => $file_cache, file_cache_dir => $file_cache_dir, cache_debug => [qw/ mem_hit mem_miss file_hit file_miss /], ); for my $count (1..2) { my $warn = ''; { local $SIG{__WARN__} = sub { $warn .= shift; }; my $htc = HTML::Template::Compiled->new( %args, ); if ($count == 2) { $htc->clear_cache(); HTML::Template::Compiled->clear_filecache($cache_dir); } } $warn =~ s/[\r\n]//g; my $exp = $exp{mc}->{$mc}->{count}->{$count}; my $cache_string = $mc == 0 ? "file cache" : $mc == 1 ? "mem cache" : "file and mem cache"; cmp_ok($warn, 'eq', $exp, "cache=$cache_string count=$count"); } } } HTML::Template::Compiled->clear_filecache($cache_dir); remove_cache($cache_dir); 03_param.t100644001750001750 427212712112457 16757 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/t use Test::More tests => 12; BEGIN { use_ok('HTML::Template::Compiled'); use_ok('HTML::Template::Compiled::Classic'); } { local $HTML::Template::Compiled::DEFAULT_QUERY = 1; my $htc = HTML::Template::Compiled->new( path => 't/templates', scalarref => \' ', ); $htc->param( this => { is => [qw(a test for param)], returning => 'the value for a parameter', }, ); my $test = $htc->param("this"); ok($test->{is}->[3] eq 'param', "param('var')"); my @param = sort $htc->param(); #print "(@param)\n"; cmp_ok(@param, "==", 2, "param() 1"); cmp_ok($param[0], "eq", 'bar', "param() 2"); cmp_ok($param[1]||'', "eq", 'foo', "param() 2"); eval { my @query = sort $htc->query(); cmp_ok("@param", "eq", "@query", "query"); }; param_accumulates: { $htc->clear_params; $htc->param({ foo => 'foo value' }); like($htc->output, qr/foo value/); $htc->param({ bar => 'bar value' }); like($htc->output, qr/foo value/); } literal_dot_is_ok: { # To be compatible with H::T, we need # to first check if a dot is literal # part of the name before treating it magically. # This is important for a smooth upgrade path. my $htc = HTML::Template::Compiled::Classic->new( path => 't/templates', scalarref => \'', ); $htc->param('foo.bar', 'WORKS'); like($htc->output, qr/WORKS/, "HTC::Classic literal dot is OK"); } subref_variables: { my $htc = HTML::Template::Compiled::Classic->new( scalarref => \"", global_vars => 1, ); $htc->param( foo => sub { return "bar" }, loop => [{a=>23}], ); my $out = $htc->output; #print "($out)\n"; cmp_ok($out, 'eq', "bar23bar", "HTC::Classic subref variables"); } case_sensitive: { my $htc = HTML::Template::Compiled::Classic->new( scalarref => \" & ", case_sensitive => 0, ); $htc->param( foo => 'Harold', bar => 'Maude', ); my $out = $htc->output; #print "($out)\n"; cmp_ok($out, 'eq', "Harold & Maude", "HTC::Classic case_sensitive"); } } 27_chomp.t100644001750001750 165512712112457 16775 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/tuse warnings; use strict; use lib 't'; use Test::More tests => 3; use_ok('HTML::Template::Compiled'); use HTC_Utils qw($cache $tdir &cdir); { my $htc = HTML::Template::Compiled->new( scalarref => \<<'EOM', <%var foo PRE_CHOMP=3 POST_CHOMP=3 %> EOM tagstyle => [qw(+classic +asp +comment )], debug => 0, ); $htc->param(foo => 23); my $out = $htc->output; #print "out: $out\n"; cmp_ok($out, 'eq', '23232323', "chomp"); } { my $htc = HTML::Template::Compiled->new( scalarref => \<<'EOM', <%loop foo %> * <%= _ %> <%/loop PRE_CHOMP=3 POST_CHOMP=3 %> EOM tagstyle => [qw(+asp)], debug => 0, ); my $exp = <<'EOM'; * 2 * 3 * 4 EOM $htc->param(foo => [2..4]); chomp($exp); my $out = $htc->output; #print "out: $out\n"; cmp_ok($out, 'eq', $exp, "chomp loop"); } 19_query.t100644001750001750 621012712112457 17025 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/tuse warnings; use strict; use Test::More tests => 5; use lib 't'; use HTC_Utils qw($tdir &cdir &create_cache &remove_cache); my $cache_dir = "cache19"; $cache_dir = create_cache($cache_dir); # test query() (From HTML::Template test suite) use HTML::Template::Compiled; use HTML::Template::Compiled::Lazy; use File::Copy; use Fcntl qw(:seek); my $file_orig = File::Spec->catfile(qw(t templates query-test.tmpl)); my $file_copy = File::Spec->catfile(qw(t templates query-test-copy.tmpl)); copy($file_orig, $file_copy); chmod 0644, $file_copy; my $ok1 = query_template(); ok($ok1, "query 1"); #print `ls t/cache`; if (1) { my $htc = HTML::Template::Compiled::Lazy->new( scalarref => \"<%= foo%>", use_query => 1, expire_time => 1, ); my @params; eval { @params = $htc->query; }; cmp_ok("@params", 'eq', 'foo', 'HTC::Lazy and query()'); } sleep 3; { open my $fh, '+<', $file_copy or die $!; local $/; my $data = <$fh>; seek $fh, SEEK_SET, 0; truncate $fh, 0; $data =~ s/EXAMPLE_INNER_LOOP/EXAMPLE_INNER_LOOP_TEST/; print $fh $data; close $fh; } my $ok2 = query_template(); ok(!$ok2, "query 2"); #exit; sub query_template { my $template = HTML::Template::Compiled->new( path => 't/templates', filename => 'query-test-copy.tmpl', file_cache_dir => $cache_dir, file_cache => 1, expire_time => 1, use_query => 1, ); my %params; eval { %params = map {$_ => 1} $template->query(loop => 'EXAMPLE_LOOP'); }; my @result; eval { @result = $template->query(loop => ['EXAMPLE_LOOP', 'BEE']); }; my $ok = ( $@ =~ /error/ and $template->query(name => 'var') eq 'VAR' and $template->query(name => 'included_var') eq 'VAR' and #$template->query(name => 'included_var2') eq 'VAR' and $template->query(name => 'EXAMPLE_LOOP') eq 'LOOP' and exists $params{bee} and exists $params{bop} and exists $params{example_inner_loop} and $template->query(name => ['EXAMPLE_LOOP', 'EXAMPLE_INNER_LOOP']) eq 'LOOP' ); my $out = $template->output; $template->clear_cache; return $ok; print "out: $out\n"; } { # test query() (From HTML::Template test suite) my $template = HTML::Template::Compiled->new( path => 't/templates', filename => 'query-test2.tmpl', use_query => 1, ); my %p; eval { %p = map {$_ => 1} $template->query(loop => ['LOOP_FOO', 'LOOP_BAR']); }; ok(exists $p{foo} and exists $p{bar} and exists $p{bash}, "foo bar"); $template->clear_cache; } { my $template = HTML::Template::Compiled->new( path => 't/templates', filename => 'query-test2.tmpl', use_query => 0, ); my $warn = ''; { local $SIG{__WARN__} = sub { $warn .= shift }; my $test = $template->query(loop => ['LOOP_FOO', 'LOOP_BAR']); } cmp_ok($warn, '=~', qr{\QYou are using query() but have not specified that you want to use it}, "no use_query but using query()"); } unlink $file_copy; HTML::Template::Compiled->clear_filecache($cache_dir); remove_cache($cache_dir); 21_while.t100644001750001750 540512712112457 16766 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/tuse warnings; use strict; use lib qw(t); use Test::More tests => 7; use_ok('HTML::Template::Compiled'); use HTC_Utils qw($cache $tdir &cdir); { my $class = 'HTML::Template::Compiled::__Test'; my $iterator = bless [undef,[23..25]], $class; my $next = sub { my ($self) = @_; my $index = $self->[0]; my $array = $self->[1]; return unless @$array; unless (defined $index) { $self->[0] = $index = 0; } elsif ($index < $#$array) { $self->[0] = ++$index; } else { $self->[0] = undef; return; } return $array->[$index]; }; { no strict 'refs'; *{$class."::next"} = $next; } my $htc = HTML::Template::Compiled->new( filehandle => \*DATA, debug => 0, loop_context_vars => 1, ); #while (my $row = $iterator->next) { #print "row $row\n"; #} $htc->param(iterator => $iterator); my $out = $htc->output; cmp_ok($out,"=~", qr{ 23.*1odd.* 24.*2.* 25.*3odd.* 23.*1odd.* 24.*2.* 25.*3odd}xs, "while"); #print "out: $out\n"; } { my $htc = HTML::Template::Compiled->new( scalarref => \' <%each letters%><%= __key__ %>=<%= __value__ %><%/each%> <%each numbers sort=num %><%= __key__ %>=<%= __value__ %><%/each%> <%each numbers sort=num reverse=1 %><%= __key__ %>=<%= __value__ %><%/each%> <%each letters_nested sort=alpha sortby="[0]" %>sortby <%set_var val value=__value__ %>key<%= __key__ %>=<%= $val[0] %> <%/each%> <%each letters_nested2 sort=alpha sortby="letter" %>sortby2 <%set_var val value=__value__ %>key<%= __key__ %>=<%= $val.letter %> <%/each%>', debug => 0, loop_context_vars => 1, ); $htc->param(letters => { a => 1, b => 2, c => 3 }); $htc->param(numbers => { 21 => 'b', 2 => 'a', 100 => 'c' }); $htc->param(letters_nested => { 1 => ['b'], 2 => ['a'], 3 => ['c'] }); $htc->param(letters_nested2 => { 1 => {letter=>'b'}, 2 => {letter=>'a'}, 3 => {letter=>'c'} }); my $out = $htc->output; #print "out: $out\n"; cmp_ok($out, '=~', 'a=1b=2c=3', 'each alpha sort'); cmp_ok($out, '=~', '2=a21=b100=c', 'each numeric sort'); cmp_ok($out, '=~', '100=c21=b2=a', 'each numeric sort reverse'); cmp_ok($out, '=~', 'sortby key2=a sortby key1=b sortby key3=c', 'each numeric sort reverse sortby'); cmp_ok($out, '=~', 'sortby2 key2=a sortby2 key1=b sortby2 key3=c', 'each numeric sort reverse sortby2'); } __DATA__ <%with iterator%> <%while next %> <%VAR NAME="_" %> <%= __counter__ %><%if __odd__ %>odd<%/if%> <%/while%> <%while next alias=hiThere%> <%VAR NAME="$hiThere" %> <%= __counter__ %><%if __odd__ %>odd<%/if%> <%/while%> <%/with iterator%> 09_wrong.t100644001750001750 511112712112457 17012 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/t# Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl HTML-Template-Compiled.t' use Test::More tests => 11; BEGIN { use_ok('HTML::Template::Compiled') }; eval { my $htc = HTML::Template::Compiled->new( scalarref => \<<'EOM', bar <%if foo %>bar<%/if%> <%if foo %>bar EOM debug => $ENV{HARNESS_ACTIVE} ? 0 : 1, line_numbers => 1, ); }; print "err: $@\n" unless $ENV{HARNESS_ACTIVE}; ok($@ =~ m/Missing closing tag for 'IF'/, "premature end of template"); # test wrong balanced tag my $wrong; eval { $wrong = HTML::Template::Compiled->new( path => 't/templates', line_numbers => 1, filename => 'wrong.html', debug => $ENV{HARNESS_ACTIVE} ? 0 : 1, ); }; print "err: $@\n" unless $ENV{HARNESS_ACTIVE}; ok($@ =~ m/does not match opening tag/ , "wrong template"); eval { my $htc = HTML::Template::Compiled->new( path => 't/templates', filename => 'notexist.htc', debug => $ENV{HARNESS_ACTIVE} ? 0 : 1, ); }; print "err: $@\n" unless $ENV{HARNESS_ACTIVE}; ok($@ =~ m/not found/ , "template not found"); eval { my $str = <<'EOM'; EOM my $htc = HTML::Template::Compiled->new( path => 't/templates', scalarref => \$str, debug => $ENV{HARNESS_ACTIVE} ? 0 : 1, ); }; print "err: $@\n" unless $ENV{HARNESS_ACTIVE}; ok($@ =~ m/not found/ , "template from include not found"); { my @wrong = ( "", "", "", "foo", ); for my $wrong (@wrong) { eval { my $htc = HTML::Template::Compiled->new( scalarref => \$wrong, debug => 0, ); }; print STDERR "Error? $@\n" unless $ENV{HARNESS_ACTIVE};; cmp_ok($@, "=~", qr{\Q: Syntax error in tag at }, "die when syntax is wrong"); } } { my $tmpl = <<"EOM"; end EOM for my $strict (0, 1) { my $out = ''; eval { my $htc = HTML::Template::Compiled->new( scalarref => \$tmpl, strict => $strict, ); $htc->param(foo => 23); $out = $htc->output; }; my $err = $@; if ($strict) { cmp_ok($err, '=~', qr{\Q Syntax error in tag at }, "unknown tag strict"); } else { $out =~ s/\s+/ /g; my $exp = '23 5; use_ok('HTML::Template::Compiled'); use HTC_Utils qw($cache $tdir &cdir); { my $htc = HTML::Template::Compiled->new( scalarref => \<<'EOM', test <%= .array[0][0] %> Count outer: <%= .array# %> Count undef: <%= .undef# %> Count inner 1: <%= .array[0]# %> Count inner 2: <%= .array[1]# %> EOM debug => 0, ); $htc->param( array => [ [qw(a b c)], [qw(d e f g)], ], ); my $out = $htc->output; #print "out: $out\n"; cmp_ok($out, '=~', "Count outer: +2", "array count 1"); cmp_ok($out, '=~', "Count inner 1: +3", "array count 2"); cmp_ok($out, '=~', "Count inner 2: +4", "array count 3"); cmp_ok($out, '=~', "Count undef: +0", "undef array count"); } 05_filter.t100644001750001750 375212712112457 17150 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/tuse Test::More tests => 5; BEGIN { use_ok('HTML::Template::Compiled') }; HTML::Template::Compiled->ExpireTime(1); use lib 't'; use HTC_Utils qw($tdir &cdir &create_cache &remove_cache); my $cache_dir = "cache05"; $cache_dir = create_cache($cache_dir); my $filter = sub { for (${$_[0]}) { s#\{\{\{ nomen est (\w+) \}\}\}##gi; s#\{\{\{ iterate over (\w+) \}\}\}##gi; s#\{\{\{ end of iterate \}\}\}##gi; s#\{\{\{ occupy (\S+) \}\}\}##gi; }; }; my $f1 = File::Spec->catfile(qw/ t templates filter.htc /); my $f2 = File::Spec->catfile(qw/ t templates filter_included.htc /); chmod 0644, $f1; chmod 0644, $f2; my $filters = { 'sub' => $filter, }; test($filter, 1); test([$filters], 2); test($filters, 3); test($filters, 4); sub test { my ($f, $i) = @_; # test filter utime(time, time, $f2) or die $!; unless ($i == 4) { utime(time, time, $f1) or die $!; } sleep 1; my $htc; { local $SIG{__WARN__} = sub { unless ($_[0] =~ m/subroutine .* redefined/i) { print STDERR "warning: @_\n"; } }; $htc = HTML::Template::Compiled->new( path => 't/templates', filename => 'filter.htc', filter => $f, file_cache_dir => $cache_dir, file_cache => 1, ); } $htc->param( omen => 'Caesar', list => [ { bellum => 'Gallicum' }, { bellum => 'Gallicum I' }, { bellum => 'Gallicum II' }, ], ); my $exp = <<'EOM'; Name: Caesar War: Bellum Gallicum War: Bellum Gallicum I War: Bellum Gallicum II Included Name: Caesar EOM my $out = $htc->output(); cmp_ok($out, 'eq', $exp, "filter $i"); $htc->clear_cache() if $i < 3; #print "\n($out)\n($exp)\n"; delete $INC{'HTML/Template/Compiled/Filter.pm'}; no strict 'refs'; undef *{ 'HTML::Template::Compiled::Filter::filter' }; } HTML::Template::Compiled->clear_filecache($cache_dir); remove_cache($cache_dir); __END__ 17_escape.t100644001750001750 460212712112457 17121 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/t# Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl HTML-Template-Compiled.t' use Test::More tests => 6; use Data::Dumper; use File::Spec; use strict; use warnings; local $Data::Dumper::Indent = 1; local $Data::Dumper::Sortkeys = 1; BEGIN { use_ok('HTML::Template::Compiled') }; BEGIN { use_ok('HTML::Template::Compiled::Plugin::XMLEscape') }; my $cache = File::Spec->catfile('t', 'cache'); { my $htc = HTML::Template::Compiled->new( scalarref => \<<'EOM', EOM default_escape => 'HTML', debug => 0, ); my $html = ''; my $nohtml = $html; $htc->param( html => $html, nohtml => $nohtml, ); $html = HTML::Template::Compiled::Utils::escape_html($html); my $out = $htc->output; $out =~ tr/\n\r //d; #print $out,$/; cmp_ok($out, "eq", $html . $nohtml, "default_escape"); } { my $htc = HTML::Template::Compiled->new( scalarref => \<<"EOM", EOM debug => 0, ); my $foo = "test \\'foo"; $htc->param(foo => $foo); my $out = $htc->output; $out =~ tr/\n\r//d; $out =~ s/^\s*//; #print $out, $/; cmp_ok($out, 'eq', q{}, "escape=JS"); } { my $htc = HTML::Template::Compiled->new( scalarref => \<<"EOM", <%= foo escape=xml %> EOM plugin => [qw(::XMLEscape)], debug => 0, ); #warn Data::Dumper->Dump([\$htc], ['htc']); my $foo = ""; my $xml = HTML::Template::Compiled::Plugin::XMLEscape::escape_xml($foo); my $xml_attr = HTML::Template::Compiled::Plugin::XMLEscape::escape_xml_attr($foo); $htc->param(foo => $foo); my $out = $htc->output; $out =~ tr/\n\r//d; $out =~ s/^\s*//; #print $out, $/; cmp_ok($out, 'eq', qq{$xml}, "Plugin XMLEscape"); } { my $htc = HTML::Template::Compiled->new( scalarref => \<<"EOM", <%= foo escape=ijson %> EOM debug => 0, ); my $foo = q#{ "a" : "name='myvar'" }#; my $ijson = HTML::Template::Compiled::Utils::escape_ijson($foo); $htc->param(foo => $foo); my $out = $htc->output; $out =~ tr/\n\r//d; $out =~ s/^\s*//; #print $out, $/; cmp_ok($out, 'eq', qq{$ijson}, "ijson escape"); } 04_out_fh.t100644001750001750 241012712112457 17134 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/tuse Test::More tests => 5; BEGIN { use_ok('HTML::Template::Compiled') }; use lib 't'; use File::Spec; use HTC_Utils qw($tdir &cdir &create_cache &remove_cache); my $cache_dir = "cache04"; $cache_dir = create_cache($cache_dir); my $out = File::Spec->catfile('t', 'templates', 'out_fh.htc.output04'); HTML::Template::Compiled->clear_filecache($cache_dir); test('compile', 'clearcache'); test('filecache'); test('memcache', 'clearcache'); HTML::Template::Compiled->preload($cache_dir); test('after preload', 'clearcache'); sub test { my ($type, $clearcache) = @_; # test output($fh) my $htc = HTML::Template::Compiled->new( path => 't/templates', filename => 'out_fh.htc', out_fh => 1, file_cache_dir => $cache_dir, file_cache => 1, ); open my $fh, '>', $out or die $!; $htc->output($fh); close $fh; open my $f, '<', File::Spec->catfile('t', 'templates', 'out_fh.htc') or die $!; open my $t, '<', $out or die $!; local $/; my $orig = <$f>; my $test = <$t>; for ($orig, $test) { tr/\n\r//d; } ok($orig eq $test, "out_fh $type"); $htc->clear_cache() if $clearcache; # this is not portable #ok(-s $out == -s File::Spec->catfile('t', 'out_fh.htc'), "out_fh"); } unlink $out; HTML::Template::Compiled->clear_filecache($cache_dir); remove_cache($cache_dir); 16_switch.t100644001750001750 176312712112457 17166 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/t# Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl HTML-Template-Compiled.t' use Test::More tests => 4; use Data::Dumper; use File::Spec; use strict; use warnings; local $Data::Dumper::Indent = 1; local $Data::Dumper::Sortkeys = 1; BEGIN { use_ok('HTML::Template::Compiled') }; my $cache = File::Spec->catfile('t', 'cache'); { my $htc = HTML::Template::Compiled->new( scalarref => \<<'EOM', english german or french german default case french or default EOM debug => 0, ); $htc->param( lang => 'de', ); my $out = $htc->output; #print $out,$/; ok($out =~ m/german or french.*german/s, "switch 1"); cmp_ok($out,"!~","default case", "switch 2"); ok($out =~ m/french or default/s, "switch default"); } 33_plugins.t100644001750001750 546512712112457 17350 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/t use warnings; use strict; use lib 't'; use Test::More tests => 5; use HTML::Template::Compiled; use HTC_Utils qw($cache $tdir &cdir); for (0..1) { my $plug = bless( {}, 'HTC_Test' ); HTML::Template::Compiled->register($plug); sub HTC_Test::register { my ($class) = @_; my %plugs = ( escape => { TESTING => sub { my ($arg) = @_; return "$_$arg$arg"; }, }, ); return \%plugs; } my $htc = HTML::Template::Compiled->new( scalarref => \<<'EOM', <%= foo escape=testing %> EOM plugin => [$plug], debug => 0, cache => 0, ); my $string = 'string'; $htc->param( foo => $string, ); my $out = $htc->output; #print "out: $out\n"; cmp_ok($out, '=~', "$_$string$string", "plugin as object $_"); } { my $plug = bless( { 'lang' => 'en', 'map' => { en => { HELLO_WORLD => 'Hello world', }, de => { HELLO_WORLD => 'Hallo Welt', }, es => { HELLO_WORLD => 'Hola Mundo', }, }, }, 'HTC_Test2' ); HTML::Template::Compiled->register($plug); sub HTC_Test2::translate { my ($self, $id) = @_; return $self->{map}->{ $self->{lang} }->{$id}; } sub HTC_Test2::register { my ($class) = @_; my %plugs = ( tagnames => { HTML::Template::Compiled::Token::OPENING_TAG() => { TRANSLATE => [sub { exists $_[1]->{ID} }, 'ID'], }, }, compile => { TRANSLATE => { open => sub { my ($htc, $token, $args) = @_; my $OUT = $args->{out}; my $attr = $token->get_attributes; my $expression = <<"EOM"; $OUT "Translation of $attr->{ID}: "; $OUT \$t->get_plugin('HTC_Test2')->translate('\Q$attr->{ID}\E'); EOM return $expression; }, }, }, ); return \%plugs; } my $htc = HTML::Template::Compiled->new( scalarref => \<<'EOM', <%translate id="HELLO_WORLD" %> EOM plugin => [$plug], debug => 0, cache => 0, ); my $string = 'string'; for my $lang (qw/ en de es /) { $plug->{lang} = $lang; my $translated = $plug->{map}->{$lang}->{HELLO_WORLD}; my $out = $htc->output; #print "out: $out\n"; cmp_ok($out, '=~', "$translated", "plugin as object $lang"); } } HTML::Template::Compiled->clear_filecache($cache); 15_comment.t100644001750001750 405012712112457 17316 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/t# Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl HTML-Template-Compiled.t' use Test::More tests => 7; use Data::Dumper; use File::Spec; use strict; use warnings; local $Data::Dumper::Indent = 1; local $Data::Dumper::Sortkeys = 1; BEGIN { use_ok('HTML::Template::Compiled') }; my $cache = File::Spec->catfile('t', 'cache'); { my $htc = HTML::Template::Compiled->new( scalarref => \<<'EOM', this should be escaped: EOM debug => 0, ); $htc->param( comment => 1, wanted => "we want this", unwanted => "no thanks", ); my $out = $htc->output; #print $out,$/; ok( ($out !~ m/unwanted/) && $out !~ m/no thanks/ && $out =~ m/we want this/, "tmpl_comment"); $htc->clear_params(); $htc->param( noparse => 1, wanted => "we want this", unwanted => "no thanks", ); $out = $htc->output; #print $out,$/; cmp_ok($out, '=~', qr/unwanted.*unwanted/s, "tmpl_noparse 1"); cmp_ok($out, '!~', qr/no thanks/s, "tmpl_noparse 2"); cmp_ok($out, '=~', qr/we want this/s, "tmpl_noparse 3"); cmp_ok($out, '=~', qr/clear_params(); $htc->param( escape => 1, wanted => "we want this", unwanted => "no thanks", ); $out = $htc->output; #print $out,$/; like($out, qr/\Q$escaped/, "tmpl_verbatim"); } } 18_objects.t100644001750001750 366312712112457 17321 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/t use Test::More tests => 4; use strict; use warnings; local $Data::Dumper::Indent = 1; local $Data::Dumper::Sortkeys = 1; BEGIN { use_ok('HTML::Template::Compiled') }; my $cache = File::Spec->catfile('t', 'cache'); { my $htc = HTML::Template::Compiled->new( scalarref => \<<'EOM', EOM debug => 0, global_vars => 1, ); my $object = bless { content => 23, }, "HTC_Dummy"; $htc->param( outer => $object, foo => { inner => $object, }, ); my $out = $htc->output; $out =~ tr/\n\r //d; #print $out,$/; cmp_ok($out, "eq", 23 x 4, "global objects"); } eval { require Scalar::Util }; my $scalar_util = $@ ? 0 : 1; SKIP: { skip "no Scalar::Util", 2 unless $scalar_util; for my $strict (qw/ strict nostrict/) { my $htc = HTML::Template::Compiled->new( scalarref => \<<'EOM', <%= object.get_content %> <%= object.dummy %> <%= hash.key %> EOM debug => 0, global_vars => 1, objects => $strict, cache => 0, ); my $object = bless { content => 23, }, "HTC_Dummy"; $htc->param( object => $object, hash => { key => 42, }, ); my $out = ''; eval { $out = $htc->output; }; #warn __PACKAGE__.':'.__LINE__.": error: $@\n"; $out =~ s/\s+//g; #print $out,$/; if ($strict eq 'strict') { cmp_ok($@, "=~", q/Can't locate object method "dummy"/ , "global objects '$strict'"); } else { cmp_ok($out, "eq", 2342, "global objects '$strict'"); } } } sub HTC_Dummy::get_content { return $_[0]->{content}; } HTC_Utils.pm100644001750001750 120712712112457 17317 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/tpackage # hide from cpan =) HTC_Utils; use base 'Exporter'; use File::Spec; @EXPORT_OK = qw($cache $cache_lock $tdir &cdir &create_cache &remove_cache); $cache = File::Spec->catdir(qw(t cache)); $cache_lock = File::Spec->catdir(qw(t cache lock)); $tdir = File::Spec->catdir(qw(t templates)); sub cdir { File::Spec->catdir(@_) } sub create_cache { my ($dir) = @_; my $cache = File::Spec->catdir('t', $dir); mkdir $cache; return $cache; } sub remove_cache { my ($dir) = @_; $dir ||= 'cache'; my $cache = $dir; my $cache_lock = File::Spec->catdir($dir, 'lock'); unlink $cache_lock; rmdir $cache; } 1; 31_recurse.t100644001750001750 436512712112457 17333 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/tuse warnings; use strict; use lib 't'; use Test::More tests => 4; use_ok('HTML::Template::Compiled'); use HTC_Utils qw($cache $tdir &cdir); $HTML::Template::Compiled::MAX_RECURSE = 10; # default { my $htc = HTML::Template::Compiled->new( path => $tdir, filename => "recurse.html", debug => 0, ); $htc->param( content => "1", child => { content => "2", child => { content => "3", child => { content => "4", child => { content => "5", child => { content => "6", child => { content => "7", child => { content => "8", child => { content => "9", } } } } } } } } ); my $out = $htc->output; cmp_ok($out, '=~', qr#((content: (?:\d+)).*){9}#s, "recursive ok"); for my $max (9, 15) { my $out; eval { $HTML::Template::Compiled::MAX_RECURSE = $max; $htc->clear_params; $htc->param( content => "1", child => { content => "2", child => { content => "3", child => { content => "4", child => { content => "5", child => { content => "6", child => { content => "7", child => { content => "8", child => { content => "9", child => { content => "10", child => { content => "11" }, } } } } } } } } } ); $out = $htc->output; }; #print "error: $@\n"; #print "out: $out\n"; if ($max == 9) { ok($@ && $@ =~ m/recu/, "max recursion 10 > $max"); } else { cmp_ok($out, '=~', qr#((content: (?:\d+)).*){11}#s, "max recursion 10 < $max"); } } } 36_default.t100644001750001750 127312712112457 17307 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/t# Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl HTML-Template-Compiled.t' use Test::More tests => 2; BEGIN { use_ok('HTML::Template::Compiled') }; use lib 't'; use HTC_Utils qw($cache $tdir &cdir); { my $htc = HTML::Template::Compiled->new( scalarref => \<<'EOM', EOM debug => 0, loop_context_vars => 1, path => $tdir, ); $htc->param( list => [qw(a b c d e f g h)] ); my $out = $htc->output; $out =~ s/\s+/ /g; #print $out, $/; cmp_ok($out, 'eq','foo ', "loop context vars in include"); } 10_if_else.t100644001750001750 254112712112457 17260 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/tuse Test::More tests => 3; BEGIN { use_ok('HTML::Template::Compiled') }; use File::Spec; my $cache = File::Spec->catfile('t', 'cache'); HTML::Template::Compiled->clear_filecache($cache); test_defined(); test_double_else(); sub test_defined { my ($type, $clearcache) = @_; my $str = <<'EOM'; WRONGWRONGRIGHT RIGHTWRONGRIGHT RIGHTRIGHTWRONG RIGHT EOM my $htc = HTML::Template::Compiled->new( path => 't/templates', scalarref => \$str, #debug => 1, ); $htc->param( 'undef' => undef, 'zero' => 0, 'true' => 'a true value', ); my $out = $htc->output; #print $out; my @right = $out =~ m/RIGHT/g; my @wrong = $out =~ m/WRONG/g; ok(@right == 4 && @wrong == 0, "if defined"); } sub test_double_else { my $text = qq{Before. 1. 2. 3. After.}; eval { my $template = HTML::Template::Compiled->new( debug => 1, scalarref => \$text, ); }; #print $@, $/; like($@, qr/\Q'TMPL_ELSE' does not match opening tag (ELSE)/, "including 2 tags for one tmpl_if should throw an error"); } 29_encoding.t100644001750001750 232012712112457 17445 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/tuse warnings; use strict; use lib 't'; use Test::More tests => 2; use_ok('HTML::Template::Compiled'); use HTC_Utils qw($cache $tdir &cdir); eval { require URI::Escape }; my $uri = $@ ? 0 : 1; eval { require Encode }; my $encode = $@ ? 0 : 1; eval { require HTML::Entities }; my $ent = $@ ? 0 : 1; my $template = File::Spec->catfile(qw/ t templates utf8.htc /); #use Devel::Peek; SKIP: { skip "no URI::Escape, Encode, HTML::Entities installed", 1 unless $uri && $encode && $ent; open my $fh, '>:utf8', $template; my $string = <<"EOM"; test utf8: \x{f6} <%= utf8 escape=url %> <%= utf8 escape=html_all %> EOM print $fh $string; #Dump $string; close $fh; my $htc = HTML::Template::Compiled->new( filename => 'utf8.htc', path => $tdir, debug => 0, open_mode => '<:utf8', ); my $u = "ä"; $u = Encode::decode_utf8($u); $htc->param( utf8 => $u, ); my $out = $htc->output; my $test = "\x{f6}"; #Dump $test; $test = Encode::encode('utf-8', $test); #Dump $test; Encode::_utf8_on($test); #print "out: $out\n"; #Dump $out; cmp_ok($out, '=~', qr{$test.*%C3%A4.*ä}is, "uri_escape_utf8"); unlink $template; } HTC_Plugin.pm100644001750001750 475712712112457 17472 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/tuse strict; use warnings; use Data::Dumper; { package # hide from CPAN =) HTC_Plugin1; use HTML::Template::Compiled::Expression qw(:expressions); HTML::Template::Compiled->register(__PACKAGE__); sub register { my ($class) = @_; my %plugs = ( tagnames => { HTML::Template::Compiled::Token::OPENING_TAG() => { HOMER => [sub { exists $_[1]->{BEER} }, qw(BEER)], }, }, compile => { HOMER => { open => sub { my ($htc, $token, $args) = @_; my $OUT = $args->{out}; my $attr = $token->get_attributes; my $beer = $attr->{BEER}; my $varstr = $htc->get_compiler->parse_var($htc, var => $beer, method_call => $htc->method_call, deref => $htc->deref, formatter_path => $htc->formatter_path, ); my $expression = _expr_literal( <<"EOM" $OUT "Homer wants " . $varstr . " beers"; EOM ); return $expression->to_string; }, }, }, ); return \%plugs; } } #1; #__END__ { package # hide from CPAN =) HTC_Plugin2; use HTML::Template::Compiled::Expression qw(:expressions); HTML::Template::Compiled->register(__PACKAGE__); sub register { my ($class) = @_; my %plugs = ( tagnames => { HTML::Template::Compiled::Token::OPENING_TAG() => { BART => [sub { exists $_[1]->{DONUT} }, qw(DONUT)], }, }, compile => { BART => { open => sub { my ($htc, $token, $args) = @_; my $OUT = $args->{out}; my $attr = $token->get_attributes; my $beer = $attr->{DONUT}; my $varstr = $htc->get_compiler->parse_var($htc, var => $beer, method_call => $htc->method_call, deref => $htc->deref, formatter_path => $htc->formatter_path, ); my $expression = _expr_literal( <<"EOM" $OUT "Bart wants " . $varstr . " donuts"; EOM ); return $expression->to_string; }, }, }, ); return \%plugs; } } 1; examples000755001750001750 012712112457 16376 5ustar00tinatina000000000000HTML-Template-Compiled-1.003test.tt100644001750001750 155312712112457 20072 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/examples===test.html 1========================================== name: [% name %] look ma: ~ name with "": [% name %] INCLUDE: ((([% INCLUDE included.tt %]))) --------------- loop a: [% FOREACH var = loopa %]first?[% loop.first() %] or last?[% loop.last() %] -----num:[% loop.index() %] item: [% var.a %] [% END %] loop b:[% FOREACH var = loopb %]item: ROOT:[% (!loop.first && !loop.last)%][% END %] loop c --------------- [% FOREACH var = c %]----num:[% loop.index() %] [% FOREACH var = d %]*[% IF loop.first() %]first[% END %][% IF loop.last() %]last [% END %][% IF (!loop.first && !loop.last) %]inner[% END %] item: [% F %][% IF (loop.index % 2) %]odd[% END %] [% END %][% END %] --------------------- [% IF if2 %]if.if2![% END %] [% IF if3 %]if.if3! [% ELSE %]no if.if3![% END %] [% UNLESS if3 %]no if.if3!![% END %] ===test.html ende========================================== 14_scalarref.t100644001750001750 363612712112457 17626 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/tuse lib 't'; use HTC_Utils qw($tdir &cdir &create_cache &remove_cache); my $cache_dir = "cache14"; $cache_dir = create_cache($cache_dir); use Test::More tests => 6; use Data::Dumper; use File::Spec; use strict; use warnings; local $Data::Dumper::Indent = 1; local $Data::Dumper::Sortkeys = 1; BEGIN { use_ok('HTML::Template::Compiled') }; eval { require Digest::MD5 }; my $md5 = $@ ? 0 : 1; eval { require URI::Escape }; my $uri = $@ ? 0 : 1; my $hash = { URITEST => 'a b c & d', }; SKIP: { skip "no Digest::MD5", 2 unless $md5; skip "no URI::Escape", 2 unless $uri; my $text = qq{\n}; my $htc = HTML::Template::Compiled->new( scalarref => \$text, file_cache_dir => $cache_dir, file_cache => 1, ); ok($htc, "scalarref template"); $htc->param(%$hash); my $out = $htc->output; ok($out eq 'a%20b%20c%20%26%20d'.$/, "scalarref output"); } SKIP: { skip "no URI::Escape", 2 unless $uri; my $text = [qq(\n)]; my $htc = HTML::Template::Compiled->new( arrayref => $text, file_cache_dir => $cache_dir, file_cache => 1, ); ok($htc, "arrayref template"); $htc->param(%$hash); my $out = $htc->output; ok($out eq 'a%20b%20c%20%26%20d'.$/, "arrayref output"); } eval { require Encode }; my $encode = $@ ? 0 : 1; SKIP: { skip "no Encode.pm installed", 1 unless $encode; skip "bug in prove on *BSD", 1 if $] =~ /^5\.010/ and $^O =~ /^(free|open)bsd$/; #use Devel::Peek; my $string = "\x{263A} <%= foo %>"; #Dump $string; my $htc = HTML::Template::Compiled->new( scalarref => \$string, ); $htc->param(foo => "\x{263A}"); my $out = $htc->output; binmode STDOUT, ':encoding(utf-8)'; binmode STDERR, ':encoding(utf-8)'; #Dump $out; #print $out, $/; cmp_ok($out, 'eq', "\x{263A} \x{263A}", "scalarref with utf8"); } HTML::Template::Compiled->clear_filecache($cache_dir); remove_cache($cache_dir); 07_formatter.t100644001750001750 177712712112457 17675 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/t# Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl HTML-Template-Compiled.t' use Test::More tests => 2; BEGIN { use_ok('HTML::Template::Compiled::Formatter') }; my $formatter = { 'HTC::Class1' => { fullname => sub { $_[0]->first . ' ' . $_[0]->last }, first => HTC::Class1->can('first'), last => HTC::Class1->can('last'), }, }; my $htc = HTML::Template::Compiled::Formatter->new( path => 't/templates', filename => 'formatter.htc', debug => 0, ); my $obj = bless ({ first => 'Abi', last => 'Gail'}, 'HTC::Class1'); $htc->param( test => 23, obj => $obj, ); local $HTML::Template::Compiled::Formatter::formatter = $formatter; my $out = $htc->output; my $exp = <{first} } sub HTC::Class1::last { $_[0]->{last} } __END__ <%= test%> <%= obj/first %> plus <%= obj/last%> <%= obj/fullname%> 39_line_info.t100644001750001750 420512712112457 17626 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/tuse strict; use warnings; use Test::More tests => 15; BEGIN { use_ok('HTML::Template::Compiled') }; use lib 't'; use HTC_Utils qw/ $tdir &create_cache &remove_cache /; my $cache_dir = "cache39"; $cache_dir = create_cache($cache_dir); my $warning = ''; local $SIG{__WARN__} = sub { $warning = $_[0] }; for my $li (0..1) { my %args = ( filename => "line_info1.html", file_cache_dir => $cache_dir, file_cache => 1, cache => 0, path => $tdir, line_info => $li, # debug => 1, ); my $htc = HTML::Template::Compiled->new( %args, warnings => 0, ); $htc->param( foo => undef, ); my $out = $htc->output; $out =~ s/\s+/ /g; cmp_ok($out, "eq", "test test2 test3 foo: undef line 4 test4 ", "warnings 0 output ok"); cmp_ok($warning, "eq", '', "warnings 0 shouldn't produce any warnings"); HTML::Template::Compiled->clear_filecache($cache_dir); $warning = ''; $htc = HTML::Template::Compiled->new( %args, warnings => 1, ); $htc->param( foo => undef, ); $out = $htc->output; $out =~ s/\s+/ /g; cmp_ok($out, "eq", "test test2 test3 foo: undef line 4 test4 " , "warnings 1 output ok"); cmp_ok($warning, "=~", 'Use of uninitialized value', "warnings 1 should produce warnings"); if ($li) { cmp_ok($warning, '=~', "at t.templates.line_info1.html line 4", "line information"); } HTML::Template::Compiled->clear_filecache($cache_dir); $warning = ''; $htc = HTML::Template::Compiled->new( %args, warnings => 'fatal', ); $htc->param( foo => undef, ); $out = ''; eval { $out = $htc->output; }; my $error = $@; cmp_ok($out, "eq", "", "warnings fatal empty output ok"); cmp_ok($error, "=~", 'Use of uninitialized value', "warnings fatal should die"); if ($li) { cmp_ok($error, '=~', "at t.templates.line_info1.html line 4", "line information"); } HTML::Template::Compiled->clear_filecache($cache_dir); $warning = ''; } HTML::Template::Compiled->clear_filecache($cache_dir); remove_cache($cache_dir); 24_pod_cover.t100644001750001750 74712712112457 17625 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/t use Test::More; eval "use Test::Pod::Coverage 1.00"; plan skip_all => "Test::Pod::Coverage required for testing pod coverage" if $@; plan tests => 3; # thanks to mark, at least HTC::Utils is covered... pod_coverage_ok( "HTML::Template::Compiled::Utils", "HTC::Utils is covered"); pod_coverage_ok( "HTML::Template::Compiled::Plugin::XMLEscape", "HTC::Plugin::XMLEscape is covered"); pod_coverage_ok( "HTML::Template::Compiled::Classic", "HTML::Template::Compiled::Classic is covered"); 23_tagstyles.t100644001750001750 210312712112457 17667 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/tuse warnings; use strict; use lib qw(t); use Test::More tests => 4; use_ok('HTML::Template::Compiled'); use HTC_Utils qw($cache $tdir &cdir); use Fcntl qw(:seek); { local $/; my $data = ; for my $styles ( [qw(-classic +php -comment -asp +tt)], [qw(+classic -php +comment -asp -tt)], [qw(+classic -php +comment +asp -tt)], ) { my $htc = HTML::Template::Compiled->new( scalarref => \$data, tagstyle => $styles, debug => 0, cache => 0, ); my $match = ''; for my $style (@$styles) { if ($style =~ m/^\+(.*)/) { $match .= "$1: BAR\n"; } elsif ($style =~ m/^\-(.*)/) { $match .= "$1: .*foo.*\n"; } } $htc->param(foo => "BAR"); my $out = $htc->output; cmp_ok($out,"=~", qr{$match}, "tagstyle (@$styles)"); #print "out: $out\n"; } } __DATA__ classic: php: comment: asp: <%= foo %> tt: [%var foo %] test.tst100644001750001750 204312712112457 20250 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/examples===test.html 1========================================== name: <%= $name%> look ma: ~ name with "": <%= $name%> INCLUDE: (((<%= $tmpl->include("examples/included.tst") %>))) --------------- loop a: <% for my $ix (0..$#$loopa) { local $_ = $loopa->[$ix]; %> first?<%= $ix == 0 %> or last? <%= $ix == $#$loopa %> -----num:<%= $ix+1 %> item: <%= $_->{a} %> <% } %> loop b:<% for my $ix (0..$#$loopb) { my $item = $loopb->[$ix]; %>item: ROOT:<%= $item->{inner} %> <% } %> loop c --------------- <% for my $ix (0..$#$c) { my $item = $c->[$ix]; %>----num:<%= $ix %> <%for my $ix (0..$#{$item->{d}}) { my $i_item = $item->{d}->[$ix]; %> *<% if ($ix == 0) { %>first<% } %><% if ($ix == $#{$item->{d}}) { %>last <% } %><% if ($ix != 0 && $ix != $#{$item->{d}}) { %>inner<% } %> item: <%= $i_item->{F} %><% if (($ix+1) % 2) { %>odd<% } %> <% } %> <% } %> --------------------- <% if ($if2) { %>if.if2!<% } %> <% if ($if3) { %>if.if3! <% } else { %>no if.if3!<% } %> <% unless ($if3) { %>no if.if3!!<% } %> ===test.html ende========================================== bench.pl100644001750001750 4102712712112457 20176 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/examples#!/usr/bin/perl use strict; use warnings; use Getopt::Long; use Benchmark qw/ timethese cmpthese /; use FindBin qw/ $RealBin /; chdir "$RealBin/.."; #use Devel::Size qw(size total_size); my $count = 0; mkdir "cache"; mkdir "cache/htc"; mkdir "cache/htcc"; mkdir "cache/hte"; mkdir "cache/htpl"; mkdir "cache/jit"; my %use = ( 'HTML::Template' => 0, 'HTML::Template::Pro' => 0, 'HTML::Template::Compiled' => 0, 'HTML::Template::Pluggable' => 0, 'HTML::Template::Expr' => 0, 'HTML::Template::Compiled::Classic' => 0, # 'HTML::Template::JIT' => 0, 'Template' => 0, 'Template::Alloy' => 0, 'Template::HTML' => 0, 'Template::AutoFilter' => 0, 'Template::Like' => 0, 'CGI::Ex::Template' => 0, # not yet 'Text::ScriptTemplate' => 0, 'Text::Xslate' => 0, ); for my $key (sort keys %use) { eval "require $key"; $use{$key} = 1 unless $@; my $version = $use{$key} ? $key->VERSION : "-"; printf "using %35s %s\n", $key, $version; } HTML::Template::Compiled->clear_filecache("cache/htc"); HTML::Template::Compiled->clear_filecache("cache/htcc"); my $debug = 0; $ENV{'HTML_TEMPLATE_ROOT'} = "examples"; my $FILE_CACHE = 0; my $MEM_CACHE = 1; my $LOOP_CONTEXT = 1; my $GLOBAL_VARS = 0; my $CASE_SENSITIVE = 1; my $default_escape = 0; my $template_size = 1; my $bench = 'timethese'; GetOptions( "file-cache=i" => \$FILE_CACHE, "mem-cache=i" => \$MEM_CACHE, "loop-context=i" => \$LOOP_CONTEXT, "global-vars=i" => \$GLOBAL_VARS, "case-sensitive=i" => \$CASE_SENSITIVE, "default-escape=i" => \$default_escape, "template-size=i" => \$template_size, "bench=s" => \$bench, ); my $iterations = shift; my $ht_file = 'test.htc'; my $htcc_file = $ht_file . 'c'; my $tt_file = "test.tt"; my $tst_file = "test.tst"; my $xslfile = "test.xslate"; $template_size =~ tr/0-9//cd; if ($template_size > 1) { for my $file ($ht_file, $htcc_file, $tt_file, $tst_file, $xslfile) { open my $fh, "<", "examples/$file" or die "examples/$file: $!"; my $data = do { local $/; <$fh> }; my $new_file = "$file.n$template_size"; open my $out, ">", "examples/$new_file" or die $!; print $out $data x $template_size; $file = $new_file; } } print "running with: --file-cache $FILE_CACHE --mem-cache $MEM_CACHE --loop-context $LOOP_CONTEXT " . "--global-vars $GLOBAL_VARS --case-sensitive $CASE_SENSITIVE " . "--default-escape $default_escape --template-size=$template_size "; my $STDOUT = 0; sub new_htc { my $t1 = HTML::Template::Compiled->new_file( $ht_file, #path => 'examples', case_sensitive => $CASE_SENSITIVE, # slow down loop_context_vars => $LOOP_CONTEXT, $default_escape ? (default_escape => 'HTML') : (), debug => $debug, # note that you have to create the cachedir # first, otherwise it will run without cache # cache_dir => ($FILE_CACHE ? "cache/htc" : undef), file_cache_dir => ($FILE_CACHE ? "cache/htc" : undef), file_cache => ($FILE_CACHE ? 1 : undef), cache => $MEM_CACHE, out_fh => $STDOUT ? 1 : 0, global_vars => $GLOBAL_VARS, tagstyle => [qw(-asp -comment)], expire_time => 1000, ); return $t1; } sub new_htcc { my $t1 = HTML::Template::Compiled::Classic->new_file( $htcc_file, #path => 'examples', case_sensitive => $CASE_SENSITIVE, # slow down loop_context_vars => $LOOP_CONTEXT, $default_escape ? (default_escape => 'HTML') : (), debug => $debug, # note that you have to create the cachedir # first, otherwise it will run without cache cache_dir => ($FILE_CACHE ? "cache/htcc" : undef), cache => $MEM_CACHE, out_fh => $STDOUT ? 1 : 0, global_vars => $GLOBAL_VARS, debug => 0, tagstyle => [qw(-asp -comment)], expire_time => 1000, #debug => 1, ); return $t1; } sub new_tst { my $t = Text::ScriptTemplate->new(); $t->load("examples/$tst_file"); #my $size = total_size($t1); #print "size htc = $size\n"; return $t; } sub new_htp { my $t2 = HTML::Template::Pro->new( case_sensitive => $CASE_SENSITIVE, loop_context_vars => $LOOP_CONTEXT, $default_escape ? (default_escape => 'HTML') : (), #path => 'examples', filename => $ht_file, # cache => $MEM_CACHE, # $FILE_CACHE ? # (file_cache => $FILE_CACHE, # file_cache_dir => 'cache/ht') : (), global_vars => $GLOBAL_VARS, # die_on_bad_params => 0, ); return $t2; } sub new_ht { my $t2 = HTML::Template->new( case_sensitive => $CASE_SENSITIVE, loop_context_vars => $LOOP_CONTEXT, $default_escape ? (default_escape => 'HTML') : (), #path => 'examples', filename => $ht_file, cache => $MEM_CACHE, $FILE_CACHE ? (file_cache => $FILE_CACHE, file_cache_dir => 'cache/ht') : (), global_vars => $GLOBAL_VARS, die_on_bad_params => 0, blind_cache => 1, ); return $t2; } sub new_hte { my $t2 = HTML::Template::Expr->new( case_sensitive => $CASE_SENSITIVE, loop_context_vars => $LOOP_CONTEXT, $default_escape ? (default_escape => 'HTML') : (), #path => 'examples', filename => $ht_file, cache => $MEM_CACHE, $FILE_CACHE ? (file_cache => $FILE_CACHE, file_cache_dir => 'cache/hte') : (), global_vars => $GLOBAL_VARS, die_on_bad_params => 0, ); return $t2; } sub new_htpl { my $t2 = HTML::Template::Pluggable->new( case_sensitive => $CASE_SENSITIVE, loop_context_vars => $LOOP_CONTEXT, $default_escape ? (default_escape => 'HTML') : (), #path => 'examples', filename => $ht_file, cache => $MEM_CACHE, $FILE_CACHE ? (file_cache => $FILE_CACHE, file_cache_dir => 'cache/htpl') : (), global_vars => $GLOBAL_VARS, die_on_bad_params => 0, ); return $t2; } sub new_htj { my $t2 = HTML::Template::JIT->new( loop_context_vars => 1, $default_escape ? (default_escape => 'HTML') : (), #path => 'examples', filename => $ht_file, cache => 1, jit_path => 'cache/jit', #global_vars => 1, ); return $t2; } sub new_tl { my $tt= Template::Like->new( ); # $FILE_CACHE # ? ( # COMPILE_EXT => '.ttc', # COMPILE_DIR => 'cache/tt', # ) # : (), # $MEM_CACHE # ? () # : (CACHE_SIZE => 0), # INCLUDE_PATH => 'examples', #my $size = total_size($tt); #print "size tt = $size\n"; return $tt; } sub new_tt { my $tt= Template->new( $FILE_CACHE ? ( COMPILE_EXT => '.ttc', COMPILE_DIR => 'cache/tt', ) : (), $MEM_CACHE ? () : (CACHE_SIZE => 0), INCLUDE_PATH => 'examples', ); #my $size = total_size($tt); #print "size tt = $size\n"; return $tt; } sub new_ta { my $tt = Template::Alloy->new( $FILE_CACHE ? ( COMPILE_EXT => '.ttc', COMPILE_DIR => 'cache/tt', ) : (), $MEM_CACHE ? () : (CACHE_SIZE => 0), INCLUDE_PATH => 'examples', ); #my $size = total_size($tt); #print "size tt = $size\n"; return $tt; } sub new_ttaf { my $tt= Template::AutoFilter->new( $FILE_CACHE ? ( COMPILE_EXT => '.ttc', COMPILE_DIR => 'cache/tt', ) : (), $MEM_CACHE ? () : (CACHE_SIZE => 0), INCLUDE_PATH => 'examples', ); #my $size = total_size($tt); #print "size tt = $size\n"; return $tt; } sub new_tth { my $tt= Template::HTML->new( $FILE_CACHE ? ( COMPILE_EXT => '.ttc', COMPILE_DIR => 'cache/tt', ) : (), $MEM_CACHE ? () : (CACHE_SIZE => 0), INCLUDE_PATH => 'examples', ); #my $size = total_size($tt); #print "size tt = $size\n"; return $tt; } sub new_xslate { # Text::Xslate has no file caching my $t = Text::Xslate->new( $MEM_CACHE ? (cache => 2, cache_dir => "cache/xslate") : (), path => 'examples', syntax => 'TTerse', ); return $t; } sub new_cet { my $tt= CGI::Ex::Template->new( $FILE_CACHE ? ( COMPILE_EXT => '.ttc', COMPILE_DIR => 'cache/tt', ) : (), $MEM_CACHE ? () : (CACHE_SIZE => 0), INCLUDE_PATH => 'examples', ); #my $size = total_size($tt); #print "size tt = $size\n"; return $tt; } sub new_st { my $st = Text::ScriptTemplate->new; $st->load("examples/template.st"); } my %params = ( name => '', loopa => [{a=>3},{a=>4},{a=>5}], #a => [qw(b c d)], loopb => [{ inner => 23 }], c => [ { d=>[({F=>11},{F=>22}, {F=>33})] }, { d=>[({F=>44}, {F=>55}, {F=>66})] } ], if2 => 1, if3 => 0, blubber => "html ", ); open OUT, ">>/dev/null"; #open OUT, ">&STDOUT"; sub output { my $t = shift; return unless defined $t; $t->param(%params); if ($STDOUT) { my $out; if ($t=~m/Compiled/) { $out = $t->output(\*OUT); } else { $out = $t->output; } print OUT $out; } else { my $out = $t->output(); } #print "output():$out\n"; #my $size = total_size($t); #print "size $t = $size\n"; } sub output_tst { my $t = shift; return unless defined $t; $t->setq(%params,tmpl=>$t); my $out = $t->fill; #print "output_tst():$out\n"; if ($STDOUT) { print OUT $out; } } sub output_tl { my $t = shift; return unless defined $t; chdir 'examples'; my $filett = $tt_file; if ($STDOUT) { $t->process($filett, \%params, \*OUT) or die $t->error(); } else { my $out; $t->process($filett, \%params, \$out) or die $t->error(); } #my $size = total_size($t); #print "size $t = $size\n"; #my $out = $t->output; #print "\nOUT: $out"; chdir '..'; } sub output_tt { my $t = shift; return unless defined $t; my $filett = $tt_file; #$t->process($filett, \%params, \*OUT); if ($STDOUT) { $t->process($filett, \%params, \*OUT) or die $t->error(); } else { my $out; $t->process($filett, \%params, \$out) or die $t->error(); } #my $size = total_size($t); #print "size $t = $size\n"; #print $t->{code} if exists $t->{code}; #my $out = $t->output; #print "\nOUT: $out"; } sub output_ttaf { my $t = shift; return unless defined $t; my $filett = $tt_file; #$t->process($filett, \%params, \*OUT); if ($STDOUT) { $t->process($filett, \%params, \*OUT) or die $t->error(); } else { my $out; $t->process($filett, \%params, \$out) or die $t->error(); } #my $size = total_size($t); #print "size $t = $size\n"; #print $t->{code} if exists $t->{code}; #my $out = $t->output; #print "\nOUT: $out"; } sub output_xslate { my $t = shift; return unless defined $t; my $filett = $tt_file; #$t->process($filett, \%params, \*OUT); # $t->process($filett, \%params, \*OUT) or die $t->error(); #my $size = total_size($t); #print "size $t = $size\n"; #print $t->{code} if exists $t->{code}; my $out = $t->render($xslfile, \%params); #my $out = $t->output; if ($STDOUT) { print OUT $out; } } my $global_htc = $use{'HTML::Template::Compiled'} ? new_htc : undef; my $global_htcc = $use{'HTML::Template::Compiled::Classic'} ? new_htcc : undef; my $global_ht = $use{'HTML::Template'} ? new_ht : undef; my $global_htp = $use{'HTML::Template::Pro'} ? new_htp : undef; my $global_htpl = $use{'HTML::Template::Pluggable'} ? new_htpl : undef; my $global_htj = $use{'HTML::Template::JIT'} ? new_htj : undef; my $global_tt = $use{'Template'} ? new_tt : undef; my $global_ta = $use{'Template::Alloy'} ? new_ta : undef; my $global_ttaf = $use{'Template::AutoFilter'} ? new_ttaf : undef; my $global_tth = $use{'Template::HTML'} ? new_tth : undef; my $global_xslate = $use{'Text::Xslate'} ? new_xslate : undef; my $global_tl = $use{'Template::Like'} ? new_tl : undef; my $global_cet = $use{'CGI::Ex::Template'} ? new_cet : undef; my $global_tst = $use{'Text::ScriptTemplate'} ? new_tst : undef; if(1) { my %args = ( $use{'HTML::Template::Compiled'} ? ( # deactivate memory cache #new_htc_w_clear_cache => sub {my $t = new_htc();$t->clear_cache}, # normal, with memory cache # new_htc => sub {my $t = new_htc()}, #output_htc => sub {output($global_htc)}, all_htc => sub {my $t = new_htc();output($t)}, ) : (), $use{'HTML::Template::Compiled::Classic'} ? ( # deactivate memory cache #new_htc_w_clear_cache => sub {my $t = new_htc();$t->clear_cache}, # normal, with memory cache # new_htcc => sub {my $t = new_htcc()}, #output_htc => sub {output($global_htc)}, all_htcc => sub {my $t = new_htcc();output($t)}, ) : (), $use{'HTML::Template'} ? ( # new_ht => sub {my $t = new_ht()}, #output_ht => sub {output($global_ht)}, all_ht => sub {my $t = new_ht();output($t)}, ) : (), $use{'HTML::Template::Pro'} ? ( # new_htp => sub {my $t = new_htpl()}, #output_htp => sub {output($global_htp)}, all_htp => sub {my $t = new_htp();output($t)}, ) : (), $use{'HTML::Template::Pluggable'} ? ( # new_htpl => sub {my $t = new_htpl()}, #output_htpl => sub {output($global_htpl)}, all_htpl => sub {my $t = new_htpl();output($t)}, ) : (), $use{'HTML::Template::Expr'} && !$FILE_CACHE ? ( # new_hte => sub {my $t = new_hte()}, #output_hte => sub {output($global_hte)}, all_hte => sub {my $t = new_hte();output($t)}, ) : (), $use{'HTML::Template::JIT'} ? ( #new_htj => sub {my $t = new_htj();}, #output_htj => sub {output($global_htj)}, all_htj => sub {my $t = new_htj();output($t)}, ) : (), $use{'Template'} ? ( #new_tt => sub {my $t = new_tt();}, #output_tt => sub {output_tt($global_tt)}, process_tt => sub {output_tt($global_tt)}, $MEM_CACHE ? () : (all_tt_new_object => sub {my $t = new_tt();output_tt($t)}), ): (), $use{'Template::Alloy'} ? ( #new_tt => sub {my $t = new_tt();}, #output_tt => sub {output_tt($global_tt)}, process_ta => sub {output_tt($global_ta)}, $MEM_CACHE ? () : (all_ta_new_object => sub {my $t = new_ta();output_tt($t)}), ): (), $use{'Template::AutoFilter'} ? ( #new_ttaf => sub {my $t = new_ttaf();}, #output_ttaf => sub {output_ttaf($global_ttaf)}, process_ttaf => sub {output_ttaf($global_ttaf)}, $MEM_CACHE ? () : (all_ttaf_new_object => sub {my $t = new_ttaf();output_ttaf($t)}), ): (), $use{'Template::HTML'} ? ( #new_tt => sub {my $t = new_tt();}, #output_tt => sub {output_tt($global_tt)}, process_tth => sub {output_tt($global_tth)}, $MEM_CACHE ? () : (all_tth_new_object => sub {my $t = new_tth();output_tt($t)}), ): (), $use{'Text::Xslate'} ? ( #new_tt => sub {my $t = new_tt();}, #output_tt => sub {output_tt($global_tt)}, process_xslate => sub {output_xslate($global_xslate)}, $MEM_CACHE ? () : (all_xslate_new_object => sub {my $t = new_xslate();output_xslate($t)}), ): (), $use{'Template::Like'} ? ( process_tl => sub {output_tl($global_tl)}, ): (), $use{'CGI::Ex::Template'} ? ( #new_tt => sub {my $t = new_tt();}, #output_tt => sub {output_tt($global_tt)}, process_cet => sub {output_tt($global_cet)}, $MEM_CACHE ? () : (all_cet_new_object => sub {my $t = new_cet();output_tt($t)}), ): (), $use{'Text::ScriptTemplate'} ? ( #new_tst => sub {my $t = new_tst();}, #output_tst => sub {output_tst($global_tst)}, all_tst => sub {my $t = new_tst();output_tst($t)}, ): (), ); # try to align table correctly also for longer strings my %args_new; for my $key (keys %args) { my $new_key = sprintf "%21s", $key; $args_new{ $new_key } = $args{ $key }; } if ($bench eq 'timethese') { timethese ($iterations||-1, { %args_new }); } elsif ($bench eq 'cmpthese') { cmpthese ($iterations||-1, { %args_new }); } } __END__ test.htc100644001750001750 156212712112457 20221 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/examples===test.html 1========================================== name: look ma: ~ name with "": INCLUDE: ((())) --------------- loop a: first? or last? -----num: item: loop b:item: ROOT: loop c --------------- ----num: *firstlast inner item: odd --------------------- if.if2! if.if3! no if.if3! no if.if3!! ===test.html ende========================================== new_shortcuts.t100644001750001750 473212712112457 20265 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/t#!/usr/bin/perl use Test::More qw/no_plan/; use HTML::Template::Compiled; # Tests for the "new_" shortcuts new_filehandle: { open(TEMPLATE, "t/templates/simple.tmpl") || croak $!; $t = HTML::Template::Compiled->new_filehandle(*TEMPLATE); $t->param('ADJECTIVE', 'very'); like ($t->output, qr/very/ ); close(TEMPLATE); } new_file: { $t = HTML::Template::Compiled->new_file('t/templates/simple.tmpl'); $t->param('ADJECTIVE', 'very'); like ($t->output, qr/very/ ); } new_scalar_ref: { $t = HTML::Template::Compiled->new_scalar_ref( \'IIII am a simple template.' ); $t->param('ADJECTIVE', 'very'); like ($t->output, qr/very/ ); } new_array_ref: { $t = HTML::Template::Compiled->new_array_ref( ['I am a simple template.'] ); $t->param('ADJECTIVE', 'very'); like ($t->output, qr/very/ ); } type_filename: { $t = HTML::Template::Compiled->new_file('t/templates/simple.tmpl'); my $t = HTML::Template::Compiled->new( type => 'filename', source => 't/templates/simple.tmpl', ); $t->param('ADJECTIVE', 'very'); like ($t->output, qr/very/ ); } short: { use HTML::Template::Compiled short => 1; my $htc = HTC( scalarref => \"foo", ); my $out = $htc->output; cmp_ok($out, 'eq', "foo", "HTC() shortcut"); } { eval { my $t = HTML::Template::Compiled->new( type => 'filename', ); }; my $err = $@; cmp_ok($err, '=~', qr{\QHTML::Template::Compiled->new() called with 'type' parameter set, but no 'source'}); } { eval { my $t = HTML::Template::Compiled->new( type => 'nonsense', source => 't/templates/simple.tmpl', ); }; my $err = $@; cmp_ok($err, '=~', qr{\QHTML::Template::Compiled->new() : type parameter must be set to 'filename', 'arrayref', 'scalarref' or 'filehandle'}); } { eval { my $t = HTML::Template::Compiled->new_file( 't/templates/simple.tmpl', scalarref => \'test', ); }; my $err = $@; cmp_ok($err, '=~', qr{\QHTML::Template::Compiled->new called with multiple (or no) template sources specified}); } { eval { my $t = HTML::Template::Compiled->new_file( '', scalarref => \'test', ); }; my $err = $@; cmp_ok($err, '=~', qr{\QHTML::Template::Compiled->new called with empty filename parameter}); } 20_precompile.t100644001750001750 231012712112457 20004 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/tuse warnings; use strict; use Test::More tests => 4; use_ok('HTML::Template::Compiled'); use lib 't'; use HTC_Utils qw($tdir &cdir &create_cache &remove_cache); my $cache_dir = "cache20"; $cache_dir = create_cache($cache_dir); HTML::Template::Compiled->clear_filecache($cache_dir); { my $pre = 'precompiled1.tmpl'; my $scalar = <<'EOM'; Precompiled scalarref! EOM my $templates = HTML::Template::Compiled->precompile( path => $tdir, file_cache_dir => $cache_dir, file_cache => 1, filenames => [$pre, \$scalar], ); #warn Data::Dumper->Dump([\$templates], ['templates']); my $out = $templates->[0]->output; #print "out: '$out'\n"; my $out2 = $templates->[1]->output; #print "out2: '$out2'\n"; my $exp = do { open my $fh, '<', File::Spec->catfile($tdir, $pre) or die $!; local $/; <$fh>; }; tr/\r\n//d for $exp, $out, $out2, $scalar; cmp_ok(scalar @$templates, "==", 2, "precompile count"); cmp_ok($out, "eq", $exp, "precompiled output"); cmp_ok($out2, "eq", $scalar, "precompiled scalarref"); #print `ls t/cache/`; } HTML::Template::Compiled->clear_filecache($cache_dir); remove_cache($cache_dir); test.htcc100644001750001750 157312712112457 20366 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/examples===test.html 1========================================== name: look ma: ~ name with "": INCLUDE: ((())) --------------- loop a: first? or last? -----num: item: loop b:item: ROOT: loop c --------------- ----num: *firstlast inner item: odd --------------------- if.if2! if.if3! no if.if3! no if.if3!! ===test.html ende========================================== 08_global_vars.t100644001750001750 356612712112457 20164 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/t# Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl HTML-Template-Compiled.t' use Test::More tests => 4; BEGIN { use_ok('HTML::Template::Compiled') }; { my $htc = HTML::Template::Compiled->new( path => 't/templates', filehandle => \*DATA, global_vars => 1, search_path_on_include => 1, debug => 0, case_sensitive => 0, ); $htc->param( global => 42, outer => [ { loopvar => 'one', }, { loopvar => 'two', global => 23, }, { loopvar => 'three', }, ], ); my $out = $htc->output; #print $out, $/; cmp_ok($out, '=~', qr{ loopvar:\ one.*global:\ 42.*\ included:.* loopvar:\ two.*global:\ 23.*\ included:.* loopvar:\ three.*global:\ 42.*\ included:.* }xs, 'global_vars'); cmp_ok($out, "!~", "neverset", "global_vars and unset variable"); } { my $htc = HTML::Template::Compiled->new( global_vars => 2, scalarref => \< EOM debug => 0, ); $htc->param( a => { b => { inner => 23 }, c => { inner => 42 }, }, ); my $out = $htc->output; #print "($out)\n"; like($out, qr/^\s+23\s+42\s+$/, "global_vars => 2"); } __DATA__ global: loopvar: global: included: neverset 40_data_dumper.t100644001750001750 137112712112457 20142 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/tuse strict; use warnings; use Test::More tests => 2; use HTML::Template::Compiled; use lib 't'; { local $Data::Dumper::Terse = 1; local $Data::Dumper::Pad = "FOO"; my %args = ( scalarref => \<<"EOM", foo: <%= foo %> <%loop list join=", " %><%= _ %><%/loop list %> EOM cache => 0, pre_chomp => 0, post_chomp => 1, # debug => 1, ); my $htc = HTML::Template::Compiled->new( %args, ); $htc->param( foo => 23, list => [2 .. 5], ); my $out = $htc->output; #warn __PACKAGE__.':'.__LINE__.": $out\n"; cmp_ok($out, '=~', "foo: 23", "[Data::Dumper] literal template strings"); cmp_ok($out, '=~', "2, 3, 4, 5", "[Data::Dumper] 'join' strings in loops"); } 06_dyn_include.t100644001750001750 617112712112457 20157 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/tuse strict; use warnings; use Test::More tests => 19; BEGIN { use_ok('HTML::Template::Compiled') }; use lib 't'; use HTC_Utils qw($tdir &cdir &create_cache &remove_cache); my $cache_dir = "cache06"; $cache_dir = create_cache($cache_dir); my $htc = HTML::Template::Compiled->new( path => 't/templates', filename => 'dyn_include.htc', # debug => 1, # cache_debug => 1, file_cache => 1, file_cache_dir => $cache_dir, ); #exit; for my $ix (1..2,undef) { for my $count (1..2) { $htc->param( file => (defined $ix? "dyn_included$ix.htc" : undef), test => 23, ); my $out; eval { $out = $htc->output; }; if (defined $ix) { #print $out; $out =~ s/\r\n|\r/\n/g; cmp_ok($out, "=~", "Dynamic include:", "dynamic include $ix.1"); cmp_ok($out, "=~", "This is dynamically included file $ix\.", "dynamic include $ix.2"); cmp_ok($out, "=~", "23", "dynamic include $ix.3"); } else { #print "Error: $@\n"; #print "out: $out\n"; cmp_ok($out, "=~", 'Dynamic include:\s+$', "undefined filename"); } } } { my $htc = HTML::Template::Compiled->new( scalarref => \<<'EOM', inc: <%include_string foo %> EOM debug => 0, ); $htc->param( foo => 'included=<%= bar%>', bar => 'real', ); my $out = $htc->output; #print "out: $out\n"; my $exp = 'inc: included=real'; cmp_ok($out, '=~', $exp, "include_string"); } { my $htc; eval { $htc = HTML::Template::Compiled->new( filename => 'user_template.html', path => 't/templates', no_includes => 1, ); }; my $error = "$@"; cmp_ok($error, '=~', 'Syntax error.*near.*include', "no_includes"); } { my $htc = HTML::Template::Compiled->new( filename => "wrapped.html", path => 't/templates', # debug => 1, loop_context_vars => 1, cache => 0, ); $htc->param( foo => 23, ); my $out = $htc->output; my $exp = <<"EOM"; wrapper: wrapped in wrapper.html: foo: 23 wrapped in wrapper2.html: foo2: 23 wrapped in wrapper1.html: foo1: 23 EOM #warn __PACKAGE__.':'.__LINE__.": $out\n"; for ($out, $exp) { s/[\r\n]/ /g; tr/ / /s; } cmp_ok($out, 'eq', $exp, "wrapper"); $out = File::Spec->catfile('t', 'templates', 'out_fh.htc.output06'); open my $fh, '>', $out or die $!; $htc = HTML::Template::Compiled->new( filename => "wrapped.html", path => 't/templates', # debug => 1, loop_context_vars => 1, cache => 0, out_fh => 1, ); $htc->param( foo => 23, ); $htc->output($fh); close $fh; open $fh, "<", $out or die $!; my $out2 = do { local $/; <$fh> }; #warn __PACKAGE__.':'.__LINE__.": $out2\n"; for ($out2) { s/[\r\n]/ /g; tr/ / /s; } cmp_ok($out2, 'eq', $exp, "wrapper out_fh"); unlink $out; } HTML::Template::Compiled->clear_filecache($cache_dir); remove_cache($cache_dir); __END__ Dynamic include: This is dynamically included file 1. 23 objects.pl100644001750001750 332412712112457 20526 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/examples#!/usr/bin/perl package HTC::Object; use strict; use warnings; use base qw(Class::Accessor); __PACKAGE__->follow_best_practice; __PACKAGE__->mk_accessors(qw(first last age)); sub fullname { my $first = $_[0]->get_first; my $last = $_[0]->get_last; return "$last, $first"; } package main; use strict; use warnings; use HTML::Template::Compiled; use Fcntl qw(:seek); my ($template, $perlcode); { local $/; $template = ; seek DATA, 0, SEEK_SET; $perlcode = ; } my $htc = HTML::Template::Compiled->new( scalarref => \$template, tagstyle => [qw(+tt)], use_expressions => 1, ); my $persons = [ HTC::Object->new({first => 'Bart', last => 'Simpson', age => 10, hair => 'yellow'}), HTC::Object->new({first => 'Maggie', last => 'Simpson', age => 10, hair => 'yellow'}), HTC::Object->new({first => 'March', last => 'Simpson', age => 42, hair => 'purple'}), HTC::Object->new({first => 'Homer', last => 'Simpson', age => 42, hair => 'none'}), ]; $htc->param( count => scalar @$persons, items => $persons, script => $0, perlcode => $perlcode, columns => [qw/ age hair /], ); my $output = $htc->output; print $output; __DATA__ HTC example with objects

Script: [%= .script %]

Found [%= .count %] persons: [%loop .columns %]<%/loop %> [%loop items alias=person %] [%loop .columns alias=column PRE_CHOMP=3 %] [%/loop PRE_CHOMP=3 %] [%/loop items%]
Name[%= expr="ucfirst(_)" %]
[%= fullname %][%= expr="person{column}" %]


The Script:

[%= perlcode escape=html %]
test.xslate100644001750001750 156512712112457 20746 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/examples===test.html 1========================================== name: [% name %] look ma: ~ name with "": [% name %] INCLUDE: ((([% INCLUDE "included.xslate" %]))) --------------- loop a: [% FOREACH var IN loopa %]first?[% loop.first() %] or last?[% loop.last() %] -----num:[% loop.index() %] item: [% var.a %] [% END %] loop b:[% FOREACH var IN loopb %]item: ROOT:[% (!loop.first && !loop.last)%][% END %] loop c --------------- [% FOREACH var IN c %]----num:[% loop.index() %] [% FOREACH var IN d %]*[% IF loop.first() %]first[% END %][% IF loop.last() %]last [% END %][% IF (!loop.first && !loop.last) %]inner[% END %] item: [% F %][% IF (loop.index % 2) %]odd[% END %] [% END %][% END %] --------------------- [% IF if2 %]if.if2![% END %] [% IF if3 %]if.if3! [% ELSE %]no if.if3![% END %] [% UNLESS if3 %]no if.if3!![% END %] ===test.html ende========================================== test.htc.20100644001750001750 4235012712112457 20461 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/examples===test.html 1========================================== name: look ma: ~ name with "": INCLUDE: ((())) --------------- loop a: first? or last? -----num: item: loop b:item: ROOT: loop c --------------- ----num: *firstlast inner item: odd --------------------- if.if2! if.if3! no if.if3! no if.if3!! ===test.html ende========================================== ===test.html 1========================================== name: look ma: ~ name with "": INCLUDE: ((())) --------------- loop a: first? or last? -----num: item: loop b:item: ROOT: loop c --------------- ----num: *firstlast inner item: odd --------------------- if.if2! if.if3! no if.if3! no if.if3!! ===test.html ende========================================== ===test.html 1========================================== name: look ma: ~ name with "": INCLUDE: ((())) --------------- loop a: first? or last? -----num: item: loop b:item: ROOT: loop c --------------- ----num: *firstlast inner item: odd --------------------- if.if2! if.if3! no if.if3! no if.if3!! ===test.html ende========================================== ===test.html 1========================================== name: look ma: ~ name with "": INCLUDE: ((())) --------------- loop a: first? or last? -----num: item: loop b:item: ROOT: loop c --------------- ----num: *firstlast inner item: odd --------------------- if.if2! if.if3! no if.if3! no if.if3!! ===test.html ende========================================== ===test.html 1========================================== name: look ma: ~ name with "": INCLUDE: ((())) --------------- loop a: first? or last? -----num: item: loop b:item: ROOT: loop c --------------- ----num: *firstlast inner item: odd --------------------- if.if2! if.if3! no if.if3! no if.if3!! ===test.html ende========================================== ===test.html 1========================================== name: look ma: ~ name with "": INCLUDE: ((())) --------------- loop a: first? or last? -----num: item: loop b:item: ROOT: loop c --------------- ----num: *firstlast inner item: odd --------------------- if.if2! if.if3! no if.if3! no if.if3!! ===test.html ende========================================== ===test.html 1========================================== name: look ma: ~ name with "": INCLUDE: ((())) --------------- loop a: first? or last? -----num: item: loop b:item: ROOT: loop c --------------- ----num: *firstlast inner item: odd --------------------- if.if2! if.if3! no if.if3! no if.if3!! ===test.html ende========================================== ===test.html 1========================================== name: look ma: ~ name with "": INCLUDE: ((())) --------------- loop a: first? or last? -----num: item: loop b:item: ROOT: loop c --------------- ----num: *firstlast inner item: odd --------------------- if.if2! if.if3! no if.if3! no if.if3!! ===test.html ende========================================== ===test.html 1========================================== name: look ma: ~ name with "": INCLUDE: ((())) --------------- loop a: first? or last? -----num: item: loop b:item: ROOT: loop c --------------- ----num: *firstlast inner item: odd --------------------- if.if2! if.if3! no if.if3! no if.if3!! ===test.html ende========================================== ===test.html 1========================================== name: look ma: ~ name with "": INCLUDE: ((())) --------------- loop a: first? or last? -----num: item: loop b:item: ROOT: loop c --------------- ----num: *firstlast inner item: odd --------------------- if.if2! if.if3! no if.if3! no if.if3!! ===test.html ende========================================== ===test.html 1========================================== name: look ma: ~ name with "": INCLUDE: ((())) --------------- loop a: first? or last? -----num: item: loop b:item: ROOT: loop c --------------- ----num: *firstlast inner item: odd --------------------- if.if2! if.if3! no if.if3! no if.if3!! ===test.html ende========================================== ===test.html 1========================================== name: look ma: ~ name with "": INCLUDE: ((())) --------------- loop a: first? or last? -----num: item: loop b:item: ROOT: loop c --------------- ----num: *firstlast inner item: odd --------------------- if.if2! if.if3! no if.if3! no if.if3!! ===test.html ende========================================== ===test.html 1========================================== name: look ma: ~ name with "": INCLUDE: ((())) --------------- loop a: first? or last? -----num: item: loop b:item: ROOT: loop c --------------- ----num: *firstlast inner item: odd --------------------- if.if2! if.if3! no if.if3! no if.if3!! ===test.html ende========================================== ===test.html 1========================================== name: look ma: ~ name with "": INCLUDE: ((())) --------------- loop a: first? or last? -----num: item: loop b:item: ROOT: loop c --------------- ----num: *firstlast inner item: odd --------------------- if.if2! if.if3! no if.if3! no if.if3!! ===test.html ende========================================== ===test.html 1========================================== name: look ma: ~ name with "": INCLUDE: ((())) --------------- loop a: first? or last? -----num: item: loop b:item: ROOT: loop c --------------- ----num: *firstlast inner item: odd --------------------- if.if2! if.if3! no if.if3! no if.if3!! ===test.html ende========================================== ===test.html 1========================================== name: look ma: ~ name with "": INCLUDE: ((())) --------------- loop a: first? or last? -----num: item: loop b:item: ROOT: loop c --------------- ----num: *firstlast inner item: odd --------------------- if.if2! if.if3! no if.if3! no if.if3!! ===test.html ende========================================== ===test.html 1========================================== name: look ma: ~ name with "": INCLUDE: ((())) --------------- loop a: first? or last? -----num: item: loop b:item: ROOT: loop c --------------- ----num: *firstlast inner item: odd --------------------- if.if2! if.if3! no if.if3! no if.if3!! ===test.html ende========================================== ===test.html 1========================================== name: look ma: ~ name with "": INCLUDE: ((())) --------------- loop a: first? or last? -----num: item: loop b:item: ROOT: loop c --------------- ----num: *firstlast inner item: odd --------------------- if.if2! if.if3! no if.if3! no if.if3!! ===test.html ende========================================== ===test.html 1========================================== name: look ma: ~ name with "": INCLUDE: ((())) --------------- loop a: first? or last? -----num: item: loop b:item: ROOT: loop c --------------- ----num: *firstlast inner item: odd --------------------- if.if2! if.if3! no if.if3! no if.if3!! ===test.html ende========================================== ===test.html 1========================================== name: look ma: ~ name with "": INCLUDE: ((())) --------------- loop a: first? or last? -----num: item: loop b:item: ROOT: loop c --------------- ----num: *firstlast inner item: odd --------------------- if.if2! if.if3! no if.if3! no if.if3!! ===test.html ende========================================== included.tt100644001750001750 17112712112457 20655 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/examples-----INCLUDED!!! inc: [% blubber %] -----INCLUDED END!!! loop a: [% FOREACH var = loopa %] item: [% var.a %] [% END %] included.tst100644001750001750 23312712112457 21037 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/examples-----INCLUDED!!! inc: <%= $bubber%> -----INCLUDED END!!! loop a: <% for my $ix (0..$#$loopa) { local $_ = $loopa->[$ix]; %> item: <%= $_->{a} %> <% } %> bench_mem.pl100644001750001750 1227612712112457 21040 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/examples#!/usr/bin/perl use strict; use warnings; $|=1; use File::Copy; use FindBin qw/ $RealBin /; chdir "$RealBin/.."; # call perl examples/bench_mem.pl htc 1000 my ($mod, $count) = @ARGV; usage() unless $mod; mkdir "examples/mem"; mkdir "examples/memcache"; mkdir "examples/memcache/htc"; mkdir "examples/memcache/jit"; my %modules = ( tt => 'Template', ht => 'HTML::Template', htc => 'HTML::Template::Compiled', htj => 'HTML::Template::JIT', ); $count ||= 5; eval "require $modules{$mod}"; #print HTML::Template::Compiled->VERSION,$/; my %files = ( ht => 'test.htc', htc => 'test.htc', htj => 'test.htc', tt => 'test.tt', ); my @unique = keys %{ {reverse %files} }; sub new_htc { my $t = HTML::Template::Compiled->new( path => 'examples/mem', loop_context_vars => 1, filename => $_[0], cache_dir => "examples/memcache/htc", #cache => 0, ); return $t; } sub new_ht { my $t = HTML::Template->new( path => 'examples/mem', loop_context_vars => 1, filename => $_[0], cache => 1, ); return $t; } sub new_htj { my $t = HTML::Template::JIT->new( path => ['examples/mem'], loop_context_vars => 1, filename => $_[0], cache => 1, jit_path => 'examples/memcache/jit', ); return $t; } my $tt; if ($mod eq 'tt') { $tt = Template->new( COMPILE_EXT => '.ttc', COMPILE_DIR => 'examples/memcache/tt', INCLUDE_PATH => 'examples/mem', ); } sub new_tt { return $tt } my %params = ( name => '', loopa => [{a=>3},{a=>4},{a=>5}], #a => [qw(b c d)], loopb => [{ inner => 23 }], c => [ { d=>[({F=>11},{F=>22}, {F=>33})] }, { d=>[({F=>44}, {F=>55}, {F=>66})] } ], if2 => 1, if3 => 0, blubber => "html ", ); open OUT, ">>/dev/null"; #open OUT, ">&STDOUT"; my $cparam = $count; my $ht_out = sub { my $t = shift; return unless defined $t; $params{name} = (ref $t).' '.$cparam++; $t->param(%params); my $out = $t->output; $t->param({}); print OUT $out; }; my $outputs = { ht => $ht_out, htc => $ht_out, htj => $ht_out, tt => sub { my ($t,$f) = @_; return unless defined $t; #print OUT "TT $f\n"; $t->process($f, \%params, \*OUT); }, }; my $news = { tt => \&new_tt, ht => \&new_ht, htc => \&new_htc, htj => \&new_htj, }; { my $file = $files{$mod}; print "File $file\n"; -f "examples/mem/included.tt" or copy "examples/included.tt", "examples/mem/included.tt" or die $!; -f "examples/mem/included.htc" or copy "examples/included.htc", "examples/mem/included.htc" or die $!; # preprocess half of the templates my $t = process($count/2, $mod, $file); print_top("root"); for my $i (1..2) { if (my $pid = fork) { } else { print "Starting loop $i\n"; my $t = process($count, $mod, $file); print_top($i); print "End loop $i\n"; exit; } } print "Waiting for child processes to finish\n"; wait; print "Still waiting for child processes to finish\n"; wait; print "Finished child processes\n"; print_top("root"); #; } sub print_top { my $top = qx{top -b -n 1 |grep $$}; #my $top = qx{top -b -n 1 |grep perl}; chomp $top; print "\ntop($_[0]) PID $$:\n$top\n"; } sub process { my ($count, $mod, $file) = @_; for my $i ( 1 .. $count ) { my $dup = sprintf "%s.%02d", $file, $i; -f "examples/mem/$dup" or copy "examples/$file", "examples/mem/$dup" or die $!; my $t; if ($mod eq 'tt') { $t = $tt; } else { $t = $news->{$mod}->("$dup") or die $!; } #print STDERR "$mod '$t' loop '$i'\r"; $outputs->{$mod}->( $t, $dup ) or die $t->error; #select undef, undef, undef, 1/($count/5); } } sub usage { print <<"EOM"; Usage: $0 (tt|ht|htc) num Example: 100 iterations for TT: $0 tt 100 EOM exit; } __END__ -- with caching the template objects extra :!perl examples/bench_mem.pl htj 500 File test.htc htj 'tmpl_3588d6c4e3fc6254d1133a51e4c439b0' loop '500' top: 744 tina 25 0 18980 16m 10m S 0.0 3.3 0:07.74 perl :!perl examples/bench_mem.pl ht 500 File test.htc ht 'HTML::Template=HASH(0x89ae50c)' loop '500' top: 754 tina 25 0 11928 10m 2648 S 0.0 2.0 0:02.61 perl :!perl examples/bench_mem.pl tt 500 File test.tt tt 'Template=HASH(0xa184104)' loop '500' top: 759 tina 24 0 36556 34m 2668 S 0.0 6.7 0:03.15 perl :!perl examples/bench_mem.pl htc 500 File test.htc htc 'HTML::Template::Compiled=ARRAY(0x94a0f44)' loop '500' top: 764 tina 25 0 23272 21m 2732 S 0.0 4.2 0:01.54 perl -- without caching the template objects extra :!perl examples/bench_mem.pl htj 500 File test.htc htj 'tmpl_3588d6c4e3fc6254d1133a51e4c439b0' loop '500' top: 784 tina 25 0 18964 16m 10m S 0.0 3.3 0:07.76 perl :!perl examples/bench_mem.pl ht 500 File test.htc ht 'HTML::Template=HASH(0x88b62dc)' loop '500' top: 792 tina 25 0 10900 9312 2648 S 0.0 1.8 0:02.66 perl :!perl examples/bench_mem.pl tt 500 File test.tt tt 'Template=HASH(0x8366640)' loop '500' top: 797 tina 25 0 5744 4084 2668 S 0.0 0.8 0:03.62 perl :!perl examples/bench_mem.pl htc 500 File test.htc htc 'HTML::Template::Compiled=ARRAY(0x9498650)' loop '500' top: 788 tina 25 0 23256 21m 2732 S 0.0 4.2 0:01.55 perl included.htc100644001750001750 20612712112457 21003 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/examples-----INCLUDED!!! inc: -----INCLUDED END!!! loop a: item: objects.html100644001750001750 524312712112457 21061 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/examplesHTC example with objects

Script: examples/objects.pl

Found 4 persons:
NameAgeHair
Simpson, Bart 10 yellow
Simpson, Maggie 10 yellow
Simpson, March 42 purple
Simpson, Homer 42 none


The Script:

#!/usr/bin/perl

package HTC::Object;
use strict;
use warnings;
use base qw(Class::Accessor);
__PACKAGE__->follow_best_practice;
__PACKAGE__->mk_accessors(qw(first last age));
sub fullname {
            my $first = $_[0]->get_first;
            my $last = $_[0]->get_last;
            return "$last, $first";
}

package main;
use strict;
use warnings;
use HTML::Template::Compiled;
use Fcntl qw(:seek);

my ($template, $perlcode);
{
    local $/;
    $template = <DATA>;
    seek DATA, 0, SEEK_SET;
    $perlcode = <DATA>;
}

my $htc = HTML::Template::Compiled->new(
    scalarref => \$template,
    tagstyle => [qw(+tt)],
    use_expressions => 1,
);
my $persons = [
    HTC::Object->new({first => 'Bart',   last => 'Simpson', age => 10, hair => 'yellow'}),
    HTC::Object->new({first => 'Maggie', last => 'Simpson', age => 10, hair => 'yellow'}),
    HTC::Object->new({first => 'March',  last => 'Simpson', age => 42, hair => 'purple'}),
    HTC::Object->new({first => 'Homer',  last => 'Simpson', age => 42, hair => 'none'}),
];
$htc->param(
    count => scalar @$persons,
    items => $persons,
    script => $0,
    perlcode => $perlcode,
    columns => [qw/ age hair /],
);
my $output = $htc->output;
print $output;

__DATA__
<html><head><title>HTC example with objects</title></head>
<body>
<h2>Script: [%= .script %]</h2><p>
Found [%= .count %] persons:
<table>
<tr><th>Name</th>[%loop .columns %]<th>[%= expr="ucfirst(_)" %]</th><%/loop %></tr>
[%loop items alias=person %]
<tr>
    <td>[%= fullname %]</td>
    [%loop .columns alias=column PRE_CHOMP=3 %]
    <td>[%= expr="person{column}" %]</td>
    [%/loop PRE_CHOMP=3 %]
</tr>
[%/loop items%]
</table>
<hr>
<h2>The Script:</h2>
<pre>
[%= perlcode escape=html %]
</pre>
</body></html>

32_compile_plugin.t100644001750001750 110712712112457 20661 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/tuse warnings; use strict; use lib 't'; use Test::More tests => 1; use HTML::Template::Compiled; use HTC_Utils qw($cache $tdir &cdir); use HTC_Plugin; { my $htc = HTML::Template::Compiled->new( scalarref => \<<'EOM', <%homer beer=beercount %> <%bart donut=donutcount %> EOM plugin => [qw(HTC_Plugin1 HTC_Plugin2)], debug => 0, ); $htc->param( beercount => 3, donutcount => 7, ); my $out = $htc->output; #print "out: $out\n"; cmp_ok($out, '=~', qr{Homer wants 3 beers.*Bart wants 7 donuts}s, "two plugins"); } included.htcc100644001750001750 20612712112457 21146 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/examples-----INCLUDED!!! inc: -----INCLUDED END!!! loop a: item: templates000755001750001750 012712112457 17021 5ustar00tinatina000000000000HTML-Template-Compiled-1.003/twrong.html100644001750001750 15012712112457 21157 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/t/templatesBand:

songs.html100644001750001750 154512712112457 21205 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/t/templates<%= .SELF%>?lang= Band: Albums: (first) (not last)(last) (SingleAlbumOther) <%LOOP SONGS%> <%= __counter__%>. <%/LOOP%> --- Bio: Homepage: Bio: Homepage: Song 0: <%= OBJECT/key%> out_fh.htc100644001750001750 1412712112457 21100 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/t/templatestest output filter.htc100644001750001750 22512712112457 21125 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/t/templatesName: {{{ nomen est omen }}} {{{ iterate over list }}}War: Bellum {{{ nomen est bellum }}} {{{ end of iterate }}} {{{ occupy filter_included.htc }}} simple.tmpl100644001750001750 17512712112457 21333 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/t/templates Simple Template IIII am a simple template. included.xslate100644001750001750 17212712112457 21527 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/examples-----INCLUDED!!! inc: [% blubber %] -----INCLUDED END!!! loop a: [% FOREACH var IN loopa %] item: [% var.a %] [% END %] 34_loop_context_vars.t100644001750001750 437112712112457 21433 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/t # Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl HTML-Template-Compiled.t' use Test::More tests => 17; BEGIN { use_ok('HTML::Template::Compiled') }; use lib 't'; use HTC_Utils qw($cache $tdir &cdir); use strict; use warnings; my $short_tmpl = 'file_debug.html'; my $long_tmpl = cdir('subdir', 'file_debug.html'); my $short_path = cdir($tdir, $short_tmpl); my $long_path = cdir($tdir, $long_tmpl); { my $htc = HTML::Template::Compiled->new( path => $tdir, filename => $short_tmpl, cache => 0, loop_context_vars => 1, search_path_on_include => 1, debug => 0, ); my $out = $htc->output; #print $out, $/; $out =~ s/\s+/ /g; cmp_ok($out, "=~", qr#^test \Q$short_path $short_tmpl\E end#, "filename debug 1"); } { my $htc = HTML::Template::Compiled->new( path => $tdir, filename => $long_tmpl, loop_context_vars => 1, search_path_on_include => 1, cache => 0, debug => 0, ); my $out = $htc->output; #print $out, $/; $out =~ s/\s+/ /g; cmp_ok($out, "=~", qr#^test \Q$long_path $long_tmpl\E end#, "filename debug 2"); } for my $debug (qw/ start end /, 'start,end') { for my $short (0, 1) { my $debug_string = $debug; $debug_string .= ',short' if $short; my $htc = HTML::Template::Compiled->new( path => $tdir, filename => $long_tmpl, loop_context_vars => 1, search_path_on_include => 1, debug => 0, cache => 0, debug_file => $debug_string, ); my $out = $htc->output; #print $out, $/; $out =~ s/\s+/ /g; cmp_ok($out, "=~", qr#test \Q$long_path\E \Q$long_tmpl\E end#, "filename debug '$debug_string'"); my $testpath = $short ? $long_tmpl : $long_path; if ($debug =~ m/start/) { cmp_ok($out, "=~", qr##, "filename debug '$debug_string' start"); } if ($debug =~ m/end/) { cmp_ok($out, "=~", qr##, "filename debug '$debug_string' end"); } } } include.html100644001750001750 6412712112457 21432 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/t/templatesINCLUDED: wrapper.html100644001750001750 4012712112457 21461 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/t/templates<%= __wrapped__ %> wrapped.html100644001750001750 40312712112457 21466 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/t/templateswrapper: <%wrapper wrapper.html %> wrapped in wrapper.html: foo: <%= foo %> <%wrapper wrapper2.html %>wrapped in wrapper2.html: foo2: <%= foo %><%/wrapper %> <%wrapper wrapper.html %>wrapped in wrapper1.html: foo1: <%= foo %><%/wrapper %> <%/wrapper %> recurse.html100644001750001750 16012712112457 21474 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/t/templatescontent: <%= content %> <%if child %> <%with child %> <%include recurse.html %> <%/with child %> <%/if child %> formatter.htc100644001750001750 10312712112457 21636 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/t/templates<%= test%> <%= obj/first %> plus <%= obj/last%> <%= obj/fullname%> wrapper2.html100644001750001750 4212712112457 21545 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/t/templates<%= __wrapped__ %> subdir000755001750001750 012712112457 20311 5ustar00tinatina000000000000HTML-Template-Compiled-1.003/t/templatesb.html100644001750001750 4212712112457 21514 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/t/templates/subdirthis is t/templates/subdir/b.html query-test.tmpl100644001750001750 72012712112457 22160 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/t/templates file_debug.html100644001750001750 6612712112457 22076 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/t/templatestest <%= __filename__ %> <%= __filenameshort__ %> end dyn_include.htc100644001750001750 5212712112457 22113 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/t/templatesDynamic include: line_info1.html100644001750001750 6312712112457 22031 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/t/templatestest test2 test3 foo:<%= foo %> undef line 4 test4 include_perl.htc100644001750001750 4512712112457 22265 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/t/templates<%perl __OUT__ "this is perl!\n"; %> var_include.html100644001750001750 1412712112457 22275 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/t/templates<%= $FOO %> query-test2.tmpl100644001750001750 43312712112457 22243 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/t/templates 01_HTML-Template-Compiled.t100644001750001750 767312712112457 21734 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/tuse strict; use warnings; use Test::More tests => 6; use Data::Dumper; local $Data::Dumper::Indent = 1; local $Data::Dumper::Sortkeys = 1; BEGIN { use_ok('HTML::Template::Compiled') }; use Fcntl qw(:seek); use File::Copy qw(copy); use lib 't'; use HTC_Utils qw($tdir &cdir &create_cache &remove_cache); my $cache_dir = "cache01"; $cache_dir = create_cache($cache_dir); my $hash = { SELF => '/path/to/script.pl', LANGUAGE => 'de', BAND => 'Bauhaus', ALBUMS => [ { ALBUM => 1, NAME => 'Mask', SONGS => [ { NAME => 'Hair of the Dog' }, { NAME => 'Passion of Lovers' }, ], }, ], INFO => { BIOGRAPHY => undef, LINK => 'http://...' }, OBJECT => bless({ '_key' => 23, }, "HTC::Test"), URITEST => 'a b c & d', }; sub HTC::Test::key { return $_[0]->{"_key"} } my $include_orig = cdir($tdir,'include.html'); my $include = cdir($tdir,'include_copy.html'); copy($include_orig, $include) or die $!; chmod 0644, $include; my %args = ( path => $tdir, #case_insensitive => 1, case_sensitive => 0, loop_context_vars => 1, line_numbers => 1, filename => 'songs.html', # debug => $ENV{HARNESS_ACTIVE} ? 0 : 1, # for testing without cache comment out file_cache_dir => $cache_dir, file_cache => 1, #cache => 0, #search_path_on_include => 1, expire_time => 2, ); sleep 3; @HTML::Template::Compiled::subclass::ISA = qw(HTML::Template::Compiled); my $subclass = 'HTML::Template::Compiled::subclass'; sub HTML::Template::Compiled::subclass::method_call { '/' } sub HTML::Template::Compiled::subclass::deref { '.' } HTML::Template::Compiled->clear_filecache($cache_dir); my $htc = $subclass->new(%args); ok($htc, "template created"); my $time_before = time; $htc->param(%$hash); eval { require URI::Escape }; my $uri = $@ ? 0 : 1; SKIP: { skip "no URI::Escape installed", 3, unless ($uri); my $out = $htc->output; my $dump = <<'EOM'; $DUMP = { 'biography' => undef, 'link' => 'http://...' }; EOM $dump = HTML::Template::Compiled::Utils::escape_html($dump); my $exp = <<'EOM' . $dump . <<'EOM'; /path/to/script.pl?lang=de Band: Bauhaus Albums: (first) (last) Mask (Album) 1. Hair of the Dog 2. Passion of Lovers --- Bio: No bio available Homepage: http://... EOM Bio: No "bio" available Homepage: http://... Song 0: Hair of the Dog a%20b%20c%20%26%20d INCLUDED: Hair of the Dog 23 23 EOM for ($exp, $out) { s/^\s+//mg; tr/\n\r//d; } cmp_ok($out, "eq", $exp, "output ok"); open my $fh, '+<', $include or die $!; local $/; my $txt = <$fh>; $txt =~ s/INCLUDED/INCLUDED_NEW/; seek $fh, 0, SEEK_SET; truncate $fh, 0; print $fh $txt; close $fh; my $htc = $subclass->new(%args); $htc->param(%$hash); $out = $htc->output; my $time_after = time; if ($time_after - $time_before >= 2) { # took too long, cache expired, just return ok ok(1, "output after update skipped"); } else { $out =~ s/^\s+//mg; $out =~ tr/\n\r//d; cmp_ok($out, "eq", $exp, "output after update ok"); } $exp =~ s/INCLUDED/INCLUDED_NEW/; sleep 2; my $mtime = (stat $include)[9]; my $now = time; $htc = $subclass->new(%args); $htc->param(%$hash); $out = $htc->output; $out =~ s/^\s+//mg; $out =~ tr/\n\r//d; cmp_ok($out,"eq", $exp, "output after update & sleep ok"); unless ($out eq $exp) { # try to output helpful informations for debugging diag( sprintf "File modification time $include: %s Now: %s", scalar localtime $mtime, scalar localtime $now, ); } open $fh, '+<', $include or die $!; local $/; $txt = <$fh>; $txt =~ s/INCLUDED_NEW/INCLUDED/; seek $fh, 0, SEEK_SET; truncate $fh, 0; print $fh $txt; close $fh; } { open my $fh, '<', $include or die $!; my $htc = $subclass->new( filehandle => $fh, ); $htc->param(%$hash); my $out = $htc->output; #print STDERR "out: '$out'\n"; cmp_ok($out, "eq", "INCLUDED: Hair of the Dog\n", "filehandle output"); } HTML::Template::Compiled->clear_filecache($cache_dir); remove_cache($cache_dir); unlink $include; dyn_included2.htc100644001750001750 6512712112457 22345 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/t/templatesThis is dynamically included file 2. precompiled1.tmpl100644001750001750 1512712112457 22377 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/t/templatesPrecompiled! dyn_included1.htc100644001750001750 6512712112457 22344 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/t/templatesThis is dynamically included file 1. Template000755001750001750 012712112457 17645 5ustar00tinatina000000000000HTML-Template-Compiled-1.003/lib/HTMLCompiled.pm100644001750001750 30542512712112457 22150 0ustar00tinatina000000000000HTML-Template-Compiled-1.003/lib/HTML/Templatepackage HTML::Template::Compiled; our $VERSION = '1.003'; # VERSION use Data::Dumper; use Scalar::Util; BEGIN { use constant D => $ENV{HTC_DEBUG} || 0; } use strict; use warnings; use Digest::MD5 qw/ md5_hex /; use Carp; use Fcntl qw(:seek :flock); use File::Spec; use File::Basename qw(dirname basename); use HTML::Template::Compiled::Utils qw(:walkpath :log :escape &md5); use HTML::Template::Compiled::Expression qw(:expressions); use HTML::Template::Compiled::Compiler; # TODO eval { require URI::Escape; }; #eval { # require Encode; #}; #my $Encode = $@ ? 0 : 1; use base 'Exporter'; our @EXPORT_OK = qw(&HTC); use HTML::Template::Compiled::Parser qw( $CASE_SENSITIVE_DEFAULT $NEW_CHECK $DEBUG_DEFAULT $SEARCHPATH %FILESTACK %COMPILE_STACK %PATHS $DEFAULT_ESCAPE $DEFAULT_QUERY $UNTAINT $DEFAULT_TAGSTYLE $MAX_RECURSE ); use vars qw($__ix__); use constant MTIME => 0; use constant CHECKED => 1; use constant LMTIME => 2; use constant LCHECKED => 3; use constant DEBUG_COMPILED => 0b001; use constant DEBUG_CACHE_FILE_MISS => 0b0001; use constant DEBUG_CACHE_FILE_HIT => 0b0010; use constant DEBUG_CACHE_MEM_MISS => 0b0100; use constant DEBUG_CACHE_MEM_HIT => 0b1000; our $DEBUG = 0; our $LAST_EXCEPTION; # options / object attributes use constant PARAM => 0; BEGIN { my @map = ( undef, qw( path md5_path filename file scalar filehandle file_cache cache_dir cache search_path loop_context case_sensitive global_vars default_path debug debug_file objects perl out_fh default_escape filter formatter globalstack use_query parse_tree parser compiler includes plugins open_mode chomp expire_time strict warnings line_info args optimize ) #use_expressions ); for my $i ( 1 .. $#map ) { my $method = "_$map[$i]"; my $get = sub { return $_[0]->[$i] }; my $set; $set = sub { $_[0]->[$i] = $_[1] }; no strict 'refs'; *{"get$method"} = $get; *{"set$method"} = $set; } } # tired of typing? sub HTC { __PACKAGE__->new(@_) } sub new { my ( $class, %args ) = @_; D && $class->log("new()"); # handle the "type", "source" parameter format (does anyone use it?) if ( exists $args{type} ) { exists $args{source} or $class->_error_no_source(); $args{type} =~ m/^(?:filename|scalarref|arrayref|filehandle)$/ or $class->_error_wrong_source(); $args{ $args{type} } = $args{source}; delete $args{type}; delete $args{source}; } if (exists $args{filename}) { return $class->new_file($args{filename}, %args); } elsif (exists $args{scalarref}) { return $class->new_scalar_ref($args{scalarref}, %args); } elsif (exists $args{filehandle}) { return $class->new_filehandle($args{filehandle}, %args); } elsif (exists $args{arrayref}) { return $class->new_array_ref($args{arrayref}, %args); } croak("$class->new called with not enough arguments"); } sub _error_no_query { my ($self) = @_; my $class = ref $self || $self; carp "You are using query() but have not specified that you want to use it" . " (specify with use_query => 1)"; } sub _error_not_compiled { my ($self) = @_; my $class = ref $self || $self; carp "Template was not compiled yet"; } sub _error_wrong_source { my ($self) = @_; my $class = ref $self || $self; croak("$class->new() : type parameter must be set to 'filename', " . "'arrayref', 'scalarref' or 'filehandle'!"); } sub _error_no_source { my ($self) = @_; my $class = ref $self || $self; croak("$class->new() called with 'type' parameter set," . " but no 'source'!"); } sub _error_template_sources { my ($self) = @_; my $class = ref $self || $self; croak( "$class->new called with multiple (or no) template sources specified!" . "A valid call to new() has exactly ne filename => 'file' OR exactly one" . " scalarref => \\\$scalar OR exactly one arrayref => \\\@array OR" . " exactly one filehandle => \*FH" ); } sub _error_empty_filename { my ($self) = @_; my $class = ref $self || $self; croak("$class->new called with empty filename parameter!"); } sub new_from_perl { my ($class, %args) = @_; my $self = bless [], $class; $self->init_args(\%args); D && $self->log("new(perl) filename: $args{filename}"); $self->init_cache(\%args); $self->init(%args); $self->set_perl( $args{perl} ); $self->set_filename( $args{filename} ); my $md5path = md5_hex(@{ $args{path} || [] }); $self->set_path( $args{path} ); $self->set_md5_path( $md5path ); $self->set_scalar( $args{scalarref} ); unless ( $self->get_scalar ) { my $file = $self->createFilename( $self->get_path, \$self->get_filename ); $self->set_file($file); } return $self; } sub new_file { my ($class, $filename, %args) = @_; my $self = bless [], $class; $self->init_args(\%args); $args{path} = $self->build_path($args{path}); $self->_error_empty_filename() if (!defined $filename or !length $filename); $args{filename} = $filename; if (exists $args{scalarref} || exists $args{arrayref} || exists $args{filehandle}) { $self->_error_template_sources; } $self->set_filename( $filename ); $self->init_cache(\%args); my $md5path = md5_hex(@{ $args{path} || [] }); $self->set_path( $args{path} ); $self->set_md5_path( $md5path ); if (my $t = $self->from_cache(\%args)) { $t->init_includes(); return $t; } $self->init(%args); $self->from_scratch; $self->init_includes; return $self; } sub new_filehandle { my ($class, $filehandle, %args) = @_; my $self = bless [], $class; $self->init_args(\%args); if (exists $args{scalarref} || exists $args{arrayref} || exists $args{filename}) { $self->_error_template_sources; } $args{filehandle} = $filehandle; $args{path} = $self->build_path($args{path}); $self->set_filehandle( $args{filehandle} ); $args{cache} = 0; $self->init_cache(\%args); my $md5path = md5_hex(@{ $args{path} || [] }); $self->set_path( $args{path} ); $self->set_md5_path( $md5path ); if (my $t = $self->from_cache(\%args)) { return $t; } $self->init(%args); $self->from_scratch; $self->init_includes; return $self; } sub new_array_ref { my ($class, $arrayref, %args) = @_; if (exists $args{scalarref} || exists $args{filehandle} || exists $args{filename}) { $class->_error_template_sources; } my $scalarref = \( join '', @$arrayref ); delete $args{arrayref}; return $class->new_scalar_ref($scalarref, %args); } sub new_scalar_ref { my ($class, $scalarref, %args) = @_; my $self = bless [], $class; $self->init_args(\%args); if (exists $args{arrayref} || exists $args{filehandle} || exists $args{filename}) { $self->_error_template_sources; } $args{scalarref} = $scalarref; $args{path} = $self->build_path($args{path}); $self->init_cache(\%args); $self->set_scalar( $args{scalarref} ); my $text = $self->get_scalar; my $md5 = md5($$text); # if ($args{cache} and !$md5) { # croak "For caching scalarrefs you need Digest::MD5"; # } $self->set_filename($md5); D && $self->log("md5: $md5"); my $md5path = md5_hex(@{ $args{path} || [] }); $self->set_path( $args{path} ); $self->set_md5_path( $md5path ); if (my $t = $self->from_cache(\%args)) { return $t; } $self->init(%args); $self->from_scratch; $self->init_includes; return $self; } sub init_includes { my ($self) = @_; my $includes = $self->get_includes; my $cache = $self->get_cache_dir||''; for my $fullpath (keys %$includes) { my ($path, $filename, $htc) = @{ $includes->{$fullpath} }; D && $self->log("checking $fullpath ($filename) $htc?"); # TODO check $cache $cache .= '-' . $self->get_md5_path; #warn __PACKAGE__.':'.__LINE__.": init_includes() $filename\n"; if (not $htc or HTML::Template::Compiled::needs_new_check($cache||'',$filename, $self->get_expire_time) ) { $htc = $self->new_from_object($path,$filename,$fullpath,$cache); } $includes->{$fullpath}->[2] = $htc; $includes->{$fullpath}->[2]->set_plugins($self->get_plugins); } } sub build_path { my ($self, $path) = @_; unless (defined $path) { $path = []; } elsif (!ref $path) { $path = [$path]; } defined $ENV{'HTML_TEMPLATE_ROOT'} and push @$path, $ENV{'HTML_TEMPLATE_ROOT'}; return $path; } sub from_scratch { my ($self) = @_; D && $self->log("from_scratch filename=".$self->get_filename); my $fname = $self->get_filename; if ( defined $fname and !$self->get_scalar and !$self->get_filehandle ) { #D && $self->log("tried from_cache() filename=".$fname); my $file = $self->createFilename( $self->get_path, \$fname ); D && $self->log("set_file $file ($fname)"); $self->set_file($file); } elsif ( defined $fname ) { $self->set_file($fname); } D && $self->log( "compiling... " . $self->get_filename ); $self->compile(); return $self; } sub from_cache { my ($self, $args) = @_; my $t; D && $self->log( "from_cache() filename=" . $self->get_filename ); $args ||= {}; my $plug = $args->{plugin} || []; my $debug = $self->get_debug || $args->{debug}; # try to get memory cache if ( $self->get_cache ) { my $dir = $self->get_cache_dir; $dir = '' unless defined $dir; $dir .= '-' . $self->get_md5_path; my $fname = $self->get_filename; $t = $self->from_mem_cache($dir,$fname, $args); if ($t) { $t->set_args($args); if (@$plug) { $t->set_plugins($plug); $t->load_plugins($plug); } if ($debug->{cache} & DEBUG_CACHE_MEM_HIT) { warn "### HTML::Template::Compiled Cache Debug ### MEM CACHE HIT: $fname\n"; } return $t; } # warn __PACKAGE__.':'.__LINE__.": not in mem cache: $fname\n"; if ($debug->{cache} & DEBUG_CACHE_MEM_MISS) { warn "### HTML::Template::Compiled Cache Debug ### MEM CACHE MISS: @{[ $self->get_filename ]}\n"; } } D && $self->log( "from_cache() 2 filename=" . $self->get_filename ); # not in memory cache, try file cache if ( $self->get_cache_dir ) { my $file = $self->get_scalar || $self->get_filehandle ? $self->get_filename : $self->createFilename( $self->get_path, \$self->get_filename ); my $dir = $self->get_cache_dir; if (defined $dir and not -d $dir) { croak "Cachedir '$dir' does not exist"; } $t = $self->from_file_cache($dir, $file); if ($t) { $t->set_args($args); if (@$plug) { $t->set_plugins($plug); $t->load_plugins($plug); } if ($debug->{cache} & DEBUG_CACHE_FILE_HIT) { warn "### HTML::Template::Compiled Cache Debug ### FILE CACHE HIT: @{[ $self->get_filename ]}\n"; } return $t; } if ($debug->{cache} & DEBUG_CACHE_FILE_MISS) { warn "### HTML::Template::Compiled Cache Debug ### FILE CACHE MISS: @{[ $self->get_filename ]}\n"; } } D && $self->log( "from_cache() 3 filename=" . $self->get_filename ); return; } { my $cache; # { # $cachedir => { # $filename => $htc_object, my $times; sub needs_new_check { my ($dir, $fname, $expire_time) = @_; my $times = $times->{$dir}->{$fname} or return 1; my $now = time; return 0 if $now - $times->{checked} < $expire_time; return 1; } sub from_mem_cache { my ($self, $dir, $fname, $args) = @_; my $cached = $cache->{$dir}->{$fname}; my $times = $times->{$dir}->{$fname}; D && $self->log("\$cached=$cached \$times=$times \$fname=$fname\n"); if ( $cached && $self->uptodate($times, $args) ) { return $cached->clone; } D && $self->log("no or old memcache"); return; } sub _debug_cache { my ($self) = @_; my $dir = $self->get_cache_dir; my $objects = $cache->{$dir}; my $times = $times->{$dir}; warn Data::Dumper->Dump([\$times], ['times']); my @keys = keys %$objects; warn Data::Dumper->Dump([\@keys], ['keys']); } sub add_mem_cache { my ( $self, %times ) = @_; D && $self->stack(1); my $dir = $self->get_cache_dir; $dir = '' unless defined $dir; my @c = caller(); $dir .= '-' . $self->get_md5_path; my $fname = $self->get_filename; D && $self->log( "add_mem_cache $fname" ); my $clone = $self->clone; $clone->clear_params(); my @plugs = @{ $self->get_plugins || [] }; for my $i (0 .. $#plugs) { if (ref $plugs[$i]) { if ($plugs[$i]->can('serialize')) { $plugs[$i] = $plugs[$i]->serialize(); } } } $clone->set_plugins(\@plugs); $cache->{$dir}->{$fname} = $clone; $times->{$dir}->{$fname} = \%times; } sub clear_cache { my $dir = $_[0]->get_cache_dir; # clear the whole cache $cache = {}, $times = {}, return unless defined $dir; # only specific directory $cache->{$dir} = {}; $times->{$dir} = {}; } sub clear_filecache { my ( $self, $dir ) = @_; defined $dir or $dir = $self->get_cache_dir; return unless -d $dir; ref $self and $self->lock; opendir my $dh, $dir or die "Could not open '$dir': $!"; my @files = grep { m/(\.pl|\.storable)$/ } readdir $dh; for my $file (@files) { my $file = File::Spec->catfile( $dir, $file ); unlink $file or die "Could not delete '$file': $!"; } ref $self and $self->unlock; return 1; } sub uptodate { my ( $self, $cached_times, $args ) = @_; return 1 if $self->get_scalar; my $expire_time = $self->get_expire_time; $expire_time = $args->{expire_time} unless defined $expire_time; # unless ($cached_times) { # my $dir = $self->get_cache_dir; # $dir = '' unless defined $dir; # my $fname = $self->get_filename; # my $cached = $cache->{$dir}->{$fname}; # $cached_times = $times->{$dir}->{$fname}; # return unless $cached; # } my $now = time; if ( $now - $cached_times->{checked} < $expire_time ) { return 1; } else { my $file = $self->createFilename( $self->get_path, \$self->get_filename ); $self->set_file($file); #print STDERR "uptodate($file)\n"; my @times = $self->_checktimes($file); if ( $times[MTIME] <= $cached_times->{mtime} ) { D && $self->log("uptodate template old"); # set last check time to new value $cached_times->{checked} = $now; return 1; } } # template is not up to date, re-compile it return 0; } } sub compile { my ($self) = @_; my ( $source, $compiled ); my $compiler = $self->get_compiler; if ( my $file = $self->get_file and !$self->get_scalar ) { D && $self->log( "compile from file " . $file ); die "Could not open '$file': $!" unless -f $file; my @times = $self->_checktimes($file); my $text = $self->_readfile($file); my ( $source, $compiled ) = $compiler->compile( $self, $text, $file ); $self->set_perl($compiled); $self->get_cache and $self->add_mem_cache( checked => time, mtime => $times[MTIME], ); D && $self->log("compiled $file"); if ( $self->get_cache_dir ) { D && $self->log("add_file_cache($file)"); $self->add_file_cache( $source, checked => time, mtime => $times[MTIME], ); } } elsif ( my $text = $self->get_scalar ) { my $md5 = $self->get_filename; # yeah, weird D && $self->log("compiled $md5"); my ( $source, $compiled ) = $compiler->compile( $self, $$text, $md5 ); $self->set_perl($compiled); if ( $self->get_cache_dir ) { D && $self->log("add_file_cache($file)"); $self->add_file_cache( $source, checked => time, mtime => time, ); } } elsif ( my $fh = $self->get_filehandle ) { local $/; my $data = <$fh>; my ( $source, $compiled ) = $compiler->compile( $self, $data, '' ); $self->set_perl($compiled); } } sub add_file_cache { my ( $self, $source, %times ) = @_; $self->lock; my $cache = $self->get_cache_dir; if (defined $cache and not -d $cache) { croak "Cachedir '$cache' does not exist"; } my $plfile = $self->escape_filename( $self->get_file ); my $filename = $self->get_filename; my $lmtime = localtime $times{mtime}; my $lchecked = localtime $times{checked}; my $cachefile = "$cache/$plfile"; D && $self->log("add_file_cache() $cachefile"); { require Storable; require B::Deparse; local $Storable::Deparse = 1; my $clone = $self->clone; $clone->prepare_for_cache; my $v = $self->VERSION || '0.01'; my $to_cache = { htc => $clone, version => $v, times => { mtime => $times{mtime}, checked => $times{checked}, }, }; Storable::store($to_cache, "$cachefile.storable"); } $self->unlock; } sub get_plugin { my ($self, $class) = @_; for my $plug (@{ $self->get_plugins || [] }) { return $plug if (ref $plug || $plug) eq $class; } return; } sub from_file_cache { my ($self, $dir, $file) = @_; D && $self->stack; D && $self->log("include file: $file"); my $escaped = $self->escape_filename($file); my $req = File::Spec->catfile( $dir, "$escaped.storable" ); return unless -f $req; return $self->include_file($req); } sub include_file { my ( $self, $req ) = @_; D && $self->log("do $req"); my $r; my $t; { require Storable; require B::Deparse; local $Storable::Eval = 1; my $cache; eval { $cache = Storable::retrieve($req); }; #warn __PACKAGE__.':'.__LINE__.": error? $@\n"; return if $@; my $cached_version = $cache->{version}; $t = $cache->{htc}; if (($t->VERSION || '0.01') ne $cached_version || !$t->uptodate( $cache->{times} )) { # is not uptodate return; } my $plug = $t->get_plugins || []; $t->get_cache and $t->add_mem_cache( checked => $cache->{times}->{checked}, mtime => $cache->{times}->{mtime}, ); } return $t; } sub createFilename { my ( $self, $path, $filename_ref, $cwd ) = @_; my $filename = $$filename_ref; D && $self->log("createFilename($path,$filename)"); D && $self->stack(1); #warn __PACKAGE__.':'.__LINE__.": ---- createFilename($path, $$filename_ref, $cwd)\n"; if ($path) { local $" = "\0"; my $cached = $PATHS{"@$path"}->{$filename}; return $cached if defined $cached; } if ( !$path or (File::Spec->file_name_is_absolute($filename) && -f $filename) ) { return $filename; } else { D && $self->log( "file: " . File::Spec->catfile( $path, $filename ) ); if ($path && @$path) { my @search = @$path; for ( @search ) { my $fp = File::Spec->catfile( $_, $filename ); if (-f $fp) { local $" = "\0"; $PATHS{"@$path"}->{$filename} = $fp; return $fp; } } # not found in $path, try current template dir if (defined $cwd) { my $fp = File::Spec->catfile( $cwd, $filename ); if (-f $fp) { for my $p (@search) { if ($fp =~ m{^\Q$p\E(.*)}) { my $rest = $1; my (undef, @p) = File::Spec->splitdir($rest); $rest = File::Spec->catfile(@p); $$filename_ref = $rest; $PATHS{"@$path"}->{$rest} = $fp; } } return $fp; } } } elsif (-f $filename) { $PATHS{''}->{$filename} = $filename; return $filename; } # TODO - bug with scalarref croak "'$filename' not found"; } } sub dump { my ( $self, $var ) = @_; require Data::Dumper; local $Data::Dumper::Indent = 1; local $Data::Dumper::Sortkeys = 1; return Data::Dumper->Dump( [$var], ['DUMP'] ); } sub dump_var { my ($class, $var, $varname) = @_; local $Data::Dumper::Terse = 0; local $Data::Dumper::Indent = 2; local $Data::Dumper::Purity = 0; local $Data::Dumper::Pad = ""; local $Data::Dumper::Useqq = 0; local $Data::Dumper::Deepcopy = 0; local $Data::Dumper::Quotekeys = 1; local $Data::Dumper::Bless = 'bless'; local $Data::Dumper::Pair = ' => '; local $Data::Dumper::Maxdep = 0; local $Data::Dumper::Useperl = 0; local $Data::Dumper::Sortkeys = 1; return Data::Dumper->Dump( [$var], [$varname] ); } sub init_cache { my ($self, $args) = @_; my $cachedir = $args->{file_cache_dir}; if ($args->{file_cache}) { $self->set_cache_dir($cachedir) if $args->{file_cache}; } $self->set_cache( exists $args->{cache} ? $args->{cache} : 1 ); } sub init_args { my ($self, $args) = @_; if (exists $args->{cache_dir}) { # will soon be deprecated $args->{file_cache_dir} = delete $args->{cache_dir}; unless (exists $args->{file_cache}) { # warn in future versions $args->{file_cache} = 1; } } if ($args->{plugin} and (ref $args->{plugin}) ne 'ARRAY') { $args->{plugin} = [$args->{plugin}]; } my $debug_cache_args = delete $args->{cache_debug} || 0; my $debug_cache = 0; if ($debug_cache_args) { unless (ref $debug_cache_args) { # no array ref, just a true value $debug_cache |= DEBUG_CACHE_FILE_MISS | DEBUG_CACHE_FILE_HIT | DEBUG_CACHE_MEM_MISS | DEBUG_CACHE_MEM_HIT; } else { for my $opt (@$debug_cache_args) { if ($opt eq 'file_miss') { $debug_cache |= DEBUG_CACHE_FILE_MISS; } elsif ($opt eq 'file_hit') { $debug_cache |= DEBUG_CACHE_FILE_HIT; } elsif ($opt eq 'mem_miss') { $debug_cache |= DEBUG_CACHE_MEM_MISS; } elsif ($opt eq 'mem_hit') { $debug_cache |= DEBUG_CACHE_MEM_HIT; } } } } # check deprecated for (qw(method_call deref formatter_path default_path formatter)) { if (exists $args->{$_}) { croak "Option $_ is deprecated, see documentation"; } } if (exists $args->{dumper}) { croak "Option dumper is deprecated, use a plugin instead"; } my $debug_file = delete $args->{debug_file} || 0; my $debug_compiled = delete $args->{debug} ? 1 : 0; my $debug = 0; $debug |= DEBUG_COMPILED if $debug_compiled; $args->{debug} = { options => $debug, file => $debug_file, cache => $debug_cache, }; my %optimize = ( initial_var => 1, object_check => 0, root_hash => 0, %{ $args->{optimize} || {} }, ); %$args = ( search_path_on_include => $SEARCHPATH, loop_context_vars => 0, case_sensitive => $CASE_SENSITIVE_DEFAULT, # debug_file => 0, objects => 'strict', out_fh => 0, global_vars => 0, default_escape => $DEFAULT_ESCAPE, default_path => PATH_DEREF, use_query => $DEFAULT_QUERY, #use_expressions => 0, use_perl => 0, open_mode => '', no_includes => 0, pre_chomp => 0, post_chomp => 0, expire_time => $NEW_CHECK, strict => 1, optimize => \%optimize, %$args, ); $self->set_args($args); # return %defaults; } sub init { my ( $self, %args ) = @_; $self->set_expire_time($args{expire_time}); $self->set_loop_context(1) if $args{loop_context_vars}; $self->set_case_sensitive( $args{case_sensitive} ); $self->set_default_escape( $args{default_escape} ); $self->set_default_path( $args{default_path} ); $self->set_use_query( $args{use_query} ); $self->set_chomp([$args{pre_chomp}, $args{post_chomp}]); $self->set_strict( $args{strict} ); $self->set_optimize($args{optimize}); my $warnings = $args{warnings} || 0; unless ($warnings eq 1 or $warnings eq 'fatal') { $warnings = 0; } $self->set_warnings($warnings); my $line_info = 0; if ($args{line_info}) { $line_info = 1; } $self->set_line_info($line_info); #$self->set_use_expressions( $args{use_expressions} ); if ($args{use_expressions}) { require HTML::Template::Compiled::Expr; } $args{open_mode} = '' unless length $args{open_mode}; if ($args{open_mode}) { $args{open_mode} =~ s/^[<>]//; # <:utf8 } $self->set_open_mode( $args{open_mode} ); $self->set_search_path( $args{search_path_on_include} ); $self->set_includes({}); if ( $args{filter} ) { require HTML::Template::Compiled::Filter; $self->set_filter( HTML::Template::Compiled::Filter->new( $args{filter} ) ); } $self->set_debug( $args{debug} ); $self->set_debug_file( $args{debug_file} ); $self->set_objects( $args{objects} ); $self->set_out_fh( $args{out_fh} ); $self->set_global_vars( $args{global_vars} ); if (my $plugins = $args{plugin}) { $self->set_plugins($plugins); } my $compiler = $self->compiler_class->new; $self->set_compiler($compiler); my $tagstyle = $args{tagstyle}; my $parser; if (ref $tagstyle eq 'ARRAY') { # user specified named styles or regexes $parser = $self->parser_class->new( tagstyle => $tagstyle, use_expressions => $args{use_expressions}, strict => $args{strict}, ); $parser->set_perl($args{use_perl}); } $args{parser} = ${$args{parser}} if ref $args{parser} eq 'REF'; if (UNIVERSAL::isa($args{parser}, 'HTML::Template::Compiled::Parser')) { $parser = $args{parser}; } unless ($parser) { $parser ||= $self->parser_class->default(); $parser->set_perl($args{use_perl}); $parser->set_expressions($args{use_expressions}); $parser->set_strict($args{strict}); } $parser->set_chomp([$args{pre_chomp}, $args{post_chomp}]); if ($args{use_perl}) { $parser->add_tagnames({ HTML::Template::Compiled::Token::OPENING_TAG() => { PERL => [sub { 1 }], } }); } if ($args{no_includes}) { $parser->remove_tags(qw/ INCLUDE INCLUDE_VAR INCLUDE_STRING /); } $self->set_parser($parser); if (my $plugins = $self->get_plugins) { $self->init_plugins($plugins); $self->set_plugins($plugins); } } { my %_plugins; sub load_plugins { my ($self, $plugins) = @_; for my $plug (@$plugins) { next if ref $plug; next if $_plugins{$plug}; if ($plug =~ m/^::/) { $plug = "HTML::Template::Compiled::Plugin$plug"; } next if $_plugins{$plug}; unless ($plug->can('register')) { eval "require $plug"; if ($@) { carp "Could not load plugin $plug\n"; } } $_plugins{$plug} = 1; } } } sub init_plugins { my ($self, $plugins) = @_; $self->load_plugins($plugins); my $parser = $self->get_parser; my $compiler = $self->get_compiler; for my $plug (@$plugins) { my $actions = $self->get_plugin_actions($plug); if (my $tagnames = $actions->{tagnames}) { $parser->add_tagnames($tagnames); } if (my $escape = $actions->{escape}) { $compiler->add_escapes((ref $plug) || $plug, $escape); } if (my $tags = $actions->{compile}) { $compiler->add_tags($tags); } } } { my $classes = {}; sub register { my ($class, $plugins) = @_; $plugins = [$plugins] unless ref $plugins eq 'ARRAY'; for my $plug (@$plugins) { my $actions = $plug->register; my $plug_class = (ref $plug) || $plug; $classes->{ $plug_class} = $actions; HTML::Template::Compiled::Compiler->setup_escapes($plug_class, $actions->{escape}||{}); } } sub get_plugin_actions { my ($self, $pclass) = @_; return $classes->{ref $pclass || $pclass}; } } sub _readfile { my ( $self, $file ) = @_; my $open_mode = $self->get_open_mode; open my $fh, "<$open_mode", $file or die "Cannot open '$file': $!"; local $/; <$fh>; } sub get_code { return $_[0]->get_perl; } sub compile_early { 1 } sub method_call { '.' } sub deref { '.' } sub formatter_path { '/' } sub parser_class { 'HTML::Template::Compiled::Parser' } sub compiler_class { 'HTML::Template::Compiled::Compiler' } sub quote_file { defined(my $f = $_[1]) or return ''; $f =~ s/'/\\'/g; return qq/'$f'/; } # this method gets a varname like 'var' or 'object.method' # or 'hash.key' and makes valid perl code out of it that will # be eval()ed later # so assuming . is the character for dereferencing hashes the string # hash.key (found inside ) will be converted to # '$t->get_var($P, $$C, 1, [PATH_DEREF, 'key'])' # the get_var method walks the paths given through the data structure. # $P is the parameter hash of the template, $C is a reference to the current # parameter hash. the third argument to get_var is 'final'. # is a 'final' path, and is not. # so final means it's in 'print-context'. # -------- warning, ugly code # i'm trading maintainability for efficiency here sub try_global { my ( $self, $walk, $path ) = @_; my $stack = $self->get_globalstack || []; #warn Data::Dumper->Dump([\$stack], ['stack']); for my $item ( $walk, reverse @$stack ) { if (my $code = UNIVERSAL::can($item, $path)) { my $r = $code->($item); return $r; } else { next unless exists $item->{$path}; return $item->{$path}; } } return; } { sub _walk_formatter { my ($self, $walk, $key, $global) = @_; my $ref = ref $walk; my $fm = $HTML::Template::Compiled::Formatter::formatter; my $sub = exists $fm->{$ref} ? $fm->{$ref}->{$key} : undef; my $stack = []; my $new_walk; if ($global) { $stack = $self->get_globalstack || []; } for my $item ($walk, reverse @$stack) { #print STDERR "::::::: formatter $walk -> $key (sub=$sub)\n"; if (defined $sub) { $new_walk = $sub->($walk); last; } elsif (exists $item->{$key}) { #print STDERR "===== \$item->{$key} exists! '$item->{$key}'\n"; $new_walk = $item->{$key}; last; } # try next item in stack } #print STDERR "---- formatter $walk\n"; return $new_walk; } # ----------- still ugly code # not needed anymore # if (my $formatter = $self->get_formatter() and $final and my $ref = ref $walk) { # if (my $sub = $formatter->{$ref}->{''}) { # my $return = $sub->($walk,$self,$P); # return $return unless ref $return; # } # } # return $walk; } # end ugly code, phooey # returns if the var is valid # only allow '.', '/', '+', '-' and '_' # fix 2007-07-23: HTML::Template allows every character # although the documentation says it doesn't. sub validate_var { return 1; #return $_[1] !~ tr{a-zA-Z0-9._[]/#-}{}c; } sub escape_filename { my ( $t, $f ) = @_; $f =~ s#([/:\\])#'%'.uc sprintf"%02x",ord $1#ge; return $f; } sub _checktimes { my $self = shift; D && $self->stack; my $filename = shift; my $mtime = ( stat $filename )[9]; #print STDERR "stat $filename = $mtime\n"; my $checked = time; my $lmtime = localtime $mtime; my $lchecked = localtime $checked; return ( $mtime, $checked, $lmtime, $lchecked ); } sub clone { my ($self) = @_; return bless [@$self], ref $self; } sub new_scalar_from_object { my ($self, $scalar) = @_; my $new = $self->clone; $new->set_includes({}); $new->set_perl(undef); $new->set_filehandle(); $new->set_cache(0); $new->set_cache_dir(undef); $new->set_scalar(\$scalar); my $md5 = md5($scalar); $new->set_filename($md5); $new = $new->from_scratch; return $new; } # create from existing object (TMPL_INCLUDE) sub new_from_object { my ( $self, $path, $filename, $fullpath, $cache ) = @_; unless (defined $filename) { my ($file) = (caller(1))[3]; croak "Filename is undef (in template $file)"; } my $new = $self->clone; D && $self->log("new_from_object($path,$filename,$fullpath,$cache)"); $new->set_filename($filename); #if ($fullpath) { # $self->set_file($fullpath); #} $new->set_includes({}); $new->set_scalar(); $new->set_filehandle(); my $md5path = md5_hex(@{ $path || [] }); $new->set_path($path); $new->set_md5_path( $md5path ); $new->set_perl(undef); if (my $cached = $new->from_cache($self->get_args)) { $cached->set_plugins($self->get_plugins); $cached->init_includes; return $cached } unless ($new->get_compiler) { my %args = %{ $self->get_args || {} }; $new->init(%args); } $new = $new->from_scratch; $new->init_includes; return $new; } sub prepare_for_cache { my ($self) = @_; $self->clear_params; my @plugs = @{ $self->get_plugins || [] }; for my $i (0 .. $#plugs) { if (ref $plugs[$i]) { if ($plugs[$i]->can('serialize')) { $plugs[$i] = $plugs[$i]->serialize(); } } } $self->set_plugins(\@plugs); my $includes = $self->get_includes; for my $fullpath (keys %$includes) { my ($path, $filename, $htc) = @{ $includes->{$fullpath} }; $includes->{$fullpath} = [$path, $filename]; } $self->set_parser(undef); $self->set_compiler(undef); $self->set_args(undef); $self->set_globalstack(undef); } sub preload { my ( $class, $dir ) = @_; opendir my $dh, $dir or die "Could not open '$dir': $!"; my @files = grep { m/\.pl|\.storable$/ } readdir $dh; closedir $dh; my $loaded = 0; for my $file (@files) { my $success = $class->include_file( File::Spec->catfile( $dir, $file ) ); $loaded++ if $success; } return scalar $loaded; } sub precompile { my ($class, %args) = @_; my $files = delete $args{filenames}; return unless ref $files eq 'ARRAY'; my @precompiled; for my $file (@$files) { my $htc = $class->new(%args, (ref $file eq 'SCALAR' ? 'scalarref' : ref $file eq 'ARRAY' ? 'arrayref' : ref $file eq 'GLOB' ? 'filehandle' : 'filename') => $file, ); push @precompiled, $htc, } return \@precompiled; } sub clear_params { $_[0]->[PARAM] = (); } sub get_param { return $_[0]->[PARAM]; } sub param { my $self = shift; if (!@_) { return $self->query(); return UNIVERSAL::can($self->[PARAM],'can') ? $self->[PARAM] : $self->[PARAM] ? keys %{$self->[PARAM]} : (); } my %p; if (@_ == 1) { if ( ref $_[0] ) { # feed a hashref or object if (ref $_[0] eq 'HASH') { # hash, no object %p = %{ $_[0] }; } else { $self->[PARAM] = $_[0]; return; } } else { # query a parameter return $self->[PARAM]->{ $_[0] }; } } else { %p = @_; } if ( !$self->get_case_sensitive ) { my $lc = $self->lchash( {%p} ); %p = %$lc; } $self->[PARAM]->{$_} = $p{$_} for keys %p; } sub query { my ($self, $what, $tags) = @_; # param() no arguments should behave like query # query() is not activated by default, and # my %param = (); $htc->param(%param); should # *not* call query(). so we check if the user wants # a return value; that indicates that they wanted to # use query-like behaviour. return unless defined wantarray(); #print STDERR "query(@_)\n"; my $info = $self->get_parse_tree or do { $self->_error_no_query(); return; }; unless (ref $info) { # not compiled yet! $self->_error_not_compiled(); return; } my $pointer = {children => $info}; $tags = [] unless defined $tags; $tags = [$tags] unless ref $tags eq 'ARRAY'; my $includes = $self->get_includes; my %include_info = map { $includes->{$_}->[1] => $includes->{$_}->[2]->get_parse_tree; } keys %{ $includes }; for my $tag (@$tags) { my $value; my %includes = map { my $item = $pointer->{children}->{$_}; ($item->{type} eq 'INCLUDE' and $include_info{$_}) ? (%{$include_info{$_}}) : () } keys %{ $pointer->{children} }; if (defined ($value = $pointer->{children}->{lc $tag})) { $pointer = $value; } elsif (defined ($value = $includes{lc $tag})) { $pointer = $value; } else { return; } } unless ($what) { my @return = map { my $item = $pointer->{children}->{$_}; ($item->{type} eq 'INCLUDE' and $include_info{$_}) ? (keys %{$include_info{$_}}) : $_; } keys %{ $pointer->{children} }; return @return; } elsif ($what eq 'name') { my $type = $pointer->{type}; return $type; } elsif ($what eq 'loop') { if ($pointer->{type} eq 'LOOP') { my @return = map { my $item = $pointer->{children}->{$_}; ($item->{type} eq 'INCLUDE' and $include_info{$_}) ? (keys %{$include_info{$_}}) : $_; } keys %{ $pointer->{children} }; return @return; } else { croak "error: (@$tags) is not a LOOP" } } return; } # =head2 lchash # # my $capped_href = $self->lchash(\%href); # # Input: # - hashref or arrayref of hashrefs # # Output: Returns a reference to a cloned data structure where all the keys are # capped. # # =cut sub lchash { my ( $self, $data ) = @_; my $lc; if ( ref $data eq 'HASH' ) { for my $key ( keys %$data ) { my $uc_key = lc $key; my $val = $self->lchash( $data->{$key} ); $lc->{$uc_key} = $val; } } elsif ( ref $data eq 'ARRAY' ) { for my $item (@$data) { my $new = $self->lchash($item); push @$lc, $new; } } else { $lc = $data; } return $lc; } sub output { my ( $self, $fh ) = @_; my $p = $self->[PARAM] || {}; # if we only have an object as parameter $p = ref $p eq 'HASH' ? \% { $p } : $p; my $f = $self->get_file; $fh = \*STDOUT unless $fh; if ($DEBUG) { my $output; eval { $output = $self->get_perl()->( $self, $p, \$p, $fh ); }; if ($@) { $LAST_EXCEPTION = $@; my $filename = $self->get_file; die "Error while executing '$filename': $@"; } return $output; } else { $self->get_perl()->( $self, $p, \$p, $fh ); } } sub import { my ( $class, %args ) = @_; if ( $args{compatible} ) { carp "Usage of use option 'compatible' is deprecated"; $class->CaseSensitive(0); $class->SearchPathOnInclude(0); $class->UseQuery(1); } elsif ( $args{speed} ) { carp "Usage of use option 'speed' is deprecated"; # default at the moment $class->CaseSensitive(1); $class->SearchPathOnInclude(1); $class->UseQuery(0); } if (exists $args{short}) { carp "Usage of use option 'short' is deprecated"; __PACKAGE__->export_to_level(1, scalar caller(), 'HTC'); } } sub var2expression { my ($self, $var) = @_; $var = $self->get_compiler->parse_var($self, var => $var, method_call => $self->method_call, deref => $self->deref, formatter_path => $self->formatter_path, ); return $var; } sub ExpireTime { my ($class, $seconds) = @_; $NEW_CHECK = $seconds; } sub EnableSub { carp "Warning: Subref variables are not supported any more, use HTML::Template::Compiled::Classic instead"; } sub CaseSensitive { my ($class, $bool) = @_; $CASE_SENSITIVE_DEFAULT = $bool ? 1 : 0; } sub SearchPathOnInclude { my ($class, $bool) = @_; $SEARCHPATH = $bool ? 1 : 0; } sub UseQuery { my ($class, $bool) = @_; $DEFAULT_QUERY = $bool ? 1 : 0; } sub pushGlobalstack { my $stack = $_[0]->get_globalstack; push @$stack, $_[1]; $_[0]->set_globalstack($stack); } sub popGlobalstack { my $stack = $_[0]->get_globalstack; pop @$stack; $_[0]->set_globalstack($stack); } { my $lock_fh; sub lock { my $file = File::Spec->catfile( $_[0]->get_cache_dir, "lock" ); unless ( -f $file ) { # touch open $lock_fh, '>', $file or croak "Could not open lockfile '$file' for writing: $!"; close $lock_fh; } open $lock_fh, '+<', $file or croak "Could not open lockfile '$file' for read/write: $!"; flock $lock_fh, LOCK_EX; } sub unlock { close $lock_fh; } } { my $loaded = 0; my $error = 0; sub require_storable { return 1 if $loaded; return 0 if $error; eval { require Storable; }; if ($@) { $error = 1; return 0; } eval "use B::Deparse 0.61"; if ($@) { $error = 1; return 0; } return 1; } } sub debug_code { my ($self, $html) = @_; my $perl = $self->get_perl; require B::Deparse; my $deparse = B::Deparse->new("-p", "-sC"); my $body = $deparse->coderef2text($perl); my $filename = $self->get_file; #warn __PACKAGE__.':'.__LINE__.$".Data::Dumper->Dump([\$body], ['body']); my $message = ''; if ($LAST_EXCEPTION and $LAST_EXCEPTION =~ m/at (?:\(eval \d*\)|\S+) line (\d+)\./) { my $rline = $1; my $line = $rline; $line--; my @lines = split m#$/#, $body; if ($line > $#lines) { $line = $#lines; } my $pre = $line > 0 ? join $/, @lines[0 .. $line - 1] : ''; my $post = $line < $#lines ? join $/, @lines[$line + 1 .. $#lines] : ''; my $error = "$/$/# ------------------- ERROR line $rline in template $filename -----------------$/"; my $last = $LAST_EXCEPTION; $LAST_EXCEPTION =~ s#$/# #g; $error .= "# $last$/$lines[$line]$/"; if ($html) { for ($pre, $error, $post) { s//>/g; } $message = <<"EOM";
$pre
$error
$post
EOM } else { $message .= $pre; $message .= $error; $message .= $post; } } else { $message = $LAST_EXCEPTION; } return $message; } 1; __END__ =pod =head1 NAME HTML::Template::Compiled - Template System Compiles HTML::Template files to Perl code =head1 SYNOPSIS use HTML::Template::Compiled; # recommended options: # case_sensitive => 1 # search_path_on_include => 1 # use_query => 0 # default_escape => 'HTML' # <-- HIGHLY RECOMMENDED # note that the following # use HTML::Template::Compiled speed => 1 # is deprecated (can be problematic under persistent environments) # or for the biggest compatibility with HTML::Template # case_sensitive => 0 # search_path_on_include => 0 # use_query => 1 # note that the following # use HTML::Template::Compiled compatible => 1; # is deprecated (can be problematic under persistent environments) # or use HTML::Template::Compiled::Classic my $htc = HTML::Template::Compiled->new( filename => 'test.tmpl', case_sensitive => 1, default_escape => 'HTML', ); $htc->param( BAND => $name, ALBUMS => [ { TITLE => $t1, YEAR => $y1 }, { TITLE => $t2, YEAR => $y2 }, ], ); print $htc->output; test.tmpl: Band: Title: () Or use different tag styles: Band: <%= BAND %> <%loop ALBUMS %> Title: <%= TITLE %> (<%= YEAR %>) <%/loop %> Band: [%= BAND %] [%loop ALBUMS %] Title: [%= TITLE %] ([%= YEAR %]) [%/loop %] =head1 DESCRIPTION HTML::Template::Compiled is a template system which can be used for L templates with almost the same API. It offers more flexible template delimiters, additional tags and features, and by compiling the template into perl code it can run significantly faster in persistent environments such as FastCGI or mod_perl. The goal is to offer more features for flexibility but keep the basic syntax as easy as it is. Features at a glance: =over 4 =item Dot notation for objects, hashes and arrays =item Use expressions without any disadvantages like those in L =item Write escaping plugins and plugins for new tags =item Alternate delimiters, e.g. C<[%if %]> and C<< <%if %> >> =item Avoid C option by using the C tag to create aliases. =item Tags ELSIF, EACH, WHILE, COMMENT, WRAPPER, SWITCH/CASE, INCLUDE_VAR =item Chomp newlines/whitespace =back For a quick reference, see L. As the basic features work like in L, please get familiar with its documentation before. HTML::Template::Compiled (HTC) does not implement all features of L (see L<"COMPATIBILITY">), and it has got some additional features which are explained below: L<"ADDITIONAL FEATURES"> See L<"BENCHMARKS"> for some examples on the performance. Since it depends highly on the options used and on the template size there can be no general statement on its performance. You might want to use L for CGI environments as it doesn't parse the template before calling output. But note that HTC::Lazy isn't much tested, and I don't use it myself, so there's a lack of experience. If you use it and have problems, please report. HTC will use a lot of memory because it keeps all template objects in memory. If you are on mod_perl, and have a lot of templates, you should preload them at server startup to be sure that it is in shared memory. At the moment HTC is not fully tested for keeping all data in shared memory (e.g. when a copy-on-write occurs), but it seems like it's behaving well. For preloading you can use HTML::Template::Compiled->preload($cache_dir). Generating code, writing it on disk and later eval() it can open security holes, for example if you have more users on the same machine that can access the same files (usually an http server running as 'www' or 'nobody'). See L<"SECURITY"> for details what you can do to safe yourself. NOTE: If you don't need any of the additional features listed below and if you don't need the speed (in many cases it's probably not worth trading speed for memory), then you might be better off with just using HTML::Template. NOTE2: If you have any questions, bug reports, send them to me and not to Sam Tregar. This module is developed by me at the moment, independently from HTML::Template, although I try to get most of the tests from it passing for HTC. See L<"RESOURCES"> for current information. =head2 FEATURES FROM HTML::TEMPLATE =over 4 =item TMPL_VAR =item TMPL_LOOP =item TMPL_(IF|UNLESS|ELSE) =item TMPL_INCLUDE =item HTML_TEMPLATE_ROOT =item ESCAPE=(HTML|URL|JS|0) =item DEFAULT=... =item C<__first__>, C<__last__>, C<__inner__>, C<__outer__>, C<__odd__>, C<__counter__>, C<__even__> =item =item case insensitive var names use option case_sensitive => 0 to use this feature (slow down) =item filters =item vars that are subrefs - not implemented, only in HTML::Template::Compiled::Classic =item scalarref, arrayref, filehandle =item C =item C Has a bug (doesn't return parameters in included files of included files). I'm working on that. =back =head2 ADDITIONAL FEATURES What can HTC do for you additionally to HTML::Template? =over 4 =item tag TMPL_ELSIF No need to have cascading "if-else-if-else"s =item tag TMPL_EACH Iterate over a hash. See L<"TMPL_EACH"> =item tag TMPL_WITH see L<"TMPL_WITH"> =item tag TMPL_WHILE see L<"TMPL_WHILE"> =item tag TMPL_SET_VAR see L<"SET_VAR"> =item tag TMPL_USE_VARS see L<"USE_VARS"> =item tags TMPL_COMMENT, TMPL_NOPARSE, TMPL_VERBATIM see L<"TMPL_COMMENT">, L<"TMPL_NOPARSE">, L<"TMPL_VERBATIM"> =item tag TMPL_WRAPPER see L<"WRAPPER"> =item C<__index__> Additional loop variable (C<__counter__ -1>) =item C<__break__> Additional loop variable (see L<"TMPL_LOOP">) =item C<__filename__>, C<__filenameshort__> (since 0.91_001) Insert the template filename for debugging: <%= __filename__ %> <%= __filenameshort__ %> will turn out as: templates/path/file.html path/file.html See also option debug_file in L<"OPTIONS"> for adding the filename globally. =item tags TMPL_SWITCH, TMPL_CASE see L<"TMPL_SWITCH"> =item C Include perl code in your template. See L<"RUNNING PERL WITH TMPL_PERL"> =item CHOMP New in version 0.96_001, please report any bugs and send me suggestions. You can set global chomp options in the constructor. These work like in Template-Toolkit: my $htc = HTML::Template::Compiled->new( pre_chomp => 0, # 0, 1, 2, 3, default 0 post_chomp => 1, # 0, 1, 2, 3, default 0 ); Meaning of the values: 0: Don't chomp 1: remove only spaces in the line before or after the tag 2: remove all whitespaces before or after the tag, and replace with one space 3: remove all whitespaces before or after the tag In the template you can change that feature by using PRE_CHOMP and POST_CHOMP attributes: <%= foo PRE_CHOMP=3 POST_CHOMP=1 %> The experimental tags +..._chomp have been removed. =item Generating perl code See L<"IMPLEMENTATION"> =item better variable access dot-notation for accessing hash values. See L<"EXTENDED VARIABLE ACCESS"> =item rendering objects dot-notation for accessing object methods. See L<"RENDERING OBJECTS"> =item output to filehandle See L<"OPTIONS"> =item Dynamic includes C, C. See L<"INCLUDE"> =item tag TMPL_IF_DEFINED Check for definedness instead of truth: =item ALIAS Set an alias for a loop variable. You can use the alias then with C<$alias>. The syntax without the C<$> is also possible but not recommended any more. For example, these two loops are functionally equivalent: This works with C and C at the moment. You can also set aliases with the C tag. See L<"SET_VAR"> To use template parameters with a C<$> at the beginning (which is not officially supported, but some are obviously using it), you can set: local $HTML::Template::Compiled::Compiler::DISABLE_NEW_ALIAS = 1; This is only a temporary workaround and will be removed some day! Note that you are also able to access variables with dollar signs like this: since underscore means current position in the parameter stash, and aliases are only recognized at the beginning of a template var. But note that dollar signs are still not officially supported. =item Chained escaping See L<"ESCAPING"> =item tagstyles For those who like it (i like it because it is shorter than TMPL_), you can use E% %E tags and the E%= tag instead of E%VAR (which will work, too): <%IF blah%> <%= VARIABLE%> <%/IF%> Define your own tagstyles and/or deactivate predefined ones. See L<"OPTIONS"> tagstyle. =item pre_chomp, post_chomp See L<"CHOMP"> =back =head2 MISSING AND DIFFERENT FEATURES There are some features of H::T that are missing or behaving different. I'll try to list them here. =head3 MISSING FEATURES =over 4 =item die_on_bad_params I don't think I'll implement that. =item force_untaint Not planned at the moment =item vanguard_compatibility_mode Not planned. =item shared_cache, double_cache Not planned at the moment =item blind_cache Not sure if I should implement. In HTC you have the possibility to set the expire time of the templates (after that time in memory the template file is rechecked if it has changed), so setting a very high value for expire_time would have the same effect as blind_cache. See L<"CACHING"> C =item double_file_cache If I understand correctly, in HT, this enables memory and file cache at the same time. In HTC, this is not needed. If you use file_cache and cache, both are used. =item file_cache_dir_mode Not planned. The cache dir must exist, and subdirectories are not created at the moment. =item cache_lazy_vars, cache_lazy_loops Not planned at the moment (This would be for HTML::Template::Compiled::Classic, since it implements code refs). =item utf8 Might be added in the future, HTC already has C =item various debug options Might be implemented in the future =item associate Not planned. =item max_includes Not planned =item die_on_missing_include Maybe =back =head3 DIFFERENT FEATURES =over 4 =item case_sensitive default is 1 (on). Deactivate by passing option case_sensitive 0. Note (again): this will slow down templating a lot (50%). Explanation: This has nothing to do with C or C. It's about the variable names. With case_sensitive set to 1, the following tags are different: prints the value of hash key 'Foo' prints the value of hash key 'fOO' With case_sensitive set to 0, all your parameters passed to C are converted to lowercase, and the following tags are the same: prints the value of hash key 'foo' prints the value of hash key 'foo' =item subref variables As of version 0.69, subref variables are not supported any more with HTML::Template::Compiled. Use L (contained in this distribution) instead. It provides most features of HTC. =item search_path_on_include Default: 0 In the HTML::Template documentation it says, if search_path_on_include is set to 1, the paths of the path option are searched, while the default behaviour is to look "only" in the current template directory. It's not clear if it still searches in the current directory if set to 1. I found out that it is not, so you cannot have both. In HTML::Template::Compiled, search_path_on_include can have three values: 0: search current template directory 1: search paths specified 2: search paths and current template directory. =item open_mode In HTC you should leave out the C<<> at the beginning. If you want to have your templates read in utf-8, use open_mode => ':encoding(utf-8)', as an option. =item use_query default is 0 (off). Set it via the option C =item Arrayrefs At the moment this snippet truefalse with this code: $htc->param(arrayref => []); will print true in HTC and false in HTML::Template. In HTML::Template an array is true if it has content, in HTC it's true if it (the reference) is defined. I'll try to find a way to change that behaviour, though that might be for the cost of speed. As of L 0.85 you can use this syntax: truefalse In L 0.04 it works as in HTML::Template. =item debug_cache Additional to 0 or 1 it can take an array ref for debugging only specific cache operations. =back Note: the following is deprecated: To be compatible in all of the above options all use: use HTML::Template::Compiled compatible => 1; If you don't care about these options you should use use HTML::Template::Compiled speed => 1; which is the default but depending on user wishes that might change. =head2 DEPRECATED =over 4 =item class methods ExpireTime, EnableSub, CaseSensitive, SearchPathOnInclude, UseQuery =item option formatter_path =item tag USE_VARS, not needed anymore =item option cache_dir (replaced by file_cache_dir) =item options method_call, deref, default_path, dumper =item import tags short, compatible, speed =back =head2 ESCAPING Like in HTML::Template, you have C, C and C. C will only escape '"&<>. If you want to escape more, use C. Additionally you have C, which by default will generate a Data::Dumper output. You can also chain different escapings, like C. Additionally to ESCAPE=JS you have ESCAPE=IJSON which does not escape the single quote. =head2 INCLUDE Additionally to you can do an include of a template variable: $htc->param(file_include_var => "file.htc"); Using C is deprecated. You can also include strings: template: inc: <%include_string foo %> code: $htc->param( foo => 'included=<%= bar%>', bar => 'real', ); output: inc: included=real Note that included strings are not cached and cannot include files or strings themselves. =head2 EXTENDED VARIABLE ACCESS With HTC, you have more control over how you access your template parameters. An example: my %hash = ( SELF => '/path/to/script.pl', LANGUAGE => 'de', BAND => 'Bauhaus', ALBUMS => [ { NAME => 'Mask', SONGS => [ { NAME => 'Hair of the Dog' }, ... ], }, ], INFO => { BIOGRAPHY => '...', LINK => '...' }, NAME => "Cool script", ); Now in the TMPL_LOOP C you would like to access the path to your script, stored in $hash{SELF}. in HTML::Template you have to set the option C, so you can access C<$hash{SELF}> from everywhere. Unfortunately, now C is also global, which might not a problem in this simple example, but in a more complicated template this is impossible. With HTC, you wouldn't use C here, but you can say: to access the root element, and you could even say C<.INFO.BIOGRAPHY> or C (the latter has changed since version 0.79) =head2 RENDERING OBJECTS This is still in development, so I might change the API here. Additionally to feeding a simple hash to HTC, you can feed it objects. To do method calls you can also use '.' in the template. my $htc = HTML::Template::Compiled->new( ... ); $htc->param( VAR => "blah", OBJECT => bless({...}, "Your::Class"), ); Name: C will call the fullname method of your Your::Class object. It's recommended to just use the default . value for methods and dereferencing. I might stop supporting that you can set the values for method calls by setting an option. Ideally I would like to have that behaviour changed only by inheriting. =head2 RUNNING PERL WITH TMPL_PERL Yes, templating systems are for separating code and templates. But as it turned out to be implemented much easier than expressions i decided to implement it. But expressions are also available with the option C. Note: If you have templates that can be edited by untrustworthy persons then you don't want them to include perl code. So, how do you use the perl-tag? First, you have to set the option C to C<1> when creating a template object. Important note: don't use C in the included code. Usually the template code is concatenated and returned to your perl script. To 'print' something out use __OUT__ 2**3; This will be turned into something like $OUT .= 2**3; # or print $fh 2**3; Important note 2: HTC does not parse Perl. if you use the classic tag-delimiters like this: count > 42) { > this will not work as it might seem. Use other delimiters instead: <%perl if (__CURRENT__->count > 42) { %> Example: # takes the current position of the parameter # hash, key 'foo' and multiplies it with 3 <%perl __OUT__ __CURRENT__->{foo} * 3; %> List of special keywords inside a perl-tag: =over 4 =item __OUT__ Is turned into C<$OUT .=> or C =item __HTC__ Is turned into the variable containing the current template object. =item __CURRENT__ Turned into the variable containing the current position in the parameter hash. =item __ROOT__ Turned into the variable containing the parameter hash. =item __INDEX__ Turned into the current index of a loop (starting with 0). =back =head2 INHERITANCE It's possible since version 0.69 to inherit from HTML::Template::Compiled. It's just not documented, and internal method names might change in the near future. I'll try to fix the API and document which methods you can inherit. =head3 METHODS TO INHERIT =over 4 =item method_call Default is C =item deref Default is C =item formatter_path Deprecated, see L please. =item compile_early Define if every included file should be checked and parsed at compile time of the including template or later when it is really used. Default is C =item parser_class Default is C You can write your own parser class (which must inherit from L) and use this. L uses this. =back =head2 DEBUGGING For printing out the contents of all the parameters you can do: Dump: The special name C<_> gives you the current parameter and C will by default generate a Data::Dumper output of the current variable, in this case it will dump out the contents of every album in a loop. To correctly display that in html C<|HTML> will escape html entities. =head2 TMPL_WITH If you have a deep leveled hash you might not want to always write THE.FULL.PATH.TO.YOUR.VAR. Jump to your desired level once and then you need only one level. Compare: : : Inside TMPL_WITH you can't reference parent nodes unless you're using global_vars. =head2 TMPL_LOOP The special name C<_> gives you the current parameter. In loops you can use it like this: Current item: Also you can give the current item an alias. See L<"ALIAS">. The LOOP tag allows you to define a JOIN attribute: This will output something like C. This is easier than doing: , The C, C and C tags allow you to define a BREAK attribute: \n $htc->param(bingo => [qw(X 0 _ _ X 0 _ _ X)]); outputs X 0 _ _ X 0 _ _ X So specifying BREAK=3 sets __break__ to 1 every 3rd loop iteration. TMPL_LOOP expects an array reference, also if it is a method call. If you want to iterate with TMPL_LOOP over a list from a method call, set the attribute C: =head2 TMPL_WHILE Useful for iterating, for example over database resultsets. The directive will work like: while (my $row = $resultset->fetchrow) { print $row->[0]; } So the special variable name _ is set to the current item returned by the iterator. You also can use L<"ALIAS"> here. =head2 TMPL_EACH Iterating over a hash. Internally it is not implemented as an each, so you can also sort the output: Sorted alphanumerically by default (since 0.93): : Sorted numerically: : Not sorted: : Sorted alphanumerically: : You have to set the option C to true to use the special vars C<__key__> and C<__value__>. If you want to iterate over a hash instead of a hashref (some methods might return plain hashes instead of references and TMPL_EACH expects a ref), then you can set C: Since 1.000_001 you can also define by which variable you want to sort. If you have a hash with hashes as values: $htc->param( letters => { 1 => { letter =>'b' }, 2 => { letter =>'a' }, 3 => { letter =>'c' }, }, ); <%each letters sort=alpha sortby="letter" %> <%set_var val value=__value__ %> <%= __key__ %> = <%= $val.letter %> <%/each%> =head2 SET_VAR Since 0.96_002 Sets a local variable to the value given in C or C ... C behaves like a variable name from the parameter stash. The variable name to set must match /[0-9a-z_]+/i You can refer to an alias via C<$alias> or simply C. Note that the latter syntax is not recommended any more since it can conflict with parameters from the stash. If you want to use aliases in includes, you need to use the C<$alias> syntax. =head2 USE_VARS deprecated. Was added in 0.96_004 to make it possible to use aliases set with C or C in includes. Now you should rather use the <$alias> syntax. The following explanation is just there for history and will be removed some time in the future. For now it still works. Necessary if you want vars like SET_VAR and loop aliases from outside in includes. Before the first use in the include, add: so that the compiler recognizes them as user defined vars and not parameters from the stash. This statement is valid until the end of the template so you cannot "overwrite" parameters of the stash locally. =head2 WRAPPER Since 0.97_005. Experimental. Please test. Needs option C. Works similar to WRAPPER in Template-Toolkit. Is similar to TMPL_INCLUDE, just that the included wrapper is wrapped around the content. It can be used to avoid including head and foot separately. content: some var: In wrapper.html the special loop context var C<__wrapper__> is used for the included content: wrapper.html: Important notes: If you are using C to print directly to a filehandle instead of returning to a string, this feature might not be useful, since it is appending the content inside of the wrapper to a string and prints it when it comes to the end of the wrapper tag. So if you are using C to avoid generating long strings in memory, you should rather use TMPL_INCLUDE instead. Also you need perl 5.8 or higher to use it in combination with out_fh. =head2 TMPL_COMMENT For debugging purposes you can temporarily comment out regions: Wanted: this won't be printed $htc->param(unwanted => "no thanks", wanted => "we want this"); The output is (whitespaces stripped): Wanted: we want this HTC will ignore anything between COMMENT directives. This is useful for debugging, and also for documentation inside the template which should not be outputted. =head2 TMPL_NOPARSE Anything between ... will not be recognized as template directives. Same syntax as TMPL_COMMENT. It will output the content, though. =head2 TMPL_VERBATIM Anything between ... will not be recognized as template directives. Same syntax as L<"TMPL_NOPARSE">, but it will be HTML-Escaped. This can be useful for debugging. =head2 TMPL_SWITCH The SWITCH directive has the same syntax as VAR, IF etc. The CASE directive takes a simple string or a comma separated list of strings. Yes, without quotes. This will probably change! I just don't know yet how it should look like. Suggestions? With that directive you can do simple string comparisons. (or ) echt cool very cool superculo don't speak french or swedish sorry, no translation for cool in language <%=language%> available (same as default) It's also possible to specify the default with a list of other strings: Note that the default case should always be the last statement before the closing switch. =head2 OPTIONS As you can cache the generated perl code in files, some of the options are fixed; that means for example if you set the option case_sensitive to 0 and the next time you call the same template with case_sensitive 1 then this will be ignored. The options below will be marked as (fixed). =over 4 =item path Path to template files =item search_path_on_include Search the list of paths specified with C when including a template. Default is 0 See L<"DIFFERENT FEATURES"> for the additional possible value 2. =item file_cache Set to 1 if you want to use file caching and specify the path with file_cache_dir. =item file_cache_dir Path to caching directory (you have to create it before) =item cache_dir Replaced by file_cache_dir like in L. Will be deprecated in future versions. =item cache Is 1 by default. If set to 0, no memory caching is done. Only recommendable if you have a dynamic template content (with scalarref, arrayre for example). =item expire_time Recheck template files on disk after C seconds. See L<"CACHING"> =item filename Template to parse =item scalarref Reference to a scalar with your template content. It's possible to cache scalarrefs, too, if you have Digest::MD5 installed. Note that your cache directory might get filled with files from earlier versions. Clean the cache regularly. Don't cache scalarrefs if you have dynamic strings. Your memory might get filled up fast! Use the option cache => 0 to disable memory caching. =item arrayref Reference to array containing lines of the template content (newlines have to be included) =item filehandle Filehandle which contains the template content. Note that HTC will not cache templates created like this. =item loop_context_vars (fixed) Vars like C<__first__>, C<__last__>, C<__inner__>, C<__odd__>, C<__counter__>, C<__index__>, C<__outer__>, C<__even__> The variable C<__index__> works just like C<__counter__>, only that it starts at 0 instead of 1. =item global_vars (fixed) If set to 1, every outer variable can be accessed from anywhere in the enclosing scope. Default is 0. Note that I don't recommend using global_vars. For referring to parameters up in the stash you can use aliases via C or C. See L<"ALIAS"> and L<"SET_VAR">. If you still would like to be able to navigate up the parameter stash, you have the following option: If set to 2, you don't have global vars, but have the possibility to go up the stack one level. Example: This will get you up 2 levels (remember: one dot means root in HTC) and access the 'key' element. If set to 3 (C<3 == 1|2>) you have both, global vars and explicitly going up the stack. So setting global_vars to 2 can save you from global vars but still allows you to browse through the stack. =item default_escape my $htc = HTML::Template::Compiled->new( ... default_escape => 'HTML', # or URL ); Now everything will be escaped for HTML unless you explicitly specify C (no escaping) or C. =item strict (since 0.97_001) Default: 1 If set to 0 unknown tags will be ignored and output verbatim: =item line_info (fixed) (since 1.000_004) Default: 0 my $htc = HTML::Template::Compiled->new( ... line_info => 1, # default 0 ); If any runtime errors occur, line information will output the template filename and line (instead of "eval" and the generated perl code line) =item warnings (fixed) (since 1.000_004) Default: 0 If set to 1, runtime warnings (like use of uninitialized value) will be output to stderr. If set to 'fatal', any runtime warning will cause the script to die. =item no_includes (since 0.92) Default is 0. If set to 1, the tags INCLUDE, INCLUDE_VAR and INCLUDE_STRING will cause a template syntax error when creating. This can be useful when opening untrusted templates, otherwise any file in the filesystem could be opened. =item debug_file (fixed) (since 0.91_001) Additionally to the context_vars __filename__ and __filenameshort__ you can enable filename debugging globally. If the option is set to 'start', at the start of every template will be added: If set to 'end', at the end will be added: If set to 'start,end', both comments will be added. If set to 'start,short', 'end,short' or 'start,end,short' the path to the templates will be stripped: =item optimize (fixed) (since 1.001_001) Hashref with compiler hints. Every access to the parameter stash has to check if the current var is an object or a hash. This allows you to use the same notation for hash accesses and method calls without caring about the data. But this is quite expensive. You can give the compiler hints: HTML::Template::Compiled->new( optimize => { initial_var => 1, # defaults object_check => 0, root_hash => 0, }, =over 4 =item initial_var Default: 1 Might become a default in the code itself and removed as an option. Report if you have problems and set it to 0. This is just a minor internal optimization for variable accesses like C<[%= foo.bar.baz %]> =item object_check Default: 0 If you are in a loop and make several accesses to the same var, it always checks if it is an object or not: [%loop threads %] [%= id %] [%= title %] [%= ctime %] ... [%/loop threads %] If you set this to true, the check will be done at the beginning of the loop and saved into a variable, so that subsequent accesses only use the check variable. Same for TMPL_WITH, TMPL_WHILE. If you only have one access in a loop, this might be unnecessary overhead. Also, theoretically, a variable can change during calls. In the most cases this option should be fine. I will set the default to 1 someday probably. =item root_hash It is possible to pass an object to param() instead of a hash. So even every access to the root of the parameter stash has to check if it is an object or a hashref. In the most cases the parameter stash is a hashref. If you are sure that you always have a parameter hash and activate this option, the compiler can avoid this check. =back =item objects (fixed) (since 0.91_001) if set to true, you can use method calls like <%= object.method %> Default is 'strict' (true). If set to 'strict', the method will be called if we have an object, otherwise it's treated as a hash lookup. If the method doesn't exist, it dies. If set to 'nostrict', the method will be called only if the object 'can' do the method, otherwise it will return undef (this will need Scalar::Util). If set to 0, no method calls are allowed. =item deref (fixed) Deprecated. Please inherit and overwrite method 'deref'. See L<"INHERITANCE"> Define the string you want to use for dereferencing, default is C<.> at the moment: =item method_call (fixed) Deprecated. Please inherit and overwrite method 'method_call'. See L<"INHERITANCE"> Define the string you want to use for method calls, default is . at the moment: Don't use ->, though, like you could in earlier version. Var names can contain: Numbers, letters, '.', '/', '+', '-' and '_', just like HTML::Template. Note that if your var names contain dots, though, they will be treated as hash dereferences. If you want literal dots, use L instead. =item default_path (fixed) Deprecated, see L please. my $htc = HTML::Template::Compiled->new( ... default_path # default is PATH_DEREF => HTML::Template::Compiled::Utils::PATH_FORMATTER, ); Is needed if you have an unqualified tmpl_var that should be resolved as a call to your formatter, for example. Otherwise you have to call it fully qualified. If your formatter_path is '/', you'd say tmpl_var C<_/method>. With the option default_path you can make that the default, so you don't need the C<_/>: C. If you don't use formatters, don't care about this option. =item line_numbers NOTE: This option does not exist any more; line numbers will always be reported. For debugging: prints the line number of the wrong tag, e.g. if you have a /TMPL_IF that does not have an opening tag. =item case_sensitive (fixed) default is 1, set it to 0 to use this feature like in HTML::Template. Note that this can slow down your program a lot (50%). =item dumper This option is deprecated as of version 0.76. You must now use a plugin instead, like L, for example. my $t = HTML::Template::Compiled->new( ... dumper = sub { my_cool_dumper($_[0]) }, ); --- This will call C on C. Alternatively you can use the DHTML plugin which is using C and C. You'll get a dumper like output which you can collapse and expand, for example. See L and L for more information. Example: my $t = HTML::Template::Compiled->new( ... dumper = 'DHTML', ); For an example see C. =item out_fh (fixed) my $t = HTML::Template::Compiled->new( ... out_fh => 1, ); ... $t->output($fh); # or output(\*STDOUT) or even output() This option is fixed, so if you create a template with C, every output of this template will print to a specified (or default C) filehandle. =item filter Filter template code before parsing. my $t = HTML::Template::Compiled->new( ... filter => sub { myfilter( ${$_[0]} ) }, # or filter => [ { sub => sub { myfilter( ${$_[0]} ) }, format => 'scalar', # or array }, ... ], ); =item tagstyle (fixed) Specify which styles you want to use. This option takes an arrayref with strings of named tagstyles or your own regexes. At the moment there are the following named tagstyles builtin: # classic (active by default) # comment (active by default) # asp (active by default) <%if foo%><%VAR bar%><%/if%> # php (not active by default) # tt (not active by default) [%if foo%][%var bar%][%/if foo%] You deactivate a style by saying -stylename. You activate by saying +stylename. Define your own tagstyle by specifying regexes. For example you want to use {C<{{if foo}}{{var bar}}{{/if foo}}>, then your definition should be: [ qr({{), # start of opening tag qr(}}), # end of opening tag qr({{/), # start of closing tag qr(}}), # end of closing tag ] NOTE: do not specify capturing parentheses in you regexes. If you need parentheses, use C<(?:foo|bar)> instead of C<(foo|bar)>. Say you want to deactivate asp-style, comment-style, activate php- and tt-style and your own C<{{}} > style, then say: my $htc = HTML::Template::Compiled->new( ... tagstyle => [ qw(-asp -comment +php +tt), [ qr({{), qr(}}), qr({{/), qr(}})], ], ); =item use_expressions (since 0.91_003) Set to 1 if you want to use expressions. The basic expressions work more or less like in L - I took the parsing code from it and used it with some minor changes - thanks to Sam Tregar. <%if expr="some.var > 3" %>It's grater than 3<%/if %> But with expressions you can also use more complex navigation through the template stash: You can use object methods with parameters. While a normal method call can only be called without parameters, like <%= object.name %> with expressions you can give it parameters: <%= expr="object.create_link('navi')" %> Inside function and method calls, hash keys you also can use template vars (array indices and hash keys since 0.96_003). <%= expr=".path.to.hash{var}" %> <%= expr=".path.to.hash{.another.var[123]}{'literal key'}" %> It is only minimally tested yet, so use with care and please report any bugs you find. A useful example: Output a number of items with their prices formatted. my $nf = Number::Format->new(...); my $htc = HTML::Template::Compiled->new( filename => 'items.html', use_expressions => 1, ); $htc->param( items => [ { size => 50 * 1024 * 1024 * 1024, price => 49.95 }, { size => 250 * 1024 * 1024 * 1024, price => 110.99 }, ], nf => $nf, ); items.html: <%loop .items %> Size: <%= expr=".nf.format_bytes(size)" %> Price: <%= expr=".nf.format_price(price)" %> <%/loop %> Output: Size: 50G Price: 49,95 EUR Size: 250G Price: 110,99 EUR =item formatter Deprecated, see L please. With formatter you can specify how an object should be rendered. This is useful if you don't want object methods to be called, but only a given subset of methods. my $htc = HTML::Template::Compiled->new( ... formatter => { 'Your::Class' => { fullname => sub { $_[0]->first . ' ' . $_[0]->last }, first => Your::Class->can('first'), last => Your::Class->can('last'), }, }, ); # $obj is a Your::Class object $htc->param(obj => $obj); # Template: # Fullname: =item formatter_path (fixed) Deprecated, see L please. =item debug If set to 1 you will get the generated perl code on standard error =item use_query Set it to 1 if you plan to use the query() method. Default is 0. Explanation: If you want to use query() to collect information on the template HTC has to do extra-work while compiling and uses extra-memory, so you can choose to save HTC work by setting use_query to 0 (default) or letting HTC do the extra work by setting it to 1. If you would like 1 to be the default, write me. If enough people write me, I'll think about it =) =item use_perl Set to 1 if you want to use the perl-tag. See L<"TMPL_PERL">. Default is 0. =item cache_debug Default: 0 You can debug hits and misses for file cache and memory cache: # debug all cache my $htc = HTML::Template::Compiled->new( cache_debug => 1, ... ); # only debug misses my $htc = HTML::Template::Compiled->new( cache_debug => [qw/ file_miss mem_miss /], ... ); Possible values when passing an array ref: file_miss file_hit mem_miss mem_hit Output looks similar to HTML::Template cache_debug and will be output to STDERR via warn(). =back =head2 METHODS =over 4 =item clear_cache ([DIR]) Class method. It will clear the memory cache either of a specified cache directory: HTML::Template::Compiled->clear_cache($cache_dir); or all memory caches: HTML::Template::Compiled->clear_cache(); =item clear_filecache Class- or object-method. Removes all generated perl files from a given directory. # clear a directory HTML::Template::Compiled->clear_filecache('cache_directory'); # clear this template's cache directory (and not one template file only!) $htc->clear_filecache(); =item param Works like in L. =item query Works like in L. But it is not activated by default. If you want to use it, specify the use_query option. =item preload Class method. Will preload all template files from a given cachedir into memory. Should be done, for example in a mod_perl environment, at server startup, so all templates go into "shared memory" HTML::Template::Compiled->preload($cache_dir); If you don't do preloading in mod_perl, memory usage might go up if you have a lot of templates. Note: the directory is *not* the template directory. It should be the directory which you give as the file_cache_dir option. =item precompile Class method. It will precompile a list of template files into the specified cache directory. See L<"PRECOMPILE">. =item clear_params Empty all parameters. =item debug_code (since 0.91_003) If you get an error from the generated template, you might want to debug the executed code. You can now call C to get the compiled code and the line the error occurred. Note that the reported line might not be the exact line where the error occurred, also look around the line. The template filename reported does currently only report the main template, not the name of an included template. I'll try to fix that. local $HTML::Template::Compiled::DEBUG = 1; my $htc = HTML::Template::Compiled->new( filename => 'some_file_with_runtime_error.html', ); eval { print $htc->output; }; if ($@) { # reports as text my $msg = $htc->debug_code; # reports as a html table my $msg_html = $htc->debug_code('html'); } =item get_plugin my $plugin = $htc->get_plugin('Name::of::plugin'); Returns the plugin object of that classname. If the plugin is only a string (the classname itself), it returns this string, so this method is only useful for plugin objects. =item var2expression Useful for plugins. Parses a template var (C and returns the perl expression for the compiler. =back =head1 EXPORT None. =head1 CACHING You create a template almost like in HTML::Template: my $t = HTML::Template::Compiled->new( path => 'templates', loop_context_vars => 1, filename => 'test.html', # for testing without cache comment out file_cache => 1, file_cache_dir => "cache", ); The next time you start your application and create a new template, HTC will read all generated perl files, and a call to the constructor like above won't parse the template, but just use the loaded code. If your template file has changed, though, then it will be parsed again. You can set the expire time of a template by passing the option expire_time => $seconds Note that HTML::Template::Compiled->ExpireTime($seconds); C<$HTML::Template::Compiled::NEW_CHECK> are deprecated since they change a global variable which is then visible in the whole process, so in persistent environments other apps might be affected. So an expire time of 600 seconds (default) will check after 10 minutes if the tmpl file was modified. Set it to a very high value will then ignore any changes, until you delete the generated code. For development you should set it to 0, for a pre-production server you can set it to 60 seconds, for example. It can make quite a difference. =head1 PLUGINS At the moment you can use and write plugins for the C attribute. See L for an example how to use it; and have a look at the source code if you want to know how to write a plugin yourself. Using Plugins: my $htc = HTML::Template::Compiled->new( ... plugin => ['HTML::Template::Compiled::Foo::Bar'], # oor shorter: plugin => ['::Foo::Bar'], ); =head1 LAZY LOADING Let's say you're in a CGI environment and have a lot of includes in your template, but only few of them are actually used. HTML::Template::Compiled will (as L does) parse all of your includes at once. Just like the C function does in perl. To get a behaviour like require, use L. =head1 TODO associate, methods with simple parameters, expressions, pluggable, ... =head1 IMPLEMENTATION HTC generates a perl subroutine out of every template. Each included template is a subroutine for itself. You can look at the generated code by activating file caching and looking into the cache directory. When you call C, the subroutine is called. The subroutine either creates a string and adds each template text or the results of the tags to the string, or it prints it directly to a filehandle. Because of the implementation you have to know at creation time of the module if you want to get a string back or if you want to print to a filehandle. =head1 SECURITY HTML::Template::Compiled uses basically the same file caching model as, for example, Template- Toolkit does: The compiled Perl code is written to disk and later reread via C or by reading the file and C the content. If you are sharing a read/write environment with untrusted users (for example on a machine with a webserver, like many webhosters offer, and all scripts are running as the same httpd user), realize that there is possibility of modifying the Perl code that is cached and then executed. The best solution is to not be in such an environment! In this case it is the safest option to generate your compiled templates on a local machine and just put the compiled templates onto the server, with no write access for the http server. Set the C option to a high value so that HTC never attempts to check the template timestamp to force a regenerating of the code. If you are alone on the machine, but you are running under taint mode (see L) then you have to explicitly set the C<$UNTAINT> variable to 1. HTC will then untaint the code for you and treat it as if it were safe (it hopefully is =). =head1 PRECOMPILE I think there is no way to provide an easy function for precompiling, because every template can have different options. If you have all your templates with the same options, then you can use the precompile class method. It works like this: HTML::Template::Compiled->precompile( # usual options like path, default_escape, global_vars, file_cache_dir, ... filenames => [ list of template-filenames ], ); This will then pre-compile all templates into file_cache_dir. Now you would just put this directory onto the server, and it doesn't need any write-permissions, as it will be never changed (until you update it because templates have changed). =head1 BENCHMARKS The options C, C and C can have the biggest influence on speed. Setting case_sensitive to 1, loop_context_vars to 0 and global_vars to 0 saves time. On the other hand, compared to HTML::Template, you have a large speed gain under mod_perl if you use case_sensitive = 1, loop_context_vars = 0, With CGI HTC is slower. See the C contained in this distribution. Here are some examples from the benchmark script. I'm showing only Template::AutoFilter, Template::HTML, HTML::Template and HTC. These four modules allow you to set automatic HTML escaping ('filter') for all variables. loop_context_vars 1 global_vars 0 case_sensitive 1 default_escape HTML (respectively Template::AutoFilter and Template::HTML) ht: HTML::Template 2.10 htc: HTML::Template::Compiled 0.95 ttaf: Template::AutoFilter 0.112350 with Template 2.22 tth: Template::HTML 0.02 with Template 2.22 First test is with the test.(htc|tt) from the examples directory, about 900 bytes. Test without file cache and without memory cache. all_ht: 1 wallclock secs ( 0.40 usr + 0.00 sys = 0.40 CPU) @ 250.00/s (n=100) all_htc: 1 wallclock secs ( 1.74 usr + 0.01 sys = 1.75 CPU) @ 57.14/s (n=100) all_ttaf_new_object: 1 wallclock secs ( 1.69 usr + 0.01 sys = 1.70 CPU) @ 58.82/s (n=100) all_tth_new_object: 1 wallclock secs ( 1.44 usr + 0.00 sys = 1.44 CPU) @ 69.44/s (n=100) With file cache: all_ht: 1 wallclock secs ( 1.03 usr + 0.01 sys = 1.04 CPU) @ 379.81/s (n=395) all_htc: 1 wallclock secs ( 1.07 usr + 0.00 sys = 1.07 CPU) @ 260.75/s (n=279) all_ttaf_new_object: 1 wallclock secs ( 1.07 usr + 0.04 sys = 1.11 CPU) @ 251.35/s (n=279) all_tth_new_object: 1 wallclock secs ( 1.01 usr + 0.04 sys = 1.05 CPU) @ 227.62/s (n=239) With memory cache: all_ht: 1 wallclock secs ( 1.04 usr + 0.00 sys = 1.04 CPU) @ 461.54/s (n=480) all_htc: 1 wallclock secs ( 1.05 usr + 0.01 sys = 1.06 CPU) @ 3168.87/s (n=3359) process_ttaf: 1 wallclock secs ( 1.04 usr + 0.00 sys = 1.04 CPU) @ 679.81/s (n=707) process_tth: 1 wallclock secs ( 1.05 usr + 0.00 sys = 1.05 CPU) @ 609.52/s (n=640) Now I'm using a template with about 18Kb by multiplying the example template 20 times. You can see that everything is running slower but some run more slower than others. Test without file cache and without memory cache. all_ht: 8 wallclock secs ( 7.57 usr + 0.04 sys = 7.61 CPU) @ 13.14/s (n=100) all_htc: 32 wallclock secs (32.08 usr + 0.06 sys = 32.14 CPU) @ 3.11/s (n=100) all_ttaf_new_object: 36 wallclock secs (36.21 usr + 0.04 sys = 36.25 CPU) @ 2.76/s (n=100) all_tth_new_object: 29 wallclock secs (28.92 usr + 0.05 sys = 28.97 CPU) @ 3.45/s (n=100) With file cache: all_ht: 8 wallclock secs ( 7.22 usr + 0.00 sys = 7.22 CPU) @ 13.85/s (n=100) all_htc: 5 wallclock secs ( 5.32 usr + 0.00 sys = 5.32 CPU) @ 18.80/s (n=100) all_ttaf_new_object: 8 wallclock secs ( 7.59 usr + 0.15 sys = 7.74 CPU) @ 12.92/s (n=100) all_tth_new_object: 9 wallclock secs ( 8.74 usr + 0.19 sys = 8.93 CPU) @ 11.20/s (n=100) With memory cache: all_ht: 1 wallclock secs ( 1.04 usr + 0.01 sys = 1.05 CPU) @ 15.24/s (n=16) all_htc: 1 wallclock secs ( 1.12 usr + 0.00 sys = 1.12 CPU) @ 272.32/s (n=305) process_ttaf: 1 wallclock secs ( 1.07 usr + 0.00 sys = 1.07 CPU) @ 39.25/s (n=42) process_tth: 1 wallclock secs ( 1.05 usr + 0.00 sys = 1.05 CPU) @ 34.29/s (n=36) So the performance difference highly depends on the size of the template and on the various options. You can see that using the 900byte template HTC is slower with file cache than HTML::Template, but with the 18Kb template it's faster. =head1 EXAMPLES See L (and C) for an example how to feed objects to HTC. =head1 BUGS Probably many bugs I don't know yet =) Use the bugtracking system to report a bug: http://rt.cpan.org/NoAuth/Bugs.html?Dist=HTML-Template-Compiled =head1 Why another Template System? You might ask why I implement yet another templating system. There are so many to choose from. Well, there are several reasons. I like the syntax of HTML::Template *because* it is very restricted. It's also easy to use (template syntax and API). However, there are some things I miss I try to implement here. I think while HTML::Template is quite good, the implementation can be made more efficient (and still pure Perl). That's what I'm trying to achieve. I use it in my web applications, so I first write it for myself =) If I can efficiently use it, it was worth it. =head1 RESOURCES See http://htcompiled.sf.net/ for svn access. =head1 SEE ALSO L L L