diff -Nru libtext-micromason-perl-2.13/CHANGES libtext-micromason-perl-2.16/CHANGES --- libtext-micromason-perl-2.13/CHANGES 1970-01-01 00:00:00.000000000 +0000 +++ libtext-micromason-perl-2.16/CHANGES 2015-06-26 18:11:42.000000000 +0000 @@ -0,0 +1,591 @@ +NAME + Text::MicroMason::Docs::Changes - Change History for the MicroMason + Distribution + +VERSION 2 HISTORY + Version 2.16 + 2015-06-27 + Remove garbage files from dist. + + Version 2.15 + 2015-06-27 + [rt.cpan.org #105499] Fix regression due to new error/warning format + in Perl 5.22. + + [rt.cpan.org #92771] Fix line number regressionf due to a Perl line + numbering bugfix. This passes tests but I'm not entirely convinced + it's correct. + + Version 2.14 + 2013-06-11 + [rt.cpan.org #85965] Fix POD errors in Changes.pod. + + Version 2.13 + 2011-01-13 + [rt.cpan.org #64192] Skip the Safe-related tests more often, since + newer versions of Safe.pm mark their own failing tests as TODO + instead of changing the module's behavior. + + Version 2.12 + 2010-09-07 + Skip more tests that fail due to a bug in Safe.pm. Add a prereq for + Safe.pm so CPAN testers will provide more debug info on failure. + + Version 2.11 + 2010-09-07 + [rt.cpan.org #61010] Fix spelling errors and pod example bugs. + Thanks to vshih at yahoo.com for reporting these problems. + + 2010-09-07 + Under Perl 5.13.1 and later with Safe version 2.27, skip failing + tests in t/32-safe.t. The regression tests for Safe 2.27 fail in + Perl 5.13.1 as well, in a similar way. This bug is not fixable in + any reasonable way until Safe.pm is also stable. + + 2010-07-26 + [rt.cpan.org #59081] Fix spelling and pod errors. Thanks to Ansgar + Burchardt and the Debian project for submitting this bug report + along with patches. + + Version 2.10 + 2010-06-29 + [rt.cpan.org #57797] Deprecate safe_methods parameter. + Unfortunately, Safe.pm version 2.27 patches a bug we were + inadvertantly taking advantage of to implement the safe_methods + parameter. Unless we can find a working implementation of + safe_methods that is smaller than "make everything unsafe" then we + can't continue to support safe_methods. + + Using safe_methods now issues a deprecation warning, but it should + work with older versions of Safe. I'm in no hurry to remove the + feature, but I don't want anyone to use it who isn't already using + it, until we know it can be supported in the future. + + Thanks to Niko Tyni and the Debian Perl Group for submitting this + bug report. + + 2010-04-05 + "uninitialized" warnings in templates were being generated at a line + number within MicroMason instead of a line number within the + template itself. Thanks to Mike Kelly for a patch: by concatenating + an empty string to each TOKEN within the template, the warning's + line number is shifted to inside the template where the + interpolation took place. + + Version 2.09 + 2010-03-24 + Fix test that was broken by changes in URI::Escape 1.30. Double + quotes aren't reserved characters in URIs but they were previously + encoded anyway. Test modified to use reserved single quotes instead, + for URI::Escape testing. + + Version 2.08 + 2010-03-08 + Fixed PassVariables bug: <%init> failed with -PassVariables plugin. + Thanks to William Kern for reporting this. + + 2009-11-19 + Fixed [rt.cpan.org #51727] [Patch] POD nit; thanks to Frank Wiegand + for reporting this. + + Version 2.07 + 2009-11-16 + Merge patch from Simon Cavalletto: fix bug reported in CPAN forum + with "OUT" appearing in the input template stream. Thanks! + + Update requirement for Test::More 0.48 or later in Makefile.PL. + Tests using unlike() failed with Test::More version 0.47. + + Fix problem in t/08_errors.t which caused test failures in Perl 5.6. + The error message isn't as important as the test made it out to be, + but the code didn't have a problem. + + 2009-11-12 + Remove documentation for unsupported compile(lines => ...) mode. Put + it on ToDo instead. + + Version 2.06 + 2009-11-11 + Fix bug reported in CPAN forum: substr() in LineNumbers.pm was being + used incorrectly, resulting in incorrect line numbering in some + cases. + + 2009-11-12 + #51460: Clean up the tarball and resubmit a version that doesn't + contain a stray .tgz file. + + Version 2.05 + 2009-11-10 + Modify compilation error reporting: provide line numbers when + dumping the compiled template into $@, and change the #line to match + the line numbering correctly. + + 2009-11-11 + Fix bug reported by CPAN testers on some Windows boxes: use + Cwd::abs_path for strict_root checking to avoid literal path + separators in TemplateDir.pm. + + 2009-11-11 + Add a hint about -LineNumbers in the numbered template dump when a + compilation error occurs. + + Version 2.04 + 2009-11-06 + Fixed SKIP count in t/33_filters.t to prevent test failures when + URI::Escape isn't installed. + + Version 2.03 + 2009-10-30 + Happy Halloween. + + Updated tests to use Test::More for better diagnostics via CPAN + testers. + + Tweaked t/34 with a longer sleep() since some linux hosts seemed to + be sleeping for less than a second with sleep(1). + + Version 2.02 + 2009-10-29 + Updated Changes.pod. + + Fixed SKIP count in t/33 which caused test count mismatches when + HTML::Entities wasn't installed. + + Version 2.01 + 2009-10-29 + Fix a bug with TemplatePath error messages. If a template name was + provided that didn't exist in the path, the error message generated + by read_file didn't specify which template was requested. This + version now croaks in resolve_path instead of returning undef and + letting read_file croak. + + Updated pod to reflect this change and document previously + undocumented exception strings. + + Modified undocumented exception strings for strict_root violations. + + Version 2.0 + 2008-01-02 + Fix bug with || filter patch: it was erroneously removing the last + character of the filtered token, which made it fail if there was no + space before the |. + + Bump version to 2.0 + + Version 1.993_01 + 2007-12-21 + Add LineNumbers mixin and associated tests. + + 2007-12-21 + Update TODO: move almost everything into a WISH LIST with a request + for contributions, and make the main TODO list bug fixes and a few + likely developments. + + 2007-12-21 + Merge test and patch from RT bug #21802: cache expiration bug. + + 2007-12-21 + Merge changes from RT bug #18435: filter problem with <% $thing || + "default" %> + + 2007-12-21 + Bump version to 1.993_01 + + Version 1.993 + 2007-12-20 + Merge changes from pair Networks local branch, which have been in + testing and production since Q1 2007; bump version to 1.993. + + This includes: + + TemplatePath mixin + Template lookups on a search path + + TemplateDir/ Cache patch + fix interaction of caching and TemplateDir/TemplatePath + + Additional test files + Stop creating cache objects unless/until they're used + + Version 1.992_01 + 2007-12-20 + Updated pod and makefiles for maintenance transition from Simon to + Alan. Thanks for the wonderful module, Simon! I hope I can keep + things under control. + + Bumped version number. + + Version 1.992 + 2005-11-13 + Updated ToDo.pod with a few ideas for upcoming releases. + + Extended t/58-quicktemplate.t to demonstrate use of the pre_fill + method. + + 2005-11-12 + Fixed incorrect handling of default values for array or hash + variables in an <%args> block. Thanks to Alexander for the bug + report. + + Added extra newlines to the do blocks generated by Base's + assemble(), so that <% exprs %> can contain a comment. Problem + reported by Alexander. + + Improved error reporting by changing the file name embedded in the + CPP-style line number comment at the top of each stretch of + generated Perl code. Based on a problem report from Alexander. This + does not fix the line numbering problem, but at least the file name + is more helpful than it used to be. + + 2005-08-24 + Added RoughDraft of "ParseInfo.pm" based on a reply to a question + via email from Alexander. + + 2005-07-30 + Fixed return value from Text::MicroMason::Cache::File set() method; + thanks to Alan Ferrency for the helpful bug report and test case. + + 2005-07-24 + Extracted HasParams and StoreOne mixins from HTMLTemplate. + + Added QuickTemplate mixin class with emulation for + Text::QuickTemplate. + + 2005-07-20 + Added reference links to benchmarking section in Docs/ToDo.pod. + + Added "local $^W;" in two test scripts to silence extra warning on + Perl 5.005_04. + + Bumped version number. + + Version 1.991 + 2005-07-19 + Bumped version number. + + Added ApacheHandler configuration options and basic documentation. + + 2005-07-18 + Added PLP mixin class with emulation for PLP templating package. + + Added the skeleton for a basic ApacheHandler class. + + Improved strict_root support in TemplateDir and added documentation + for it. + + Extracted argument passing logic from TextTemplate to create new + PassVariables mixin. + + Added Sprintf syntax mixin and basic tests. + + 2005-07-17 + Added DoubleQuote syntax mixin and basic tests. + + Version 1.99 + 2005-07-09 + Added AllowGlobals mixin based on suggestion and patch from Jonas + Alves. Reviewed similar functionality in HTML::Mason and added docs + and tests. + + Extracted debug options to separate Debug mixin class. + + Changed name of internal new() method to create(), while propogating + the mixin finding behavior from the Text::MicroMason facade up to + Text::MicroMason::Base. + + Renamed examples directory to samples. + + Added read_handle method and output_sub attribute. + + Added assembler_vars method and removed %Assembler global. + + 2004-12-01 + Fixed early exit of t/42-text_template.t to skip test if missing + Text::Balanced. + + 2004-11-30 + Renamed the Mason compatibilty class to HTMLMason to match other + syntax classes. Changed it to be a mixin like the other classes, + instead of a subclass. + + Switched to use of Class::MixinFactory and removed old class() and + NEXT() methods. + + Extracted new interpret() method from inside of compile(). + + Adjusted setting of options and attributes so that this doesn't + happen within interpret(). + + Extracted list of related modules to new Docs::Related POD file. + + Version 1.98 + 2004-11-29 + Fixed unprotected test dependency on Text::Balanced for TextTemplate + emulation. + + Fixed unexpected side-effect of change to parsing for + single-character Filter flags. + + Minor adjustments to POD documentation. + + Version 1.97 + 2004-11-28 + Moved to do list into new pod file. Moved extra pod files into Docs + namespace. + + Added _printable to default set of functions in Filters. Tweaked + parse_filters and get_filter_functions methods. + + Changed internal names for ouput and include token types to expr and + file. Corrected typo in one of the assembler token names. + + Adjusted $Carp::CarpLevel in Base croak_msg(). + + Fixed test failure in t/33-filters.t reported by William Kern. + + 2004-10-24 + Fixed typo in ServerPages example; thanks to William Kern for + pointing it out. + + 2004-10-20 + Adjustments to documentation in top-level package. + + Version 1.96 + 2004-10-19 + Added PostProcess mixin class at the suggestion of Alan Ferrency. + + Renamed a few keys in the hash returned by assembler_rules(). + + Moved syntax documentation to Mason subclass. + + Version 1.95 + 2004-10-19 + Fixed problem with extra semicolons breaking code statements broken + onto multiple % code lines; thanks to Alan Ferrency for test code to + isolate the problem, now added to regression tests. + + 2004-10-17 + Documentation updates. + + Version 1.94 + 2004-10-17 + Factored subclass-specific lex_token() method out from superclass + lex() method. + + Added Embperl mixin class with emulation for HTML::Embperl. + + Merged Devel.pod back in to other package documentation. + + 2004-10-16 + Replaced assembler attribute with assembler_rules() method. + + Added Mason subclass and moved some functionality to there from + Base. + + Documentation updates. + + 2004-10-15 + Added HTMLTemplate mixin class with emulation for HTML::Template. + + 2004-10-13 + Added TextTemplate mixin class with emulation for Text::Template. + + Version 1.93 + 2004-10-12 + Instead of run-time eval of @MIXIN to fix SUPER resolution, now + using a new SUPER method. + + 2004-10-11 + Documentation updates. + + Version 1.92 + 2004-10-11 + Uploaded to CPAN to fix packaging issue with 1.9_1. + + Version 1.91 + 2004-10-10 + Posted description of mixin mechanism to PerlMonks for discussion. + + Debugged CompileCache and finished ExecuteCache. Added test scripts. + + Debugged TemplateDir and added test script. + + Implemented support for one-time options passed to compile that + override other attributes. Adjusted Safe facade to prevent this from + being done there, in order to avoid escapes from a Safe compartment. + + 2004-10-09 + Reorganized t/ directory. + + Version 1.90 + 2004-10-08 + Documentation updates. + + 2004-10-05 + Documentation updates. + + Version 1.55 + 2004-09-23 + Documentation updates. + + Version 1.54 + 2004-09-22 + Renamed "interpret" method to "execute" for consistency with + function interface. + + Moved try_ functionality to new ErrorCatching mixin. + + Generalized behavior of assemble method; moved template elements + into %Assembly hash. + + Version 1.53 + 2004-09-22 + Moved Safe functionality to new Safe mixin. + + Moved filtering functionality to new Filters mixin. + + 2004-09-21 + Added mixin inheritance hacking logic based on + DBIx::SQLEngine::Record::Class. + + Version 1.52 + 2004-09-19 + Extracted Changes to separate POD document. + + 2004-09-18 + Additional work. + + Version 1.51 + 2004-09-17 + Refactoring of method interface to merge compie and interpretation + into single subroutines with parameters to indicate whether we're + reading text or a file. + + Added initial support for filtering interpolated expressions based + on a patch and extended discussion with Alan Ferrency. + + Packaged as version 1.51 but not released to CPAN. + + 2004-09-16 + Refactored to object-oriented implementation to allow subclassing. + Inspired by discussion with Alan Ferrency about how to extend + functionality. + + Started CodeCache subclass based on experimental caching code + included in 1.07. + + Started TemplateDir subclass with base directory and relative path + calculations based on a patch from Tommi Maekitalo. + + Incorporated patch from Tommi Maekitalo to put default values from + an <%args> block into the %ARGS variable as well as the separate + named variables. + + Created ServerPages subclass based on feature request from William + Kern. + + 2004-09-15 + Moved package documentation into separate ReadMe.pod. + +VERSION 1 HISTORY + Version 1.07 + 2003-09-26 + Discard line break after <%perl> block as suggested by Tommi + Maekitalo. Note that removing these line breaks may affect the + rendering of your current templates! Although I am typically + hesitant to change established behavior, this does improve the + template output and brings us into line with HTML::Mason's behavior. + + Added $Debug flag and support for <%args> blocks based on a + contribution by Tommi Maekitalo. + + Adjusted internals to allow block reordering, and added support for + <%init> and <%once>. + + Released as Text-MicroMason-1.07.tar.gz. + + Version 1.06 + 2003-09-04 + Changed the way that subroutines were scoped into the + Text::MicroMason::Commands namespace so that Safe compartments with + separate namespaces and shared symbols have the visibility that one + would expect. + + Fixed a bug in which an unadorned percent sign halted parsing, as + reported by William Kern at PixelGate. Added a test to the end of + 6-regression.t that fails under 1.05 but passes under 1.06 to + confirm this. + + Simplified parser regular expressions by using non-greedy matching. + + Added documentation for *_file() functions. Corrected documentation + to reflect the fact that template code is not compiled with "use + safe" in effect by default, but that this might change in the + future. + + Released as Text-MicroMason-1.06.tar.gz. + + Version 1.05 + 2003-08-11 + Adjusted regular expression based on parsing problems reported by + Philip King and Daniel J. Wright, related to newlines and EOF. Added + regression tests that fail under 1.04 but pass under 1.05 to ensure + these features keep working as expected. + + Added non-printing-character escaping to parser failure and + debugging messages to better track future reports of + whitespace-related bugs. + + Moved tests from test.pl into t/ subdirectory. + + Added experimental suppport for file code cache in + compile_file_codecache. + + Released as Text-MicroMason-1.05.tar.gz. + + Version 1.04 + 2002-06-23 + Adjusted regular expression based on parsing problems reported by + Mark Hampton. + + Added file-include support with <& ... &> syntax. + + Documentation tweaks. Adjusted version number to simpler 0.00 + format. Released as Text-MicroMason-1.04.tar.gz. + + 2002-01-14 + Documentation tweaks based on feedback from Pascal Barbedor. Updated + author's contact information. + + Version 1.0.3 + 2001-07-01 + Renamed from HTML::MicroMason to Text::MicroMason. Documentation + tweaks. Released as Text-MicroMason-1.0.3.tar.gz. + + Version 1.0.2 + 2001-04-10 + Munged interface for clarity. Added Safe support. Adjusted docs to + reflect feedback from mason-users. Released as + HTML-MicroMason-1.0.2.tar.gz. + + Version 1.0.1 + 2001-03-28 + Parser tweakage; additional documentation. Added Exporter support. + Released as HTML-MicroMason-1.0.1.tar.gz. + + 2001-03-26 + Added try_interpret; documented error messages. + + Version 1.0.0 + 2001-03-23 + Extended documentation; added makefile, test script. Renamed + accumulator to $OUT to match Text::Template. Released as + HTML-MicroMason-1.0.0.tar.gz. + + 2001-03-22 + Created. + +SEE ALSO + For distribution, installation, support, copyright and license + information, see Text::MicroMason::Docs::ReadMe. + diff -Nru libtext-micromason-perl-2.13/debian/changelog libtext-micromason-perl-2.16/debian/changelog --- libtext-micromason-perl-2.13/debian/changelog 2015-06-26 10:03:02.000000000 +0000 +++ libtext-micromason-perl-2.16/debian/changelog 2015-06-26 19:05:14.000000000 +0000 @@ -1,3 +1,13 @@ +libtext-micromason-perl (2.16-1) unstable; urgency=medium + + * New upstream release. + * Drop all patches. All merged upstream or fixed otherwise. + * Update doc handling in debian/*. + Some files are shipped as text/plain now, others are moved. + * Mark package as autopkgtest-able. + + -- gregor herrmann Fri, 26 Jun 2015 21:04:54 +0200 + libtext-micromason-perl (2.13-4) unstable; urgency=medium [ Salvatore Bonaccorso ] diff -Nru libtext-micromason-perl-2.13/debian/clean libtext-micromason-perl-2.16/debian/clean --- libtext-micromason-perl-2.13/debian/clean 2015-06-26 10:03:02.000000000 +0000 +++ libtext-micromason-perl-2.16/debian/clean 2015-06-26 19:05:14.000000000 +0000 @@ -1,4 +1 @@ -CHANGES -README RELATED -TODO diff -Nru libtext-micromason-perl-2.13/debian/control libtext-micromason-perl-2.16/debian/control --- libtext-micromason-perl-2.13/debian/control 2015-06-26 10:03:02.000000000 +0000 +++ libtext-micromason-perl-2.16/debian/control 2015-06-26 19:05:14.000000000 +0000 @@ -16,6 +16,7 @@ Vcs-Browser: https://anonscm.debian.org/cgit/pkg-perl/packages/libtext-micromason-perl.git Vcs-Git: git://anonscm.debian.org/pkg-perl/packages/libtext-micromason-perl.git Homepage: https://metacpan.org/release/Text-MicroMason +Testsuite: autopkgtest-pkg-perl Package: libtext-micromason-perl Architecture: all diff -Nru libtext-micromason-perl-2.13/debian/patches/fix-changes-pod.patch libtext-micromason-perl-2.16/debian/patches/fix-changes-pod.patch --- libtext-micromason-perl-2.13/debian/patches/fix-changes-pod.patch 2015-06-26 10:03:02.000000000 +0000 +++ libtext-micromason-perl-2.16/debian/patches/fix-changes-pod.patch 1970-01-01 00:00:00.000000000 +0000 @@ -1,85 +0,0 @@ -Description: fix POD issues -Origin: vendor -Bug: http://rt.cpan.org/Public/Bug/Display.html?id=85965 -Forwarded: http://rt.cpan.org/Public/Bug/Display.html?id=85965 -Bug-Debian: http://bugs.debian.org/711271 -Author: gregor herrmann -Last-Update: 2013-06-16 - ---- a/MicroMason/Docs/Changes.pod -+++ b/MicroMason/Docs/Changes.pod -@@ -5,25 +5,33 @@ - - =head1 VERSION 2 HISTORY - --=over 4 -- - =head2 Version 2.13 - -+=over 4 -+ - =item 2011-01-13 - - [rt.cpan.org #64192] Skip the Safe-related tests more often, since newer - versions of Safe.pm mark their own failing tests as TODO instead of - changing the module's behavior. - -+=back -+ - =head2 Version 2.12 - -+=over 4 -+ - =item 2010-09-07 - - Skip more tests that fail due to a bug in Safe.pm. Add a prereq for - Safe.pm so CPAN testers will provide more debug info on failure. - -+=back -+ - =head2 Version 2.11 - -+=over 4 -+ - =item 2010-09-07 - - [rt.cpan.org #61010] Fix spelling errors and pod example bugs. Thanks to -@@ -42,8 +50,12 @@ - Burchardt and the Debian project for submitting this bug report along - with patches. - -+=back -+ - =head2 Version 2.10 - -+=over 4 -+ - =item 2010-06-29 - - [rt.cpan.org #57797] Deprecate safe_methods parameter. Unfortunately, -@@ -68,8 +80,12 @@ - string to each TOKEN within the template, the warning's line number is - shifted to inside the template where the interpolation took place. - -+=back -+ - =head2 Version 2.09 - -+=over 4 -+ - =item 2010-03-24 - - Fix test that was broken by changes in URI::Escape 1.30. Double -@@ -77,8 +93,12 @@ - encoded anyway. Test modified to use reserved single quotes instead, - for URI::Escape testing. - -+=back -+ - =head2 Version 2.08 - -+=over 4 -+ - =item 2010-03-08 - - Fixed PassVariables bug: <%init> failed with -PassVariables plugin. diff -Nru libtext-micromason-perl-2.13/debian/patches/perl-5.22-errors.patch libtext-micromason-perl-2.16/debian/patches/perl-5.22-errors.patch --- libtext-micromason-perl-2.13/debian/patches/perl-5.22-errors.patch 2015-06-26 10:03:02.000000000 +0000 +++ libtext-micromason-perl-2.16/debian/patches/perl-5.22-errors.patch 1970-01-01 00:00:00.000000000 +0000 @@ -1,38 +0,0 @@ -Description: fix test failure with perl 5.22 - perl 5.22 errors are a bit more verbose - allow old and new variants -Origin: vendor -Bug-Debian: https://bugs.debian.org/789855 -Author: gregor herrmann -Last-Update: 2015-06-26 -Forwarded: https://rt.cpan.org/Ticket/Display.html?id=105499 -Bug: https://rt.cpan.org/Ticket/Display.html?id=105499 - ---- a/t/41-line_numbers.t -+++ b/t/41-line_numbers.t -@@ -28,14 +28,14 @@ - { - ok my $m = Text::MicroMason->new( -LineNumbers ); - is eval { $m->execute( text=>'Hello <% $__[] %>!', 'world' ) }, undef; -- like $@, qr{requires explicit package name at text template [(]compiled at \S+.t line \d+[)] line 1}; -+ like $@, qr{requires explicit package name (?:\(did you forget to declare "my \@__"\?\) )?at text template [(]compiled at \S+.t line \d+[)] line 1}; - } - - { - ok my $m = Text::MicroMason->new( -LineNumbers ); - - is eval { $m->execute( text=> "\n\n" . 'Hello <% $__[] %>!', 'world' ) }, undef; -- like $@, qr{requires explicit package name at text template [(]compiled at \S+.t line \d+[)] line 3}; -+ like $@, qr{requires explicit package name (?:\(did you forget to declare "my \@__"\?\) )?at text template [(]compiled at \S+.t line \d+[)] line 3}; - } - - ###################################################################### -@@ -57,7 +57,7 @@ - { - ok my $m = Text::MicroMason->new( -LineNumbers ); - is eval { $m->execute( inline => 'Hello <% $__[] %>!', 'world' ) }, undef; my $line = __LINE__; -- like $@, qr{requires explicit package name at \S+.t line \Q$line\E}; -+ like $@, qr{requires explicit package name (?:\(did you forget to declare "my \@__"\?\) )?at \S+.t line \Q$line\E}; - } - - ###################################################################### diff -Nru libtext-micromason-perl-2.13/debian/patches/series libtext-micromason-perl-2.16/debian/patches/series --- libtext-micromason-perl-2.13/debian/patches/series 2015-06-26 10:03:02.000000000 +0000 +++ libtext-micromason-perl-2.16/debian/patches/series 1970-01-01 00:00:00.000000000 +0000 @@ -1,3 +0,0 @@ -fix-changes-pod.patch -test-linenumbers.patch -perl-5.22-errors.patch diff -Nru libtext-micromason-perl-2.13/debian/patches/test-linenumbers.patch libtext-micromason-perl-2.16/debian/patches/test-linenumbers.patch --- libtext-micromason-perl-2.13/debian/patches/test-linenumbers.patch 2015-06-26 10:03:02.000000000 +0000 +++ libtext-micromason-perl-2.16/debian/patches/test-linenumbers.patch 1970-01-01 00:00:00.000000000 +0000 @@ -1,20 +0,0 @@ -Description: perl 5.19 fixed a line-number bug - allow both old and new line-number in test -Origin: vendor -Bug: https://rt.cpan.org/Public/Bug/Display.html?id=92771 -Bug-Debian: https://bugs.debian.org/753043 -Forwarded: no -Author: gregor herrmann -Last-Update: 2014-06-29 - ---- a/t/08-errors.t -+++ b/t/08-errors.t -@@ -34,7 +34,7 @@ - - is eval { $m->compile( text => $scr_mobj ); 1 }, undef, "template with error dies"; - ok my @lines = split(/\n/, $@), 'multiline output in $@'; -- like shift @lines, qr{MicroMason compilation failed: syntax error at text template \(compiled at t/08-errors.t line \d+\) line 8}, -+ like shift @lines, qr{MicroMason compilation failed: syntax error at text template \(compiled at t/08-errors.t line \d+\) line [89]}, - 'first line of $@ describes the error location' - or diag $@; - like shift @lines, qr/^$/, 'second line of $@ is blank' diff -Nru libtext-micromason-perl-2.13/debian/rules libtext-micromason-perl-2.16/debian/rules --- libtext-micromason-perl-2.13/debian/rules 2015-06-26 10:03:02.000000000 +0000 +++ libtext-micromason-perl-2.16/debian/rules 2015-06-26 19:05:14.000000000 +0000 @@ -6,16 +6,9 @@ %: dh $@ -override_dh_installchangelogs: - # Convert changelog to text for installation - pod2text MicroMason/Docs/Changes.pod > Changes - dh_installchangelogs - override_dh_installdocs: - # Convert documentation for installation: README, RELATED, TODO - pod2text MicroMason/Docs/ReadMe.pod > README - pod2text MicroMason/Docs/Related.pod > RELATED - pod2text MicroMason/Docs/ToDo.pod > TODO + # Convert documentation for installation + pod2text $(CURDIR)/lib/Text/MicroMason/Docs/Related.pod > RELATED dh_installdocs override_dh_auto_install: diff -Nru libtext-micromason-perl-2.13/debian/tests/pkg-perl/skip-syntax libtext-micromason-perl-2.16/debian/tests/pkg-perl/skip-syntax --- libtext-micromason-perl-2.13/debian/tests/pkg-perl/skip-syntax 1970-01-01 00:00:00.000000000 +0000 +++ libtext-micromason-perl-2.16/debian/tests/pkg-perl/skip-syntax 2015-06-26 19:05:14.000000000 +0000 @@ -0,0 +1,2 @@ +# Apache::Constants?! +Text/MicroMason/ApacheHandler.pm diff -Nru libtext-micromason-perl-2.13/debian/tests/pkg-perl/test-files libtext-micromason-perl-2.16/debian/tests/pkg-perl/test-files --- libtext-micromason-perl-2.13/debian/tests/pkg-perl/test-files 1970-01-01 00:00:00.000000000 +0000 +++ libtext-micromason-perl-2.16/debian/tests/pkg-perl/test-files 2015-06-26 19:05:14.000000000 +0000 @@ -0,0 +1,2 @@ +t/ +samples/ diff -Nru libtext-micromason-perl-2.13/lib/Text/MicroMason/AllowGlobals.pm libtext-micromason-perl-2.16/lib/Text/MicroMason/AllowGlobals.pm --- libtext-micromason-perl-2.13/lib/Text/MicroMason/AllowGlobals.pm 1970-01-01 00:00:00.000000000 +0000 +++ libtext-micromason-perl-2.16/lib/Text/MicroMason/AllowGlobals.pm 2015-06-26 18:11:32.000000000 +0000 @@ -0,0 +1,149 @@ +package Text::MicroMason::AllowGlobals; + +use strict; +use Carp; + +###################################################################### + +sub allow_globals { + my $self = shift; + my $globals = $self->{allow_globals}; + my @current = ref( $globals ) ? @$globals : + ! defined( $globals ) ? () : + split ' ' , $globals; + + if ( scalar @_ ) { + my %once_each; + @current = grep { ! ( $once_each{$_} ++ ) } @current, @_; + $self->{allow_globals} = \@current; + } + + wantarray ? @current : join(' ', @current); +} + +###################################################################### + +sub set_globals { + my ( $self, %globals ) = @_; + + my @globals = keys %globals; + $self->allow_globals( @globals ); + + my $sub = join( "\n", + $self->allow_globals_statement(), + " sub { ", + map( { + my $var = $_; $var =~ s/^[\@\%]/*/; $var =~ s/^(\w)/\$$1/; + "$var = \$_[0]{'$_'};" + } @globals ), + " }" + ); + + $self->eval_sub( $sub )->( \%globals ) +} + +###################################################################### + +sub allow_globals_statement { + my $self = shift; + "use vars qw(" . $self->allow_globals() . ");" +} + +sub assemble { + my $self = shift; + $self->NEXT('assemble', once => $self->allow_globals_statement(), @_); +} + +###################################################################### + +1; + +__END__ + +###################################################################### + +=head1 NAME + +Text::MicroMason::AllowGlobals - Share package vars between templates + + +=head1 SYNOPSIS + +Instead of using this class directly, pass its name to be mixed in: + + use Text::MicroMason; + my $mason = Text::MicroMason->new( -AllowGlobals ); + +Share package variables: + + $mason->set_globals( '$name' => 'Bob' ); + +Use the standard compile and execute methods to parse and evalute templates: + + print $mason->compile( text=>$template )->(); + print $mason->execute( text=>$template ); + +Then, in a template, you can refer to those globals: + + Welcome, <% $name %>! + + +=head1 DESCRIPTION + + +=head2 Public Methods + +=over 4 + +=item set_globals() + +Accepts a list of pairs of global variable names and corresponding values. + +Adds each variable name to the allowed list and sets it to the initial value. + +=item allow_globals() + +Gets or sets the variables names to be allowed. + +If called with arguments, adds them to the list. + +Returns the variables to be allowed as a list, or as a space-separated string in scalar context. + +=back + +=head2 Supported Attributes + +=over 4 + +=item allow_globals + +Optional array or space-separated string of global variable names to be allowed. + +=back + +=head2 Private Methods + +=over 4 + +=item assemble() + +Adds the allow_globals_statement to each token stream before assembling it. + +=item allow_globals_statement() + +This method prepends the "use vars" statement needed for the template subroutines to compile. + +=back + + +=head1 SEE ALSO + +For an overview of this templating framework, see L. + +This is a mixin class intended for use with L. + +For distribution, installation, support, copyright and license +information, see L. + +=cut + diff -Nru libtext-micromason-perl-2.13/lib/Text/MicroMason/ApacheHandler.pm libtext-micromason-perl-2.16/lib/Text/MicroMason/ApacheHandler.pm --- libtext-micromason-perl-2.13/lib/Text/MicroMason/ApacheHandler.pm 1970-01-01 00:00:00.000000000 +0000 +++ libtext-micromason-perl-2.16/lib/Text/MicroMason/ApacheHandler.pm 2015-06-26 18:11:32.000000000 +0000 @@ -0,0 +1,139 @@ +package Text::MicroMason::ApacheHandler; + +use Apache::Constants; +use Apache::Request; + +use Text::MicroMason::Base; + +###################################################################### + +my %configs; + +sub handler ($$) { + my ($package, $r) = @_; + + my $apache = Apache::Request->instance( $r ); + + my $file = $apache->filename; + + # $apache->document_root; + my $syntax = $apache->dir_config('MicroMasonSyntax') || 'HTMLMason'; + my @mixins = $apache->dir_config->get('MicroMasonMixins'); + my @attrs = $apache->dir_config->get('MicroMasonAttribs'); + + my %seen; + unshift @attrs, ( map "-$_", grep { ! $seen{$_} ++ } ( @mixins, $syntax ) ); + + my $config = join ' ', @attrs; + + my $mason = ( $configs{$config} ||= Text::MicroMason::Base->new( @attrs ) ); + + my $template = $mason->compile( file => $file ); + + $apache->content_type( 'text/html' ); + # $apache->header_out(); + + local $Text::MicroMason::Commands::r = $apache; + print $template->( $apache->param() ); + + return Apache::Constants::OK(); +} + +sub configure { + my $apache = Apache::Request->instance( shift ); + + my $file = $apache->filename; + + # $apache->document_root; + my $syntax = $apache->dir_config('MicroMasonSyntax') || 'HTMLMason'; + my @mixins = $apache->dir_config->get('MicroMasonMixins'); + my @attrs = $apache->dir_config->get('MicroMasonAttribs'); + + my %seen; + unshift @attrs, ( map "-$_", grep { ! $seen{$_} ++ } ( @mixins, $syntax ) ); + + my $config = join ' ', @attrs; + + my $mason = ( $configs{$config} ||= Text::MicroMason::Base->new( @attrs ) ); +} + +###################################################################### + +sub translate_params { + MasonAllowGlobals => [ -AllowGlobals, allow_globals => \$1 ], + MasonCompRoot => [ -TemplateDir, template_root => \$1 ], +} + +###################################################################### + +1; + +__END__ + +###################################################################### + +=head1 NAME + +Text::MicroMason::ApacheHandler - Use MicroMason from mod_perl + + +=head1 SYNOPSIS + +In your httpd.conf or equivalent Apache configuration file: + + PerlModule Text::MicroMason::ApacheHandler + + + SetHandler perl-script + PerlHandler Text::MicroMason::ApacheHandler + + +In your document root or other web-accessible directory: + + <% my $visitor = $r->connection->remote_host(); %> + + Hello there <%= $visitor %>! + The time is now <%= localtime() %>. + + +=head1 DESCRIPTION + +B This module is new, experimental, and incomplete. Not intended for production use. Interface subject to change. If you're interested in this capability, your feedback would be appreciated. + +=head2 Configuration + +The following configuration parameters are supported: + +=over 4 + +=item MicroMasonSyntax + + PerlSetVar MicroMasonSyntax HTMLMason + +Name of the syntax class that will compile the templates. Defaults to HTMLMason. + +=item MicroMasonMixins + + PerlAddVar MicroMasonMixins Safe + PerlAddVar MicroMasonMixins CatchErrors + +List of additional mixin classes to be enabled. + +=item MicroMasonAttribs + + PerlAddVar MicroMasonAttribs "-AllowGlobals, allow_globals => '$r'" + +Allows for any set of attributes to be defined. Mixin names prefaced with a dash can also be included. + +=back + +=head1 SEE ALSO + +For an overview of this templating framework, see L. + +This is a mixin class intended for use with L. + +For distribution, installation, support, copyright and license +information, see L. + +=cut diff -Nru libtext-micromason-perl-2.13/lib/Text/MicroMason/Base.pm libtext-micromason-perl-2.16/lib/Text/MicroMason/Base.pm --- libtext-micromason-perl-2.13/lib/Text/MicroMason/Base.pm 1970-01-01 00:00:00.000000000 +0000 +++ libtext-micromason-perl-2.16/lib/Text/MicroMason/Base.pm 2015-06-26 18:11:32.000000000 +0000 @@ -0,0 +1,602 @@ +package Text::MicroMason::Base; + +use strict; +require Carp; + +###################################################################### + +###################################################################### + +use Class::MixinFactory -hasafactory; +for my $factory ( (__PACKAGE__)->mixin_factory ) { + $factory->base_class( "Text::MicroMason::Base" ); + $factory->mixin_prefix( "Text::MicroMason" ); +} + +###################################################################### + +###################################################################### + +sub new { + my $callee = shift; + my ( @traits, @attribs ); + while ( scalar @_ ) { + if ( $_[0] =~ /^\-(\w+)$/ ) { + push @traits, $1; + shift; + } else { + push @attribs, splice(@_, 0, 2); + } + } + if ( scalar @traits ) { + die("Adding moxins to an existing class not supported yet!") + unless ( $callee eq __PACKAGE__ ); + $callee->class( @traits )->create( @attribs ) + } else { + $callee->create( @attribs ) + } +} + +###################################################################### + +# $mason = $class->create( %options ); +# $clone = $object->create( %options ); +sub create { + my $referent = shift; + if ( ! ref $referent ) { + bless { $referent->defaults(), @_ }, $referent; + } else { + bless { $referent->defaults(), %$referent, @_ }, ref $referent; + } +} + +sub defaults { + return () +} + +###################################################################### + +###################################################################### + +# $code_ref = $mason->compile( text => $template, %options ); +# $code_ref = $mason->compile( file => $filename, %options ); +# $code_ref = $mason->compile( handle => $filehandle, %options ); +sub compile { + my ( $self, $src_type, $src_data, %options ) = @_; + + ($self, $src_type, $src_data) = $self->prepare($src_type, $src_data,%options); + + my $code = $self->interpret( $src_type, $src_data ); + + $self->eval_sub( $code ) + or $self->croak_msg( "MicroMason compilation failed: $@\n". _number_lines($code)."\n" ); + +} + +# Internal helper to number the lines in the compiled template when compilation croaks +sub _number_lines { + my $code = shift; + + my $n = 0; + return join("\n", map { sprintf("%4d %s", $n++, $_) } split(/\n/, $code)). + "\n** Please use Text::MicroMason->new\(-LineNumbers\) for better diagnostics!"; +} + + +###################################################################### + +# $result = $mason->execute( code => $subref, @arguments ); +# $result = $mason->execute( $src_type, $src_data, @arguments ); +# $result = $mason->execute( $src_type, $src_data, \%options, @arguments ); +sub execute { + my $self = shift; + my $sub = ( $_[0] eq 'code' ) ? do { shift; shift } : + $self->compile( shift, shift, ref($_[0]) ? %{ shift() } : () ) + or $self->croak_msg("MicroMason compilation failed: $@"); + &$sub( @_ ); +} + +###################################################################### + +###################################################################### + +# ($self, $src_type, $src_data) = $self->prepare($src_type, $src_data, %options) +sub prepare { + my ( $self, $src_type, $src_data, %options ) = @_; + $self = $self->create( %options ) if ( scalar keys %options ); + return ( $self, $src_type, $src_data ); +} + +###################################################################### + +# $perl_code = $mason->interpret( $src_type, $src_data ); +sub interpret { + my ( $self, $src_type, $src_data ) = @_; + my $template = $self->read( $src_type, $src_data ); + my @tokens = $self->lex( $template ); + my $code = $self->assemble( @tokens ); + + # Source file and line number + my $source_line = $self->source_file_line_label( $src_type, $src_data ); + + return $source_line . "\n" . $code; +} + +# $line_number_comment = $mason->source_file_line_label( $src_type, $src_data ); +sub source_file_line_label { + my ( $self, $src_type, $src_data ) = @_; + + if ( $src_type eq 'file' ) { + return qq(# line 1 "$src_data"); + } + + my @caller; + my $call_level; + do { @caller = caller( ++ $call_level ) } + while ( $caller[0] =~ /^Text::MicroMason/ or $self->isa($caller[0]) ); + my $package = ( $caller[1] || $0 ); + qq{# line 1 "text template (compiled at $package line $caller[2])"} +} + + +###################################################################### + +# $code_ref = $mason->eval_sub( $perl_code ); +sub eval_sub { + my $m = shift; + package Text::MicroMason::Commands; + eval( shift ) +} + +###################################################################### + +###################################################################### + +# $template = $mason->read( $src_type, $src_data ); +sub read { + my ( $self, $src_type, $src_data ) = @_; + + my $src_method = "read_$src_type"; + $self->can($src_method) + or $self->croak_msg("Unsupported source type '$src_type'"); + $self->$src_method( $src_data ); +} + +# $template = $mason->read_text( $template ); +sub read_text { + ref($_[1]) ? $$_[1] : $_[1]; +} + +# $contents = $mason->read_file( $filename ); +sub read_file { + my ( $self, $file ) = @_; + local *FILE; + open FILE, "$file" or $self->croak_msg("MicroMason can't open $file: $!"); + local $/ = undef; + local $_ = ; + close FILE or $self->croak_msg("MicroMason can't close $file: $!");; + return $_; +} + +# $contents = $mason->read_handle( $filehandle ); +sub read_handle { + my ( $self, $handle ) = @_; + my $fh = (ref $handle eq 'GLOB') ? $handle : $$handle; + local $/ = undef; + <$fh> +} + +###################################################################### + +# @token_pairs = $mason->lex( $template ); +sub lex { + my $self = shift; + local $_ = "$_[0]"; + my @tokens; + my $lexer = $self->can('lex_token') + or $self->croak_msg('Unable to lex_token(); must select a syntax mixin'); + # warn "Lexing: " . pos($_) . " of " . length($_) . "\n"; + until ( /\G\z/gc ) { + my @parsed = &$lexer( $self ) or + /\G ( .{0,20} ) /gcxs + && die "MicroMason parsing halted at '$1'\n"; + push @tokens, @parsed; + } + return @tokens; +} + +# ( $type, $value ) = $mason->lex_token(); +sub lex_token { + die "The lex_token() method is abstract and must be provided by a subclass"; +} + +###################################################################### + +###################################################################### + +# Text elements used for subroutine assembly +sub assembler_rules { + template => [ qw( $sub_start $init_errs $init_output + $init_args @perl $return_output $sub_end ) ], + + # Subroutine scafolding + sub_start => 'sub { ', + sub_end => '}', + init_errs => + 'local $SIG{__DIE__} = sub { die "MicroMason execution failed: ", @_ };', + + # Argument processing elements + init_args => 'my %ARGS = @_ if ($#_ % 2);', + + # Output generation + init_output => sub { my $m = shift; my $sub = $m->{output_sub} ? '$m->{output_sub}' : 'sub {push @OUT, @_}'; 'my @OUT; my $_out = ' . $sub . ';' }, + add_output => sub { my $m = shift; $m->{output_sub} ? '&$_out' : 'push @OUT,' }, + return_output => 'join("", @OUT)', + + # Mapping between token types + text_token => 'perl OUT( QUOTED );', + expr_token => "perl OUT( \"\".do{\nTOKEN\n} );", + # the "". here forces string context, and should hopefully make + # 'uninitialized' warnings appear closer to their source, rather + # than at the big join "", @OUT; at the end + file_token => "perl OUT( \$m->execute( file => do {\nTOKEN\n} ) );", + # Note that we need newline after TOKEN here in case it ends with a comment. +} + +sub assembler_vars { + my $self = shift; + my %assembler = $self->assembler_rules(); + + my @assembly = @{ delete $assembler{ template } }; + + my %token_map = map { ( /^(.*?)_token$/ )[0] => delete $assembler{$_} } + grep { /_token$/ } keys %assembler; + + my %fragments = map { $_ => map { ref($_) ? &{$_}( $self ) : $_ } $assembler{$_} } keys %assembler; + + return( \@assembly, \%fragments, \%token_map ); +} + +# $perl_code = $mason->assemble( @tokens ); +sub assemble { + my $self = shift; + my @tokens = @_; + + my ( $order, $fragments, $token_map ) = $self->assembler_vars(); + + my %token_streams = map { $_ => [] } map { ( /^\W?\@(\w+)$/ ) } @$order; + + while ( scalar @tokens ) { + my ( $type, $token ) = splice( @tokens, 0, 2 ); + + unless ( $token_streams{$type} or $token_map->{$type} ) { + my $method = "assemble_$type"; + my $sub = $self->can( $method ) + or $self->croak_msg( "Unexpected token type '$type': '$token'" ); + ($type, $token) = &$sub( $self, $token ); + } + + if ( my $typedef = $token_map->{ $type } ) { + # Perform token map substitution in a single pass so that uses of + # OUT in the token text are not improperly converted to output calls. + # -- Simon, 2009-11-14 + my %substitution_map = ( + 'OUT' => $fragments->{add_output}, + 'TOKEN' => $token, + 'QUOTED' => "qq(\Q$token\E)", + ); + $typedef =~ s/\b(OUT|TOKEN|QUOTED)\b/$substitution_map{$1}/g; + + ( $type, $token ) = split ' ', $typedef, 2; + } + + my $ary = $token_streams{$type} + or $self->croak_msg( "Unexpected token type '$type': '$token'" ); + + push @$ary, $token + } + + join( "\n", map { + /^(\W+)(\w+)$/ or $self->croak_msg("Can't assemble $_"); + if ( $1 eq '$' ) { + $fragments->{ $2 } + } elsif ( $1 eq '@' ) { + @{ $token_streams{ $2 } } + } elsif ( $1 eq '!@' ) { + reverse @{ $token_streams{ $2 } } + } elsif ( $1 eq '-@' ) { + () + } else { + $self->croak_msg("Can't assemble $_"); + } + } @$order ); +} + +###################################################################### + +###################################################################### + +sub croak_msg { + local $Carp::CarpLevel = 2; + shift and Carp::croak( ( @_ == 1 ) ? $_[0] : join(' ', map _printable(), @_) ) +} + +my %Escape = ( + ( map { chr($_), unpack('H2', chr($_)) } (0..255) ), + "\\"=>'\\', "\r"=>'r', "\n"=>'n', "\t"=>'t', "\""=>'"' +); + +# $special_characters_escaped = _printable( $source_string ); +sub _printable { + local $_ = scalar(@_) ? (shift) : $_; + return "(undef)" unless defined; + s/([\r\n\t\"\\\x00-\x1f\x7F-\xFF])/\\$Escape{$1}/sgo; + /[^\w\d\-\:\.\']/ ? "q($_)" : $_; +} + +###################################################################### + + +sub cache_key { + my $self = shift; + my ($src_type, $src_data, %options) = @_; + + return $src_data; +} + + +1; + +__END__ + +###################################################################### + +=head1 NAME + +Text::MicroMason::Base - Abstract Template Compiler + + +=head1 SYNOPSIS + +Create a MicroMason object to interpret the templates: + + use Text::MicroMason; + my $mason = Text::MicroMason->new(); + +Use the execute method to parse and evalute a template: + + print $mason->execute( text=>$template, 'name'=>'Dave' ); + +Or compile it into a subroutine, and evaluate repeatedly: + + $coderef = $mason->compile( text=>$template ); + print $coderef->('name'=>'Dave'); + print $coderef->('name'=>'Bob'); + +Templates stored in files can be run directly or included in others: + + print $mason->execute( file=>"./greeting.msn", 'name'=>'Charles'); + + +=head1 DESCRIPTION + +Text::MicroMason::Base is an abstract superclass that provides a parser +and execution environment for an extensible templating system. + +=head2 Public Methods + +=over 4 + +=item new() + + $mason = Text::MicroMason::Base->new( -Mixin1, -Mixin2, %attribs ); + +Creates a new Text::MicroMason object with mixins and attributes. + +Arguments beginning with a dash will be added as mixin classes. +Other arguments are added to the hash of attributes. + +=item compile() + + $code_ref = $mason->compile( text => $template, %options ); + $code_ref = $mason->compile( file => $filename, %options ); + +Parses the provided template and converts it into a new Perl subroutine. + +=item execute() + + $result = $mason->execute( text => $template, @arguments ); + $result = $mason->execute( file => $filename, @arguments ); + $result = $mason->execute( code => $code_ref, @arguments ); + + $result = $mason->execute( $type => $source, \%options, @arguments ); + +Returns the results produced by the template, given the provided arguments. + +=back + +=head2 Attributes + +Attributes can be set in a call to new() and locally overridden in a call to compile(). + +=over 4 + +=item output_sub + +Optional reference to a subroutine to call with each piece of template output. If this is enabled, template subroutines will return an empty string. + +=back + +=head2 Private Methods + +The following internal methods are used to implement the public interface described above, and may be overridden by subclasses and mixins. + +=over 4 + +=item class() + + $class = Text::MicroMason::Base->class( @Mixins ); + +Creates a subclass of this package that also inherits from the other classes named. Provided by Class::MixinFactory::HasAFactory. + +=item create() + + $mason = $class->create( %options ); + $clone = $mason->create( %options ); + +Creates a new instance with the provided key value pairs. + +To obtain the functionality of one of the supported mixin classes, use the class method to generate the mixed class before calling create(), as is done by new(). + +=item defaults() + +This class method is called by new() to provide key-value pairs to be included in the new instance. + +=item prepare() + + ($self, $src_type, $src_data) = $self->prepare($src_type, $src_data, %options) + +Called by compile(), the prepare method allows for single-use attributes and provides a hook for mixin functionality. + +The prepare method provides a hook for mixins to normalize or resolve the template source type and value arguments in various ways before the template is read using one of the read_type() methods. + +It returns an object reference that may be a clone of the original mason object with various compile-time attributes applied. The cloning is a shallow copy performed by the create() method. This means that the $m object visible to a template may not be the same as the MicroMason object on which compile() was originally called. + +Please note that this clone-on-prepare behavior is subject to change in future releases. + +=item interpret + + $perl_code = $mason->interpret( $src_type, $src_data ); + +Called by compile(), the interpret method then calls the read(), lex(), and assemble() methods. + +=item read + + $template = $mason->read( $src_type, $src_data ); + +Called by interpret(). Calls one of the below read_* methods. + +=item read_text + + $template = $mason->read_text( $template ); + +Called by read() when the template source type is "text", this method simply returns the value of the text string passed to it. + +=item read_file + + ( $contents, %path_info ) = $mason->read_file( $filename ); + +Called by read() when the template source type is "file", this method reads and returns the contents of the named file. + +=item read_handle + + $template = $mason->read_handle( $filehandle ); + +Called by read() when the template source type is "handle", this method reads and returns the contents of the filehandle passed to it. + +=item lex + + @token_pairs = $mason->lex( $template ); + +Called by interpret(). Parses the source text and returns a list of pairs of token types and values. Loops through repeated calls to lex_token(). + +=item lex_token + + ( $type, $value ) = $mason->lex_token(); + +Attempts to parse a token from the template text stored in the global $_ and returns a token type and value. Returns an empty list if unable to parse further due to an error. + +Abstract method; must be implemented by subclasses. + +=item assemble + + $perl_code = $mason->assemble( @tokens ); + +Called by interpret(). Assembles the parsed token series into the source code for the equivalent Perl subroutine. + +=item assembler_rules() + +Returns a hash of text elements used for Perl subroutine assembly. Used by assemble(). + +The assembly template defines the types of blocks supported and the order they appear in, as well as where other standard elements should go. Those other elements also appear in the assembler hash. + +=item eval_sub + + $code_ref = $mason->eval_sub( $perl_code ); + +Called by compile(). Compiles the Perl source code for a template using eval(), and returns a code reference. + +=item croak_msg + +Called when a fatal exception has occurred. + +=item NEXT + +Enhanced superclass method dispatch for use inside mixin class methods. Allows mixin classes to redispatch to other classes in the inheritance tree without themselves inheriting from anything. Provided by Class::MixinFactory::NEXT. + +=back + +=head2 Private Functions + +=over 4 + +=item _printable + + $special_characters_escaped = _printable( $source_string ); + +Converts non-printable characters to readable form using the standard backslash notation, such as "\n" for newline. + +=back + +=head1 EXTENDING + +You can add functionality to this module by creating subclasses or mixin classes. + +To create a subclass, just inherit from the base class or some dynamically-assembled class. To create your own mixin classes which can be combined with other mixin features, examine the operation of the class() and NEXT() methods. + +Key areas for subclass writers are: + +=over 4 + +=item prepare + +You can intercept and re-write template source arguments by overriding this method. + +=item read_* + +You can support a new template source type by creating a method with a corresponding name prefixed by "read_". It is passed the template source value and should return the raw text to be lexed. + +For example, if a subclass defined a method named read_from_db, callers could compile templates by calling C<-Ecompile( from_db =E 'welcome-page' )>. + +=item lex_token + +Replace this to parse a new template syntax. Is receives the text to be parsed in $_ and should match from the current position to return the next token type and its contents. + +=item assembler_rules + +The assembler data structure is used to construct the Perl subroutine for a parsed template. + +=item assemble_* + +You can support a new token type be creating a method with a corresponding name prefixed by "assemble_". It is passed the token value or contents, and should return a new token pair that is supported by the assembler template. + +For example, if a subclass defined a method named assemble_sqlquery, callers could compile templates that contained a C%sqlqueryE ... E/%sqlqueryE> block. The assemble_sqlquery method could return a C<< perl => $statements >> pair with Perl code that performed some appropriate action. + +=item compile + +You can wrap or cache the results of this method, which is the primary public interface. + +=item execute + +You typically should not depend on overriding this method because callers can invoke the compiled subroutines directly without calling execute. + +=back + +=head1 SEE ALSO + +For an overview of this templating framework, see L. + +For distribution, installation, support, copyright and license +information, see L. + +=cut diff -Nru libtext-micromason-perl-2.13/lib/Text/MicroMason/Cache/File.pm libtext-micromason-perl-2.16/lib/Text/MicroMason/Cache/File.pm --- libtext-micromason-perl-2.13/lib/Text/MicroMason/Cache/File.pm 1970-01-01 00:00:00.000000000 +0000 +++ libtext-micromason-perl-2.16/lib/Text/MicroMason/Cache/File.pm 2015-06-26 18:11:32.000000000 +0000 @@ -0,0 +1,103 @@ +package Text::MicroMason::Cache::File; +@ISA = 'Text::MicroMason::Cache::Simple'; + +use strict; + +# Array field names +use constant LAST_CHECK => 0; +use constant AGE => 1; +use constant VALUE => 2; + +###################################################################### + +sub get { + my ( $self, $file ) = @_; + my $entry = $self->SUPER::get( $file ) + or return; + unless (ref($entry) eq 'ARRAY' and @$entry == 3 ) { + Carp::croak("MicroMason: cache '$self' data corrupted; " . + "value for '$file' should not be '$entry'"); + } + + my $time = time(); + if ( $entry->[LAST_CHECK] < $time ) { # don't check more than once per second + my $current_age = -M $file; + if ( $entry->[AGE] > $current_age ) { + @$entry = ( 0, 0, undef ); # file has changed; cache invalid + return; + } else { + $entry->[LAST_CHECK] = $time; + } + } + return $entry->[VALUE]; +} + +sub set { + my ($self, $file, $sub) = @_; + $self->SUPER::set( $file => [ time(), -M $file, $sub ] ); + return $sub; +} + +###################################################################### + +1; + +__END__ + +###################################################################### + +=head1 NAME + +Text::MicroMason::Cache::File - Basic Cache with File-Based Expiration + + +=head1 DESCRIPTION + +This simple cache class expects the keys provided to it to be file +pathnames, and considers the cached value to have expired if the +corresponding file is changed. + +It does not perform the following functions: cache size limiting, or +deep copying of complex values. + +=head2 Public Methods + +=over 4 + +=item new() + + $cache = Text::MicroMason::Cache::File->new(); + +=item get() + + $value = $cache->get( $filename ); + +Retrieves the value associated with this key, or undef if there is no value. + +=item set() + + $cache->set( $filename, $value ); + +Stores the provided value in association with this key. + +=item clear() + + $cache->clear(); + +Removes all data from the cache. + +=back + + +=head1 SEE ALSO + +For uses of this cache class, see L. + +Additional cache classes are available in the Text::MicroMason::Cache:: +namespace, or select other caching modules on CPAN that support the +interface described in L. + +For distribution, installation, support, copyright and license +information, see L. + +=cut diff -Nru libtext-micromason-perl-2.13/lib/Text/MicroMason/Cache/Null.pm libtext-micromason-perl-2.16/lib/Text/MicroMason/Cache/Null.pm --- libtext-micromason-perl-2.13/lib/Text/MicroMason/Cache/Null.pm 1970-01-01 00:00:00.000000000 +0000 +++ libtext-micromason-perl-2.16/lib/Text/MicroMason/Cache/Null.pm 2015-06-26 18:11:32.000000000 +0000 @@ -0,0 +1,70 @@ +package Text::MicroMason::Cache::Null; + +use strict; + +###################################################################### + +sub new { my $class = shift; bless { @_ }, $class } + +sub get { return } + +sub set { return $_[2] } + +sub clear { return } + +###################################################################### + +1; + +__END__ + +###################################################################### + +=head1 NAME + +Text::MicroMason::Cache::Null - Trivial Cache with No Data Storage + + +=head1 DESCRIPTION + +This trivial cache class supports the cache interface but doesn't store or retrieve any values. + +=head2 Public Methods + +=over 4 + +=item new() + + $cache = Text::MicroMason::Cache::Null->new(); + +=item get() + + undef = $cache->get( $key ); + +Does nothing. + +=item set() + + $cache->set( $key, $value ); + +Returns the provided value. + +=item clear() + + $cache->clear(); + +Does nothing. + +=back + + +=head1 SEE ALSO + +For uses of this cache class, see L. + +Additional cache classes are available in the Text::MicroMason::Cache:: namespace, or select other caching modules on CPAN that support the interface described in L. + +For distribution, installation, support, copyright and license +information, see L. + +=cut diff -Nru libtext-micromason-perl-2.13/lib/Text/MicroMason/Cache/Simple.pm libtext-micromason-perl-2.16/lib/Text/MicroMason/Cache/Simple.pm --- libtext-micromason-perl-2.13/lib/Text/MicroMason/Cache/Simple.pm 1970-01-01 00:00:00.000000000 +0000 +++ libtext-micromason-perl-2.16/lib/Text/MicroMason/Cache/Simple.pm 2015-06-26 18:11:32.000000000 +0000 @@ -0,0 +1,72 @@ +package Text::MicroMason::Cache::Simple; + +use strict; + +###################################################################### + +sub new { my $class = shift; bless { @_ }, $class } + +sub get { $_[0]->{ $_[1] } } + +sub set { $_[0]->{ $_[1] } = $_[2] } + +sub clear { %{ $_[0] } = () } + +###################################################################### + +1; + +__END__ + +###################################################################### + +=head1 NAME + +Text::MicroMason::Cache::Simple - Basic Cache with Minimal Interface + + +=head1 DESCRIPTION + +This trivial cache class just stores values in a hash. + +It does not perform any of the following functions: expiration, cache size limiting, flatening of complex keys, or deep copying of complex values. + +=head2 Public Methods + +=over 4 + +=item new() + + $cache = Text::MicroMason::Cache::Simple->new(); + +=item get() + + $value = $cache->get( $key ); + +Retrieves the value associated with this key, or undef if there is no value. + +=item set() + + $cache->set( $key, $value ); + +Stores the provided value in association with this key. + +=item clear() + + $cache->clear(); + +Removes all data from the cache. + +=back + + +=head1 SEE ALSO + +For uses of this cache class, see L. + +Additional cache classes are available in the Text::MicroMason::Cache:: namespace, or select other caching modules on CPAN that support the interface described in L. + +For distribution, installation, support, copyright and license +information, see L. + +=cut diff -Nru libtext-micromason-perl-2.13/lib/Text/MicroMason/CatchErrors.pm libtext-micromason-perl-2.16/lib/Text/MicroMason/CatchErrors.pm --- libtext-micromason-perl-2.13/lib/Text/MicroMason/CatchErrors.pm 1970-01-01 00:00:00.000000000 +0000 +++ libtext-micromason-perl-2.16/lib/Text/MicroMason/CatchErrors.pm 2015-06-26 18:11:32.000000000 +0000 @@ -0,0 +1,103 @@ +package Text::MicroMason::CatchErrors; + +use strict; +use Carp; + +###################################################################### + +# sub defaults { +# (shift)->NEXT('assembler_rules'), error_string => 1 +# } + +sub compile { + my $result = eval { local $SIG{__DIE__}; (shift)->NEXT('compile', @_) }; + wantarray ? ($result, $@) : $result; +} + +sub execute { + my $result = eval { local $SIG{__DIE__}; (shift)->NEXT('execute', @_) }; + wantarray ? ($result, $@) : $result; +} + +###################################################################### + +1; + +__END__ + +###################################################################### + +=head1 NAME + +Text::MicroMason::CatchErrors - Add Exception Catching for Templates + + +=head1 SYNOPSIS + +Instead of using this class directly, pass its name to be mixed in: + + use Text::MicroMason; + my $mason = Text::MicroMason->new( -CatchErrors ); + +Use the standard compile and execute methods to parse and evalute templates: + + print scalar $mason->compile( text=>$template )->( @%args ); + print scalar $mason->execute( text=>$template, @args ); + +Result is undef on exception, plus an error message if in list context: + + ($coderef, $error) = $mason->compile( text=>$template ); + ($result, $error) = $mason->execute( text=>$template, 'name'=>'Dave' ); + + +=head1 DESCRIPTION + +This package adds exception catching to MicroMason, allowing you to check +an error variable rather than wrapping every call in an eval. + +Both compilation and run-time errors in your template are handled as fatal +exceptions. The base MicroMason class will croak() if you attempt to +compile or execute a template which contains a incorrect fragment of Perl +syntax. Similarly, if the Perl code in your template causes die() or +croak() to be called, this will interupt your program unless caught by an +eval block. + +This class provides that error catching behavior for the compile and +execute methods. + +In a scalar context they return the result of the call, or undef if it +failed; in a list context they return the results of the call (undef if +it failed) followed by the error message (undef if it succeeded). + +=head2 Public Methods + +=over 4 + +=item compile() + + $code_ref = $mason->compile( text => $template, %options ); + ($coderef, $error) = $mason->compile( text=>$template, %options ); + +Uses an eval block to provide an exception catching wrapper for the compile method. + +=item execute() + + $result = $mason->execute( text => $template, @arguments ); + ($result, $error) = $mason->execute( text=>$template, 'name'=>'Dave' ); + +Uses an eval block to provide an exception catching wrapper for the execute method. + +=back + + +=head1 SEE ALSO + +For an overview of this templating framework, see L. + +This is a mixin class intended for use with L. + +For distribution, installation, support, copyright and license +information, see L. + +=cut + diff -Nru libtext-micromason-perl-2.13/lib/Text/MicroMason/CompileCache.pm libtext-micromason-perl-2.16/lib/Text/MicroMason/CompileCache.pm --- libtext-micromason-perl-2.13/lib/Text/MicroMason/CompileCache.pm 1970-01-01 00:00:00.000000000 +0000 +++ libtext-micromason-perl-2.16/lib/Text/MicroMason/CompileCache.pm 2015-06-26 18:11:32.000000000 +0000 @@ -0,0 +1,113 @@ +package Text::MicroMason::CompileCache; + +use strict; +use Carp; + +require Text::MicroMason::Cache::Simple; +require Text::MicroMason::Cache::File; + +###################################################################### +# What cache class should we use for each src_type? + +my %CACHE_CLASS = ( + file => 'Text::MicroMason::Cache::File', + text => 'Text::MicroMason::Cache::Simple', + ); + +###################################################################### + +# $code_ref = compile( file => $filename ); +sub compile { + my $self = shift; + my ( $src_type, $src_data, %options ) = @_; + my $cache = $self->_compile_cache( $src_type ) + or return $self->NEXT('compile', @_); + my $key = $self->cache_key(@_); + $cache->get( $key ) or $cache->set( $key, + $self->NEXT('compile', @_), + ); +} + +sub _compile_cache { + my ($self, $type) = @_; + $CACHE_CLASS{$type} or return; + + $self->{compile_cache}{$type} ||= $CACHE_CLASS{$type}->new(); +} + +###################################################################### + + +1; + +__END__ + +=head1 NAME + +Text::MicroMason::CompileCache - Use a Cache for Template Compilation + + +=head1 SYNOPSIS + +Instead of using this class directly, pass its name to be mixed in: + + use Text::MicroMason; + my $mason = Text::MicroMason->new( -CompileCache ); + +Use the standard compile and execute methods to parse and evalute templates: + + print $mason->execute( text=>$template, 'name'=>'Dave' ); + +The template does not have to be parsed the second time because it's cached: + + print $mason->execute( text=>$template, 'name'=>'Bob' ); + +Templates stored in files are also cached, until the file changes: + + print $mason->execute( file=>"./greeting.msn", 'name'=>'Charles'); + + +=head1 DESCRIPTION + + +=head2 Public Methods + +=over 4 + +=item compile() + +Caching wrapper around normal compile() behavior. + +=back + +=head2 Supported Attributes + +=over 4 + +=item compile_cache_text + +Defaults to an instance of Text::MicroMason::Cache::Simple. You may pass in your own cache object. + +=item compile_cache_file + +Defaults to an instance of Text::MicroMason::Cache::File. You may pass in your own cache object. + +=back + +This module uses a simple cache interface that is widely supported: the +only methods required are C and C. You can +use the simple cache classes provided in the Text::MicroMason::Cache:: +namespace, or select other caching modules on CPAN that support the +interface described in L. + + +=head1 SEE ALSO + +For an overview of this templating framework, see L. + +This is a mixin class intended for use with L. + +For distribution, installation, support, copyright and license +information, see L. + +=cut diff -Nru libtext-micromason-perl-2.13/lib/Text/MicroMason/Debug.pm libtext-micromason-perl-2.16/lib/Text/MicroMason/Debug.pm --- libtext-micromason-perl-2.13/lib/Text/MicroMason/Debug.pm 1970-01-01 00:00:00.000000000 +0000 +++ libtext-micromason-perl-2.16/lib/Text/MicroMason/Debug.pm 2015-06-26 18:11:32.000000000 +0000 @@ -0,0 +1,158 @@ +package Text::MicroMason::Debug; + +use strict; +use Carp; + +###################################################################### + +use vars qw( %Defaults ); + +sub defaults { + (shift)->NEXT('defaults'), debug => { default => 1 }, +} + +###################################################################### + +sub debug_msg { + my $self = shift; + my $type = shift; + my $flag = ( ! ref $self->{debug} ) ? $self->{debug} : + exists( $self->{debug}{$type} ) ? $self->{debug}{$type} : + $self->{debug}{'default'}; + if ( $flag ) { + warn "MicroMason Debug $type: " . ( ( @_ == 1 ) ? $_[0] : join( ', ', map Text::MicroMason::Base::_printable(), @_ ) ) . "\n"; + } + + wantarray ? @_ : $_[0]; +} + +###################################################################### + +sub new { + my $self = shift; + $self->debug_msg( 'new', $self, @_ ); + $self->NEXT( 'new', @_ ); +} + +sub create { + my $self = (shift)->NEXT( 'create', @_ ); + $self->debug_msg( 'create', ref($self), %$self ); + return $self; +} + +sub prepare { + my ( $self, $src_type, $src_data ) = @_; + my @result = $self->NEXT( 'prepare', $src_type, $src_data ); + if ( scalar @result > 3 or grep { $result[$_] ne $_[$_] } 0 .. 2 ){ + $self->debug_msg( 'prepare', @result ); + } + return @result; +} + +sub interpret { + my $self = shift; + $self->debug_msg( 'interpret', @_ ); + $self->NEXT( 'interpret', @_ ) +} + +# $contents = $mason->read_file( $filename ); +sub read_file { + my $self = shift; + $self->debug_msg( 'read', "Opening file '$_[0]'" ); + $self->NEXT( 'read_file', @_ ) +} + +sub lex { + my $self = shift; + $self->debug_msg( 'source', @_ ); + $self->debug_msg( 'lex', $self->NEXT( 'lex', @_ ) ); +} + +sub assemble { + my $self = shift; + $self->debug_msg( 'assemble', $self->NEXT( 'assemble', @_ ) ); +} + +sub eval_sub { + my $self = shift; + $self->debug_msg( 'eval', @_ ); + $self->NEXT( 'eval_sub', @_ ) +} + +###################################################################### + +1; + +__END__ + +###################################################################### + +=head1 NAME + +Text::MicroMason::Debug - Provide developer info via warn + + +=head1 SYNOPSIS + +Instead of using this class directly, pass its name to be mixed in: + + use Text::MicroMason; + my $mason = Text::MicroMason->new( -Debug ); + +Use the standard compile and execute methods to parse and evalute templates: + + print $mason->compile( text=>$template )->( @%args ); + print $mason->execute( text=>$template, @args ); + +You'll see lots of warning output on STDERR: + + MicroMason Debug create: Text::MicroMason::Base::AUTO::Debug... + MicroMason Debug source: q(Hello <% $noun %>!) + MicroMason Debug lex: text, q(Hello ), expr, q( $noun ), text, q(!) + MicroMason Debug eval: sub { my @OUT; my $_out = sub { push ... + +=head1 DESCRIPTION + +This package provides numerous messages via warn for developer use when debugging templates built with Text::MicroMason. + +=head2 Supported Attributes + +=over 4 + +=item debug + +Activates debugging messages for many methods. Defaults to logging everything. + +Can be set to 0 or 1 to log nothing or everything. + +Alternately, set this to a hash reference containing values for the steps you are interested in to only log this items: + + debug => { source => 1, eval => 1 } + +You can also selectively surpress some warnings: + + debug => { default => 1, source => 0, eval => 0 } + +=back + +=head2 Private Methods + +=over 4 + +=item debug_msg + +Called to provide a debugging message for developer reference. No output is produced unless the object's 'debug' flag is true. + +=back + + +=head1 SEE ALSO + +For an overview of this templating framework, see L. + +This is a mixin class intended for use with L. + +For distribution, installation, support, copyright and license +information, see L. + +=cut diff -Nru libtext-micromason-perl-2.13/lib/Text/MicroMason/Docs/Changes.pod libtext-micromason-perl-2.16/lib/Text/MicroMason/Docs/Changes.pod --- libtext-micromason-perl-2.13/lib/Text/MicroMason/Docs/Changes.pod 1970-01-01 00:00:00.000000000 +0000 +++ libtext-micromason-perl-2.16/lib/Text/MicroMason/Docs/Changes.pod 2015-06-26 18:11:32.000000000 +0000 @@ -0,0 +1,856 @@ +=head1 NAME + +Text::MicroMason::Docs::Changes - Change History for the MicroMason Distribution + +=head1 VERSION 2 HISTORY + +=head2 Version 2.16 + +=over 4 + +=item 2015-06-27 + +Remove garbage files from dist. + +=back + +=head2 Version 2.15 + +=over 4 + +=item 2015-06-27 + +[rt.cpan.org #105499] Fix regression due to new error/warning format in Perl 5.22. + +[rt.cpan.org #92771] Fix line number regressionf due to a Perl line numbering bugfix. This + passes tests but I'm not entirely convinced it's correct. + +=back + +=head2 Version 2.14 + +=over 4 + +=item 2013-06-11 + +[rt.cpan.org #85965] Fix POD errors in Changes.pod. + +=back + +=head2 Version 2.13 + +=over 4 + +=item 2011-01-13 + +[rt.cpan.org #64192] Skip the Safe-related tests more often, since newer +versions of Safe.pm mark their own failing tests as TODO instead of +changing the module's behavior. + +=back + +=head2 Version 2.12 + +=over 4 + +=item 2010-09-07 + +Skip more tests that fail due to a bug in Safe.pm. Add a prereq for +Safe.pm so CPAN testers will provide more debug info on failure. + +=back + +=head2 Version 2.11 + +=over 4 + +=item 2010-09-07 + +[rt.cpan.org #61010] Fix spelling errors and pod example bugs. Thanks to +vshih at yahoo.com for reporting these problems. + +=item 2010-09-07 + +Under Perl 5.13.1 and later with Safe version 2.27, skip failing tests +in t/32-safe.t. The regression tests for Safe 2.27 fail in Perl 5.13.1 +as well, in a similar way. This bug is not fixable in any reasonable way +until Safe.pm is also stable. + +=item 2010-07-26 + +[rt.cpan.org #59081] Fix spelling and pod errors. Thanks to Ansgar +Burchardt and the Debian project for submitting this bug report along +with patches. + +=back + +=head2 Version 2.10 + +=over 4 + +=item 2010-06-29 + +[rt.cpan.org #57797] Deprecate safe_methods parameter. Unfortunately, +Safe.pm version 2.27 patches a bug we were inadvertantly taking +advantage of to implement the safe_methods parameter. Unless we can +find a working implementation of safe_methods that is smaller than +"make everything unsafe" then we can't continue to support +safe_methods. + +Using safe_methods now issues a deprecation warning, but it should +work with older versions of Safe. I'm in no hurry to remove the +feature, but I don't want anyone to use it who isn't already using it, +until we know it can be supported in the future. + +Thanks to Niko Tyni and the Debian Perl Group for submitting this bug report. + +=item 2010-04-05 + +"uninitialized" warnings in templates were being generated at a line +number within MicroMason instead of a line number within the template +itself. Thanks to Mike Kelly for a patch: by concatenating an empty +string to each TOKEN within the template, the warning's line number is +shifted to inside the template where the interpolation took place. + +=back + +=head2 Version 2.09 + +=over 4 + +=item 2010-03-24 + +Fix test that was broken by changes in URI::Escape 1.30. Double +quotes aren't reserved characters in URIs but they were previously +encoded anyway. Test modified to use reserved single quotes instead, +for URI::Escape testing. + +=back + +=head2 Version 2.08 + +=over 4 + +=item 2010-03-08 + +Fixed PassVariables bug: <%init> failed with -PassVariables plugin. +Thanks to William Kern for reporting this. + +=item 2009-11-19 + +Fixed [rt.cpan.org #51727] [Patch] POD nit; thanks to Frank Wiegand for +reporting this. + +=back + +=head2 Version 2.07 + +=over 4 + +=item 2009-11-16 + +Merge patch from Simon Cavalletto: fix bug reported in CPAN forum with +"OUT" appearing in the input template stream. Thanks! + +Update requirement for Test::More 0.48 or later in Makefile.PL. Tests +using unlike() failed with Test::More version 0.47. + +Fix problem in t/08_errors.t which caused test failures in Perl 5.6. The +error message isn't as important as the test made it out to be, but the +code didn't have a problem. + +=item 2009-11-12 + +Remove documentation for unsupported compile(lines => ...) mode. Put it +on ToDo instead. + +=back + +=head2 Version 2.06 + +=over 4 + +=item 2009-11-11 + +Fix bug reported in CPAN forum: substr() in LineNumbers.pm was being +used incorrectly, resulting in incorrect line numbering in some cases. + +=item 2009-11-12 + +#51460: Clean up the tarball and resubmit a version that doesn't +contain a stray .tgz file. + +=back + +=head2 Version 2.05 + +=over 4 + +=item 2009-11-10 + +Modify compilation error reporting: provide line numbers when dumping +the compiled template into $@, and change the #line to match the line +numbering correctly. + +=item 2009-11-11 + +Fix bug reported by CPAN testers on some Windows boxes: use +Cwd::abs_path for strict_root checking to avoid literal path separators +in TemplateDir.pm. + +=item 2009-11-11 + +Add a hint about -LineNumbers in the numbered template dump when a +compilation error occurs. + +=back + +=head2 Version 2.04 + +=over 4 + +=item 2009-11-06 + +Fixed SKIP count in t/33_filters.t to prevent test failures when +URI::Escape isn't installed. + +=back + +=head2 Version 2.03 + +=over 4 + +=item 2009-10-30 + +Happy Halloween. + +Updated tests to use Test::More for better diagnostics via CPAN testers. + +Tweaked t/34 with a longer sleep() since some linux hosts seemed to be +sleeping for less than a second with sleep(1). + +=back + +=head2 Version 2.02 + +=over 4 + +=item 2009-10-29 + +Updated Changes.pod. + +Fixed SKIP count in t/33 which caused test count mismatches when +HTML::Entities wasn't installed. + +=back + +=head2 Version 2.01 + +=over 4 + +=item 2009-10-29 + +Fix a bug with TemplatePath error messages. If a template name was +provided that didn't exist in the path, the error message generated by +read_file didn't specify which template was requested. This version +now croaks in resolve_path instead of returning undef and letting +read_file croak. + +Updated pod to reflect this change and document previously undocumented +exception strings. + +Modified undocumented exception strings for strict_root violations. + +=back + +=head2 Version 2.0 + +=over 4 + +=item 2008-01-02 + +Fix bug with || filter patch: it was erroneously removing the last +character of the filtered token, which made it fail if there was no +space before the |. + +Bump version to 2.0 + +=back + +=head2 Version 1.993_01 + +=over 4 + +=item 2007-12-21 + +Add LineNumbers mixin and associated tests. + +=item 2007-12-21 + +Update TODO: move almost everything into a WISH LIST with a request for +contributions, and make the main TODO list bug fixes and a few likely +developments. + +=item 2007-12-21 + +Merge test and patch from RT bug #21802: cache expiration bug. + +=item 2007-12-21 + +Merge changes from RT bug #18435: filter problem with +<% $thing || "default" %> + +=item 2007-12-21 + +Bump version to 1.993_01 + +=back + +=head2 Version 1.993 + +=over 4 + +=item 2007-12-20 + +Merge changes from pair Networks local branch, which have been in +testing and production since Q1 2007; bump version to 1.993. + +This includes: + +=over 2 + +=item TemplatePath mixin + +Template lookups on a search path + +=item TemplateDir/ Cache patch + + fix interaction of caching and TemplateDir/TemplatePath + +=item Additional test files + +=item Stop creating cache objects unless/until they're used + +=back + +=back + +=head2 Version 1.992_01 + +=over 4 + +=item 2007-12-20 + +Updated pod and makefiles for maintenance transition from Simon to +Alan. Thanks for the wonderful module, Simon! I hope I can keep things +under control. + +Bumped version number. + +=back + +=head2 Version 1.992 + +=over 4 + +=item 2005-11-13 + +Updated ToDo.pod with a few ideas for upcoming releases. + +Extended t/58-quicktemplate.t to demonstrate use of the pre_fill method. + +=item 2005-11-12 + +Fixed incorrect handling of default values for array or hash variables in an <%args> block. Thanks to Alexander for the bug report. + +Added extra newlines to the do blocks generated by Base's assemble(), so that <% exprs %> can contain a comment. Problem reported by Alexander. + +Improved error reporting by changing the file name embedded in the CPP-style line number comment at the top of each stretch of generated Perl code. Based on a problem report from Alexander. This does not fix the line numbering problem, but at least the file name is more helpful than it used to be. + +=item 2005-08-24 + +Added RoughDraft of "ParseInfo.pm" based on a reply to a question via email from Alexander. + +=item 2005-07-30 + +Fixed return value from Text::MicroMason::Cache::File set() method; thanks to Alan Ferrency for the helpful bug report and test case. + +=item 2005-07-24 + +Extracted HasParams and StoreOne mixins from HTMLTemplate. + +Added QuickTemplate mixin class with emulation for Text::QuickTemplate. + +=item 2005-07-20 + +Added reference links to benchmarking section in Docs/ToDo.pod. + +Added "local $^W;" in two test scripts to silence extra warning on Perl 5.005_04. + +Bumped version number. + +=back + +=head2 Version 1.991 + +=over 4 + +=item 2005-07-19 + +Bumped version number. + +Added ApacheHandler configuration options and basic documentation. + +=item 2005-07-18 + +Added PLP mixin class with emulation for PLP templating package. + +Added the skeleton for a basic ApacheHandler class. + +Improved strict_root support in TemplateDir and added documentation for it. + +Extracted argument passing logic from TextTemplate to create new PassVariables mixin. + +Added Sprintf syntax mixin and basic tests. + +=item 2005-07-17 + +Added DoubleQuote syntax mixin and basic tests. + +=back + +=head2 Version 1.99 + +=over 4 + +=item 2005-07-09 + +Added AllowGlobals mixin based on suggestion and patch from Jonas Alves. Reviewed similar functionality in HTML::Mason and added docs and tests. + +Extracted debug options to separate Debug mixin class. + +Changed name of internal new() method to create(), while propogating the mixin finding behavior from the Text::MicroMason facade up to Text::MicroMason::Base. + +Renamed examples directory to samples. + +Added read_handle method and output_sub attribute. + +Added assembler_vars method and removed %Assembler global. + +=item 2004-12-01 + +Fixed early exit of t/42-text_template.t to skip test if missing Text::Balanced. + +=item 2004-11-30 + +Renamed the Mason compatibilty class to HTMLMason to match other syntax classes. Changed it to be a mixin like the other classes, instead of a subclass. + +Switched to use of Class::MixinFactory and removed old class() and NEXT() methods. + +Extracted new interpret() method from inside of compile(). + +Adjusted setting of options and attributes so that this doesn't happen within interpret(). + +Extracted list of related modules to new Docs::Related POD file. + +=back + +=head2 Version 1.98 + +=over 4 + +=item 2004-11-29 + +Fixed unprotected test dependency on Text::Balanced for TextTemplate emulation. + +Fixed unexpected side-effect of change to parsing for single-character Filter flags. + +Minor adjustments to POD documentation. + +=back + +=head2 Version 1.97 + +=over 4 + +=item 2004-11-28 + +Moved to do list into new pod file. Moved extra pod files into Docs namespace. + +Added _printable to default set of functions in Filters. Tweaked parse_filters and get_filter_functions methods. + +Changed internal names for ouput and include token types to expr and file. Corrected typo in one of the assembler token names. + +Adjusted $Carp::CarpLevel in Base croak_msg(). + +Fixed test failure in t/33-filters.t reported by William Kern. + +=item 2004-10-24 + +Fixed typo in ServerPages example; thanks to William Kern for pointing it out. + +=item 2004-10-20 + +Adjustments to documentation in top-level package. + +=back + + +=head2 Version 1.96 + +=over 4 + +=item 2004-10-19 + +Added PostProcess mixin class at the suggestion of Alan Ferrency. + +Renamed a few keys in the hash returned by assembler_rules(). + +Moved syntax documentation to Mason subclass. + +=back + +=head2 Version 1.95 + +=over 4 + +=item 2004-10-19 + +Fixed problem with extra semicolons breaking code statements broken onto +multiple % code lines; thanks to Alan Ferrency for test code to isolate +the problem, now added to regression tests. + +=item 2004-10-17 + +Documentation updates. + +=back + + +=head2 Version 1.94 + +=over 4 + +=item 2004-10-17 + +Factored subclass-specific lex_token() method out from superclass lex() method. + +Added Embperl mixin class with emulation for HTML::Embperl. + +Merged Devel.pod back in to other package documentation. + +=item 2004-10-16 + +Replaced assembler attribute with assembler_rules() method. + +Added Mason subclass and moved some functionality to there from Base. + +Documentation updates. + +=item 2004-10-15 + +Added HTMLTemplate mixin class with emulation for HTML::Template. + +=item 2004-10-13 + +Added TextTemplate mixin class with emulation for Text::Template. + +=back + +=head2 Version 1.93 + +=over 4 + +=item 2004-10-12 + +Instead of run-time eval of @MIXIN to fix SUPER resolution, now using a new SUPER method. + +=item 2004-10-11 + +Documentation updates. + +=back + +=head2 Version 1.92 + +=over 4 + +=item 2004-10-11 + +Uploaded to CPAN to fix packaging issue with 1.9_1. + +=back + + +=head2 Version 1.91 + +=over 4 + +=item 2004-10-10 + +Posted description of mixin mechanism to PerlMonks for discussion. + +Debugged CompileCache and finished ExecuteCache. Added test scripts. + +Debugged TemplateDir and added test script. + +Implemented support for one-time options passed to compile that override other attributes. Adjusted Safe facade to prevent this from being done there, in order to avoid escapes from a Safe compartment. + +=item 2004-10-09 + +Reorganized t/ directory. + +=back + + +=head2 Version 1.90 + +=over 4 + +=item 2004-10-08 + +Documentation updates. + +=item 2004-10-05 + +Documentation updates. + +=back + + +=head2 Version 1.55 + +=over 4 + +=item 2004-09-23 + +Documentation updates. + +=back + + +=head2 Version 1.54 + +=over 4 + +=item 2004-09-22 + +Renamed "interpret" method to "execute" for consistency with function interface. + +Moved try_ functionality to new ErrorCatching mixin. + +Generalized behavior of assemble method; moved template elements into %Assembly hash. + +=back + + +=head2 Version 1.53 + +=over 4 + +=item 2004-09-22 + +Moved Safe functionality to new Safe mixin. + +Moved filtering functionality to new Filters mixin. + +=item 2004-09-21 + +Added mixin inheritance hacking logic based on DBIx::SQLEngine::Record::Class. + +=back + + +=head2 Version 1.52 + +=over 4 + +=item 2004-09-19 + +Extracted Changes to separate POD document. + +=item 2004-09-18 + +Additional work. + +=back + + +=head2 Version 1.51 + +=over 4 + +=item 2004-09-17 + +Refactoring of method interface to merge compie and interpretation into single subroutines with parameters to indicate whether we're reading text or a file. + +Added initial support for filtering interpolated expressions based on a patch and extended discussion with Alan Ferrency. + +Packaged as version 1.51 but not released to CPAN. + +=item 2004-09-16 + +Refactored to object-oriented implementation to allow subclassing. Inspired by discussion with Alan Ferrency about how to extend functionality. + +Started CodeCache subclass based on experimental caching code included in 1.07. + +Started TemplateDir subclass with base directory and relative path calculations based on a patch from Tommi Maekitalo. + +Incorporated patch from Tommi Maekitalo to put default values from an <%args> block into the %ARGS variable as well as the separate named variables. + +Created ServerPages subclass based on feature request from William Kern. + +=item 2004-09-15 + +Moved package documentation into separate ReadMe.pod. + +=back + + +=head1 VERSION 1 HISTORY + +=head2 Version 1.07 + +=over 4 + +=item 2003-09-26 + +Discard line break after <%perl> block as suggested by Tommi +Maekitalo. Note that removing these line breaks may affect the +rendering of your current templates! Although I am typically hesitant +to change established behavior, this does improve the template +output and brings us into line with HTML::Mason's behavior. + +Added $Debug flag and support for <%args> blocks based on a +contribution by Tommi Maekitalo. + +Adjusted internals to allow block reordering, and added support +for <%init> and <%once>. + +Released as Text-MicroMason-1.07.tar.gz. + +=back + +=head2 Version 1.06 + +=over 4 + +=item 2003-09-04 + +Changed the way that subroutines were scoped into the +Text::MicroMason::Commands namespace so that Safe compartments with +separate namespaces and shared symbols have the visibility that +one would expect. + +Fixed a bug in which an unadorned percent sign halted parsing, as +reported by William Kern at PixelGate. Added a test to the end of +6-regression.t that fails under 1.05 but passes under 1.06 to +confirm this. + +Simplified parser regular expressions by using non-greedy matching. + +Added documentation for *_file() functions. +Corrected documentation to reflect the fact that template code is not compiled with "use safe" in effect by default, but that this might change in the future. + +Released as Text-MicroMason-1.06.tar.gz. + +=back + +=head2 Version 1.05 + +=over 4 + +=item 2003-08-11 + +Adjusted regular expression based on parsing problems reported by Philip King and Daniel J. Wright, related to newlines and EOF. Added regression tests that fail under 1.04 but pass under 1.05 to ensure these features keep working as expected. + +Added non-printing-character escaping to parser failure and debugging messages to better track future reports of whitespace-related bugs. + +Moved tests from test.pl into t/ subdirectory. + +Added experimental suppport for file code cache in compile_file_codecache. + +Released as Text-MicroMason-1.05.tar.gz. + +=back + +=head2 Version 1.04 + +=over 4 + +=item 2002-06-23 + +Adjusted regular expression based on parsing problems reported by Mark Hampton. + +Added file-include support with <& ... &> syntax. + +Documentation tweaks. Adjusted version number to simpler 0.00 format. +Released as Text-MicroMason-1.04.tar.gz. + +=item 2002-01-14 + +Documentation tweaks based on feedback from Pascal Barbedor. Updated author's contact information. + +=back + +=head2 Version 1.0.3 + +=over 4 + +=item 2001-07-01 + +Renamed from HTML::MicroMason to Text::MicroMason. Documentation tweaks. Released as Text-MicroMason-1.0.3.tar.gz. + +=back + +=head2 Version 1.0.2 + +=over 4 + +=item 2001-04-10 + +Munged interface for clarity. Added Safe support. +Adjusted docs to reflect feedback from mason-users. +Released as HTML-MicroMason-1.0.2.tar.gz. + +=back + +=head2 Version 1.0.1 + +=over 4 + +=item 2001-03-28 + +Parser tweakage; additional documentation. +Added Exporter support. +Released as HTML-MicroMason-1.0.1.tar.gz. + +=item 2001-03-26 + +Added try_interpret; documented error messages. + +=back + +=head2 Version 1.0.0 + +=over 4 + +=item 2001-03-23 + +Extended documentation; added makefile, test script. +Renamed accumulator to $OUT to match Text::Template. +Released as HTML-MicroMason-1.0.0.tar.gz. + +=item 2001-03-22 + +Created. + +=back + + +=head1 SEE ALSO + +For distribution, installation, support, copyright and license +information, see L. + +=cut diff -Nru libtext-micromason-perl-2.13/lib/Text/MicroMason/Docs/ReadMe.pod libtext-micromason-perl-2.16/lib/Text/MicroMason/Docs/ReadMe.pod --- libtext-micromason-perl-2.13/lib/Text/MicroMason/Docs/ReadMe.pod 1970-01-01 00:00:00.000000000 +0000 +++ libtext-micromason-perl-2.16/lib/Text/MicroMason/Docs/ReadMe.pod 2015-06-26 18:11:32.000000000 +0000 @@ -0,0 +1,205 @@ +=head1 NAME + +Text::MicroMason::Docs::ReadMe - About the MicroMason Distribution + +=head1 MOTIVATION + +The HTML::Mason module provides a useful syntax for dynamic template +interpretation (sometimes called embedded scripting): plain text (or +HTML) containing occasional chunks of Perl code whose results are +interpolated into the text when the template is "executed." + +However, HTML::Mason also provides a full-featured web application +framework with numerous other functions, and there are times in which +I'd like to use the templating capability without configuring a full +Mason installation. + +Thus, the Text::MicroMason module was born: it supports the core aspects +of the HTML::Mason syntax ("<%...%>" expressions, "%...\n" lines and +"<%perl>..." blocks, "<& file &>" includes, "%ARGS" and +"$_out->()"), and omits the features that are web specific (like +autohandlers) or are less widely used (like "<%method>" blocks). + +You may well be thinking "yet another dynamic templating module? +Sheesh!" And you'd have a good point. There certainly are a wide variety +of templating toolkits on CPAN already. (For a brief list see +L.) + +Nonetheless, I think this module occupies a useful niche: it provides a +reasonable subset of HTML::Mason syntax in a very light-weight fashion. +In comparison to the other modules listed, MicroMason aims to be fairly +lightweight, using one eval per parse, converting the template to a +compiled subroutine reference, and requiring less than five hundred +lines of Perl code. + +Although it notoriously difficult to fairly benchmark competing template +frameworks, at least some anecdotal evidence indicates that this module +performs reasonably well. + http://use.perl.org/~hctif/journal/25211 + http://www.gtchat.de/templateengines/templateengines_en.html + +It is also highly modular, allowing users to select and enable the +combination of features they desire. Automatic caching, safe +compartments, post-processing and other features are available as mixin +classes that are loaded on demand. + +I've recently added mixin classes that emulate the template syntax used +by Apache::ASP, Embperl, HTML::Template, PLP, Text::Template, and +Text::QuickTemplate. + + +=head1 DISTRIBUTION STATUS + +This is version 2.16 of Text::MicroMason. + +If you encounter any problems, please inform the current maintainer and +I'll endeavor to patch them promptly. + +This module's CPAN registration should read: + + Name DSLIP Description + -------------- ----- --------------------------------------------- + Text:: Group 11: Text Processing + ::MicroMason Rdpfp Simplified HTML::Mason Templating + +Please see the CPAN Testers report for a sample of systems this module +has been tested successfully on: + + http://testers.cpan.org/show/Text-MicroMason.html + +=head1 PREREQUISITES + +The required version of perl has been increased to 5.6 as of version +1.993_01. It should work with on any standard platform which runs Perl. + +Although almost all currently existing features work on versions of Perl +reaching back to 5.0, it will benefit Text::MicroMason in the long run +if supporting legacy versions of Perl was not necessary. Please contact +the new maintainer to gripe, if you absolutely need Text::MicroMason on +an older version of Perl. + +There is one pre-requisite module not included with the core +distribution which must be installed from CPAN: +L. + +If you want to use the Text::Template compatibility mode, you will also +need to install L. + +Various other mixins included in MicroMason require other modules in +order to be useful, but MicroMason installs and tests without them. (I +should be more specific here in the future.) + +=head1 INSTALLATION + +You should be able to install this module using the CPAN shell interface: + + perl -MCPAN -e 'install Text::MicroMason' + +Alternately, you may retrieve this package from CPAN +(C). + +After downloading the distribution, follow the normal procedure to +unpack and install it, using the commands shown below or their local +equivalents on your system: + + tar xzf Text-MicroMason-*.tar.gz + cd Text-MicroMason-* + perl Makefile.PL + make test && sudo make install + + +=head1 SUPPORT + +If you have questions or feedback about this module, please feel free to +contact the maintainer or original author at the e-mail address listed +below. Although there is no formal support program, I do attempt to +answer email promptly. + +I would be particularly interested in any suggestions towards +improving the documentation, correcting any Perl-version or platform +dependencies, as well as general feedback and suggested additions. + +Bug reports that contain a failing test case are greatly appreciated, +and suggested patches will be promptly considered for inclusion in +future releases. + +You can report bugs via the CPAN web tracking system, or send mail +to C, replacing C<#> with C<@>. + + http://rt.cpan.org/NoAuth/Bugs.html?Dist=Text-MicroMason + + +=head1 COMMUNITY + +If you've found this module useful or have feedback about your +experience with it, consider sharing your opinion with other Perl users +by posting your comment to CPAN's ratings system. + + http://cpanratings.perl.org/rate/?distribution=Text-MicroMason + +For more general discussion, you may wish to post a message on the +CPAN::Forum, on PerlMonks, or on the comp.lang.perl.modules newsgroup. +These are not all monitored by the current maintainer, so if you want a +response, please contact me directly. + + http://www.cpanforum.com/dist/Text-MicroMason + http://perlmonks.org/?node=Seekers%20of%20Perl%20Wisdom + http://groups.google.com/groups?group=comp.lang.perl.modules + + +=head1 THANKS + +My sincere thanks to the following people for their feedback and +contributions: + + Pascal Barbedor + Mark Hampton + Philip King + Daniel J. Wright + William Kern + Tommi Maekitalo + Alan Ferrency + Jonas Alves + Alexander + Matthew Simon Cavalletto + Jon Warbrick + Frank Wiegand + Mike Kelly + Niko Tyni + Ansgar Burchardt + vshih + +=head1 SOURCE MATERIAL + +Portions based on HTML::Mason by Jonathan Swartz. + +Portions based on Embperl by Gerald Richter. + +Portions based on HTML::Template by Sam Tregar. + +Portions based on PLP by Juerd Waalboer. + +Portions based on Text::Template by Mark Jason Dominus. + +Portions based on Text::QuickTemplate by Eric J. Roode. + + +=head1 AUTHOR + +Developed by Matthew Simon Cavalletto at Evolution Softworks. You may +contact the author directly at C or +C, replacing C<#> with C<@>. + +Currently maintained by Alan Ferrency at pair +Networks, Inc. + +=head1 LICENSE + +Copyright 2002, 2003, 2004, 2005 Matthew Simon Cavalletto. + +Portions copyright 2001 Evolution Online Systems, Inc. + +You may use, modify, and distribute this software under the same +terms as Perl. + +=cut diff -Nru libtext-micromason-perl-2.13/lib/Text/MicroMason/Docs/Related.pod libtext-micromason-perl-2.16/lib/Text/MicroMason/Docs/Related.pod --- libtext-micromason-perl-2.13/lib/Text/MicroMason/Docs/Related.pod 1970-01-01 00:00:00.000000000 +0000 +++ libtext-micromason-perl-2.16/lib/Text/MicroMason/Docs/Related.pod 2015-06-26 18:11:32.000000000 +0000 @@ -0,0 +1,117 @@ +=head1 NAME + +Text::MicroMason::Docs::Related - A Brief Survey of Templating Modules + +=head1 RELATED MODULES + +Text::MicroMason is just one of dozens (or hundreds) of templating +distributions on CPAN. + +This document mentions a few related modules and includes a brief discussion of some similarities and differences among them. + + +=head1 OTHER COMPARISONS + +For a more authoritative discussion, see Perrin Harkins' classic article at L. + +For reference, here's a slightly mangled version of the comparison matrix +at the conclusion of that article: + + Scope Style Parsing Language + HTML::Mason Framework Callback Compiled Perl + HTML::Embperl Framework Callback Compiled Perl + Apache::ASP Framework Callback Compiled Perl and XSL + AxKit Framework Pipeline Compiled or Perl, XSL and + Cached Parse Mini-Languages + SSI Templates Callback Repeated Parse Mini-Language + Template Tlkit Templates Pipeline Compiled Mini-Language + HTML::Template Templates Pipeline Cached Parse Mini-Language + Text::Template Templates Pipeline Compiled Perl + + + +=head1 POINTS OF COMPARISON + +There are serveral ways we can differentiate between templating systems: + +=over 4 + +=item Perl Syntax vs. Little Languages + +Some templating systems use Perl syntax for both interpolated expressions +and flow control, including L, +L, and L. + +Others use "little languages", including L and L. + +=item Just Templating vs. Web Application Framework + +Some templating systems just provide functions to fill in templates, like L. + +Others are part of full-blown web application frameworks like +L, ePerl, L, +and L. + +=item Modular vs Monolithic + +Some templating systems are not particularly configurable or extensible. + +Others support various kinds of extensions, including L, L and L. + +=item Interpreted vs. Compiled + +Some templating systems repeatedly parse the template from scratch every time it is used. + +Others parse the template into an intermediate data structure and then iterate over that each time the template is used. + +Others convert the template into equivalent Perl source code which can be compiled into a directly-executable subroutine and used repeatedly, including L and L. + +=back + + +=head1 EMULATED MODULES + +=head2 Apache::ASP + +For an emulation for L, +see L. + +=head2 Embperl + +For an emulation for L, +see L. + +=head2 HTML::Template + +For an emulation for L, +see L. + +See also L. + +=head2 HTML::Mason + +For an emulation for L, +see L. + +(If you've already got HTML::Mason installed, configured, and loaded +into your process, you're probably better off using it rather than +this package. HTML::Mason's C<$interp-Emake_component()> method +allows you to parse a text string without saving it to disk first.) + +=head2 PLP + +For an emulation for L, +see L. + +=head2 Text::Template + +For an emulation for L, +see L. + + +=head1 SEE ALSO + +For distribution, installation, support, copyright and license +information, see L. + +=cut diff -Nru libtext-micromason-perl-2.13/lib/Text/MicroMason/Docs/ToDo.pod libtext-micromason-perl-2.16/lib/Text/MicroMason/Docs/ToDo.pod --- libtext-micromason-perl-2.13/lib/Text/MicroMason/Docs/ToDo.pod 1970-01-01 00:00:00.000000000 +0000 +++ libtext-micromason-perl-2.16/lib/Text/MicroMason/Docs/ToDo.pod 2015-06-26 18:11:32.000000000 +0000 @@ -0,0 +1,327 @@ +=head1 NAME + +Text::MicroMason::Docs::ToDo - Development Plans for the MicroMason Distribution + +=head1 DESCRIPTION + +This document outlines various development plans and ideas for Text::MicroMason. + +The TO DO section describes plans which are likely to happen. + +The WISH LIST section describes a variety of ideas which are likely to +be accepted as patches, but which will most likely not be developed with +any priority any time soon. + +If you are interested in a specific feature, whether it is listed here +or not, please contact the current maintainer as described in +L. + +=head1 TO DO + +=head2 Fix all known bugs + +So, please report them. + +=head2 Distribution + +=over 4 + +=item * + +Move the module files into a lib/ directory as expected in modern CPAN +distributions. + +=back + +=head2 New Mixins + +=over 4 + +=item * + +AutoLoad mixin. Using this mixin adds an AUTOLOADER to the mason object, +which interprets all unknown method calls as template names. + +=back + +=head2 New Features + +=over 4 + +=item * + +Support the previously supported but now unsupported +compile(lines => ...) source type. This was documented but non- +functional, and so the pod was removed. + +=back + +=head1 WISH LIST + +=head2 Distribution + +=over 4 + +=item * + +Use Module::Build instead of ExtUtils::MakeMaker. + +=item * + +Consider reorganizing the Text::MicroMason::* modules into a number of +subdirectories. There are currently over two dozen of them, and it's +bound to get worse as time goes on. Perhaps separate them by intent: +Cache::*, Errors::*, Syntax::*, Features::*, etc. + +=item * + +Finish and test the ParseInfo module to facilitate template +introspection. + +=item * + +Rewrite the MOTIVATION section of the ReadMe pod to reflect the shift +from an HTML::Mason clone to a more general templating engine that has +at least partial compatibilty with quite a few other modules. + +=back + +=head2 Interfaces + +=over 4 + +=item * + +Test and improve the ApacheHandler interface. + +Map user-friendly Apache config directives to mixin and initialization +options. Review HTML::Mason::ApacheHandler, HTML::Mason::Params, and +HTML::Mason::Admin. + +Headers need to be constructed as per +http://modperlbook.org/html/ch06_11.html and not sent until our first +print statement; see PLP::Tie::Print. + +=item * + +Review integration with Inline::Mason. Facilitate use of mixins so this +can also do inline ServerPages and other syntaxes. + +=back + +=head2 Core Syntax + +=over 4 + +=item * + +Determine how to best stack lex_token() method so that multiple syntax +plugins can work together. + +=item * + +Extract named blocks parsing from HTMLMason to form a separate mixin. + +=item * + +Extract variable interpolation syntax to allow it to be stacked with +other lexers. + +=back + +=head2 Syntax Emulations + +=over 4 + +=item * + +Add TemplateToolkit module with support for the basic TT syntax. The key +syntax definition is in Parser.yp, which is used to build +Template::Grammar. (L) The Template::Stash dot notation can be handled +by Data::DRef. + +=item * + +Extend HTMLTemplate module with a hash mapping options that could be +passed to HTML::Template's new() into the equivalent behavior, or croak +if they're unsupported. + +=item * + +Consider extending Embperl module to support dynamic HTML tags. + +=item * + +Consider extending ServerPages module to support dynamic XML tags. + +=back + +=head2 Template Sources + +=over 4 + +=item * + +Provide a mixin to search for all files matching a given regex to +facilitate tree searches and cache pre-fetching. + +=item * + +Ensure template inclusion is always handled correctly. Possibly provide +the current template's location in %ENV. + +=item * + +Add a DHandlers mixin that supports default files. On file requests, if +file not found, look for default file. (Attribute dhandler_name controls +name of file to look for.) + +=item * + +Add an AutoHandlers mixin that supports wrapper files. On file +requests, also search hierarchy for autohandler files. (Attribute +autohandler_name controls name of file to look for.) Build a stack of +autohandlers and store it in a mason attribute. Support ->call_next() +to work through the chain. + +(I've also gotten a user request for "decorator files" which turns out +to be roughly equivalent to the AutoHandler system.) + +=item * + +Add a TemplateDB mixin which shows how to retrieve templates from a +database table. Provides a read_db() method. Accept a DBI connection as +an attribute -- or a reference to a function which will return rows from +a sql statement. + +Consider how to support caching for templates drawn from a TemplateDB. +Perhaps in addition to the source_file there can be some kind of opaque +cache key returned by the prepare method? + +Maybe cache values for db templates can be abstracted into closures +which are run to retrieve the cached value. + +=back + +=head2 Caching + +=over 4 + +=item * + +Add a DataCache mixin that provides a pre-configured cache object for +use within template code. Requires cache() method and configuration +attributes. Cache namespace should be based on source file name or +arbitrary instance for text compilation. + +Alan says: I believe this is intended for use to cache contextual data +across template runs? Is this intended to be persistent across multiple +templates (in memory/singleton), or across multiple process invocations +(in a file)? I use mod_perl, and this sounds at best not useful and at +worst, dangerous. + +=item * + +Add an InterpretCache mixin that allows caching of the parsed and +assembled Perl code for a template file, akin to Mason's var/obj/ + directory. (This would also allow visual review when debugging the +converted code.) + +=item * + +The InterpretCache and CompileCache benefit from using a cache object +that checks the keys as filenames to see if the source file has been +updated and forces cache expiration; find a way to extract and reuse +this capability from Text::MicroMason::Cache::File. + +=back + +=head2 Blessing Templates + +=over 4 + +=item * + +Add a BlessSub mixin that blesses the compiled subroutine. This would +let us add support for template-specific behaviors and attributes. +Override eval_sub() to bless sub before returning. Attribute +bless_sub controls initializer arguments passed to BlessedSub class. +BlessedSub class is base class for blessed template objects. Provides +execute() method. + +BlessedSub classes may need their own mixin factory... To avoid having +to define separate mixins for both packages, perhaps the methods should +be delegated from the coderef to the Mason instance? (This becomes +particularly attractive if each sub is automatically getting its own +cloned mason instance anyway.) + + +=item * + +Add an AttrBlock mixin, using BlessedSub. Override lexer methods to +parse <%attr> blocks. Stores attribute definitions in a %once block. +Provides attr() method. + +=item * + +Add a MethodBlock mixin, using BlessedSub. Override lexer methods to +parse <%method> blocks. Stores method definitions in a %once block. +Hooks AUTOLOAD to catch method calls. + +=back + +=head2 Internals + +=over 4 + +=item * + +Consider moving output_sub to a new OutputHandle mixin which accepts a +handle as an attribute, then prints output to it rather than returning +the results as a string. + +=item * + +Clarify and document the clone-on-change behavior of prepare() and its +effects when making changes to a mason object after compiling a +template. Perhaps we should ensure that we clone every time, or at least +every time that it matters? + +=back + +=head2 Testing + +=over 4 + +=item * + +Set up a benchmarking tool to compare subclasses with other templating +solutions. Take an example from ApacheBench but execute templates +directly rather than via Apache. Store the expected output in a text +file for comparison. + +Other links to consider when benchmarking: + + http://www.chamas.com/bench/ + http://use.perl.org/~hctif/journal/25211 + http://www.gtchat.de/templateengines/templateengines_en.html + +=item * + +Set up a compliance test tool that compares the output of the various +MicroMason mixins with the other modules they emulate. This should be +able to use many of the same data files as the benchmarking tool. + +=item * + +Add more templates to samples directory and test them. + +=back + +=head1 SEE ALSO + +For distribution, installation, support, copyright and license +information, see L. + +=cut diff -Nru libtext-micromason-perl-2.13/lib/Text/MicroMason/DoubleQuote.pm libtext-micromason-perl-2.16/lib/Text/MicroMason/DoubleQuote.pm --- libtext-micromason-perl-2.13/lib/Text/MicroMason/DoubleQuote.pm 1970-01-01 00:00:00.000000000 +0000 +++ libtext-micromason-perl-2.16/lib/Text/MicroMason/DoubleQuote.pm 2015-06-26 18:11:32.000000000 +0000 @@ -0,0 +1,58 @@ +package Text::MicroMason::DoubleQuote; + +use strict; + +###################################################################### + +# ( $type, $value ) = $mason->lex_token(); +sub lex_token { + / (.*) /xcogs ? ( expr => do { my $x = $1; $x =~ s/\|/\\|/g; "qq|$x|" } ) : () +} + +###################################################################### + +1; + +__END__ + +###################################################################### + +=head1 NAME + +Text::MicroMason::DoubleQuote - Minimalist Interpolation Engine + + +=head1 SYNOPSIS + +Instead of using this class directly, pass its name to be mixed in: + + use Text::MicroMason; + my $mason = Text::MicroMason::Base->new( -DoubleQuote ); + +Templates can be written using Perl's double-quote interpolation syntax: + + $coderef = $mason->compile( text => 'Hello $ARGS{name}!' ); + print $coderef->( name => 'World' ); + + +=head1 DESCRIPTION + +Text::MicroMason::DoubleQuote uses Perl's double-quoting interpolation as a minimalist syntax for templating. + +Of course you don't need this module for simple cases of interpolation, but if you're already using the MicroMason framework to process template files from disk, this module should allow you to make your simplest templates run even faster. + +To embed values other than simple scalars in a double-quoted expression you can use the ${ expr } syntax. For example, you can interpolate a function call with C<"${ \( time() ) }"> or C<"@{[mysub(1,2,3)]}">. As noted in L, "this is fraught with quoting and readability problems, but it is possible." In particular, this can quickly become a mess once you start adding loops or conditionals. If you do find yourself making use of this feature, please consider switching to one of the more powerful template syntaxes like L. + + +=head1 SEE ALSO + +To refer to arguments as $name rather than as $ARGS{name}, see L. + +For an overview of this distribution, see L. + +This is a subclass intended for use with L. + +For distribution, installation, support, copyright and license +information, see L. + +=cut diff -Nru libtext-micromason-perl-2.13/lib/Text/MicroMason/Embperl.pm libtext-micromason-perl-2.16/lib/Text/MicroMason/Embperl.pm --- libtext-micromason-perl-2.13/lib/Text/MicroMason/Embperl.pm 1970-01-01 00:00:00.000000000 +0000 +++ libtext-micromason-perl-2.16/lib/Text/MicroMason/Embperl.pm 2015-06-26 18:11:32.000000000 +0000 @@ -0,0 +1,182 @@ +package Text::MicroMason::Embperl; + +use strict; +use Carp; + +use Safe; + +###################################################################### + +my %block_types = ( + '-' => 'perl', # [- perl statements -] + '+' => 'expr', # [+ perl expression +] + '!' => 'once', # [! perl statements !] + '$' => 'ep_meta', # [$ command args $] +); + +sub lex_token { + # Blocks in [-/+/! ... -/+/!] tags. + /\G \[ (\-|\+|\!) \s* (.*?) \s* \1 \] /gcxs ? ( $block_types{$1} => $2 ) : + + # Blocks in [$ command ... $] tags. + /\G \[ \$ \s* (\S+)\s*(.*?) \s* \$ \] /gcxs ? ( "ep_$1" => $2 ) : + + # Things that don't match the above + /\G ( (?: [^\[] | \[(?![\-\+\!\$]) )+ ) /gcxs ? ( 'text' => $1 ) : + + () +} + +###################################################################### + +sub assembler_rules { + my $self = shift; + $self->NEXT('assembler_rules', @_), + ep_if_token => "perl if ( TOKEN ) {", + ep_elsif_token => "perl } elsif ( TOKEN ) {", + ep_else_token => "perl } else {", + ep_endif_token => "perl }", + ep_while_token => "perl while ( TOKEN ) {", + ep_endwhile_token => "perl }", + ep_foreach_token => "perl foreach TOKEN {", + ep_endforeach_token => "perl }", + ep_do_token => "perl do {", + ep_until_token => "perl } until ( TOKEN );", + ep_var_token => "perl use strict; use vars qw( TOKEN );", +} + +###################################################################### + +1; + +__END__ + +###################################################################### + +=head1 NAME + +Text::MicroMason::Embperl - Alternate Syntax like Embperl Templates + + +=head1 SYNOPSIS + +Instead of using this class directly, pass its name to be mixed in: + + use Text::MicroMason; + my $mason = Text::MicroMason::Base->new( -Embperl ); + +Use the standard compile and execute methods to parse and evalute templates: + + print $mason->compile( text=>$template )->( @%args ); + print $mason->execute( text=>$template, @args ); + +Embperl syntax provides several ways to mix Perl into a text template: + + [- my $name = $ARGS{name}; -] + [$ if $name eq 'Dave' $] + I'm sorry [+ $name +], I'm afraid I can't do that right now. + [$ else $] + [- + my $hour = (localtime)[2]; + my $daypart = ( $hour > 11 ) ? 'afternoon' : 'morning'; + -] + Good [+ $daypart +], [+ $name +]! + [$ endif $] + + +=head1 DESCRIPTION + +This subclass replaces MicroMason's normal lexer with one that supports a syntax similar to Embperl. + +=head2 Compatibility with Embperl + +Embperl is a full-featured application server toolkit with many fatures, of which only the templating functionality is emulated. + +This is not a drop-in replacement for Embperl, as the implementation is quite different, but it should be able to process some existing templates without major changes. + +The following features of EmbPerl syntax are supported: + +=over 4 + +=item * + +Square-bracket markup tags + +=back + +The following syntax features of are B supported: + +=over 4 + +=item * + +Dynamic HTML tags + +=back + +=head2 Template Syntax + +The following elements are recognized by the Embperl lexer: + +=over 4 + +=item * + +[- perl statements -] + +Arbitrary Perl code to be executed at this point in the template. + +=item * + +[+ perl expression +] + +A Perl expression to be evaluated and included in the output. + +=item * + +[! perl statements !] + +Arbitrary Perl code to be executed once when the template is compiled. + +=item * + +[$ I ... $] + +Supported command names are: if, elsif, else, endif, foreach, endforeach, while, endwhile, do, until, var. + +=back + +=head2 Private Methods + +=over 4 + +=item lex_token + + ( $type, $value ) = $mason->lex_token(); + +Lexer for [. ... .] tags. + +Attempts to parse a token from the template text stored in the global $_ and returns a token type and value. Returns an empty list if unable to parse further due to an error. + +=item assembler_rules() + +Adds mappings from command names used in [$ ... $] tokens to the equivalent +Perl syntax. + + %syntax_rules = $mason->assembler_rules(); + +=back + +=cut + + +=head1 SEE ALSO + +For an overview of this templating framework, see L. + +This is a mixin class intended for use with L. + +For distribution, installation, support, copyright and license +information, see L. + +=cut diff -Nru libtext-micromason-perl-2.13/lib/Text/MicroMason/ExecuteCache.pm libtext-micromason-perl-2.16/lib/Text/MicroMason/ExecuteCache.pm --- libtext-micromason-perl-2.13/lib/Text/MicroMason/ExecuteCache.pm 1970-01-01 00:00:00.000000000 +0000 +++ libtext-micromason-perl-2.16/lib/Text/MicroMason/ExecuteCache.pm 2015-06-26 18:11:32.000000000 +0000 @@ -0,0 +1,111 @@ +package Text::MicroMason::ExecuteCache; + +use strict; +use Carp; + +require Text::MicroMason::Base; +require Text::MicroMason::Cache::Simple; + +###################################################################### + +# $code_ref = compile( text => $template ); +sub compile { + my $self = shift; + + my $code_ref = $self->NEXT('compile', @_); + + my $cache = $self->_execute_cache() + or return $code_ref; + + sub { + my $key = join("|", $code_ref, @_); + $cache->get( $key ) or $cache->set( $key, $code_ref->( @_ ) ); + } +} + +sub _execute_cache { + my $self = shift; + + $self->{execute_cache} ||= Text::MicroMason::Cache::Simple->new(); +} + +###################################################################### + +1; + +__END__ + +=head1 NAME + +Text::MicroMason::ExecuteCache - Use a Cache for Template Results + + +=head1 SYNOPSIS + +Instead of using this class directly, pass its name to be mixed in: + + use Text::MicroMason; + my $mason = Text::MicroMason->new( -ExecuteCache ); + +Use the standard compile method to parse a template into a subroutine: + + my $subref = $mason->compile( text=>$template ); + print $subref->( 'name'=>'Dave' ); + +The template does not have to be interpreted the second time because +the results are cached: + + print $subref->( 'name'=>'Dave' ); # fast second time + +When run with different arguments, the template is re-interpreted +and the results stored: + + print $subref->( 'name'=>'Bob' ); # first time for Bob + + print $subref->( 'name'=>'Bob' ); # fast second time for Bob + + +=head1 DESCRIPTION + +Caches the output of templates. + +Note that you should not use this feature if your template code interacts with any external state, such as making changes to an external data source or obtaining values that will change in the future. (However, you can still use the caching provided by L.) + + +=head2 Public Methods + +=over 4 + +=item compile() + +Wraps each template that is compiled into a Perl subroutine in a memoizing closure. + +=back + +=head2 Supported Attributes + +=over 4 + +=item execute_cache + +Defaults to an instance of Text::MicroMason::Cache::Simple. + +=back + +This module uses a simple cache interface that is widely supported: the +only methods required are C and C. You can +use the simple cache classes provided in the Text::MicroMason::Cache:: +namespace, or select other caching modules on CPAN that support the +interface described in L. + + +=head1 SEE ALSO + +For an overview of this templating framework, see L. + +This is a mixin class intended for use with L. + +For distribution, installation, support, copyright and license +information, see L. + +=cut diff -Nru libtext-micromason-perl-2.13/lib/Text/MicroMason/Filters.pm libtext-micromason-perl-2.16/lib/Text/MicroMason/Filters.pm --- libtext-micromason-perl-2.13/lib/Text/MicroMason/Filters.pm 1970-01-01 00:00:00.000000000 +0000 +++ libtext-micromason-perl-2.16/lib/Text/MicroMason/Filters.pm 2015-06-26 18:11:32.000000000 +0000 @@ -0,0 +1,235 @@ +package Text::MicroMason::Filters; + +use strict; +use Carp; + +use Safe; + +###################################################################### + +# Output filtering +use vars qw( %Filters ); +$Filters{p} = \&Text::MicroMason::Base::_printable; + +$Filters{h} = eval { + require HTML::Entities; sub { HTML::Entities::encode( $_[0], q[<>&'"] ) } + } || eval { require CGI; \&CGI::escapeHTML }; + +$Filters{u} = eval { require URI::Escape; \&URI::Escape::uri_escape }; + +sub defaults { + (shift)->NEXT('defaults'), filters => \%Filters, default_filters => '' +} + +###################################################################### + +# $perl_code = $mason->assemble( @tokens ); +sub assemble { + my $self = shift; + my @tokens = @_; + # warn "Filter assemble"; + foreach my $position ( 0 .. int( $#tokens / 2 ) ) { + if ( $tokens[$position * 2] eq 'expr' ) { + my $token = $tokens[$position * 2 + 1]; + my $filt_flags = ($token =~ s/(?parse_filters($self->{default_filters}, $filt_flags)) { + $token = '$m->filter( ' . join(', ', map "'$_'", @filters ) . ', ' . + 'join "", do { ' . $token . '} )'; + } + $tokens[$position * 2 + 1] = $token; + } + } + $self->NEXT('assemble', @tokens ); +} + +# @flags = $mason->parse_filters( @filter_strings ); +sub parse_filters { + my $self = shift; + + my $no_ns; + my $short = join '', 'n', grep { length($_) == 1 } keys %{ $self->{filters} }; + reverse grep { not $no_ns ||= /^n$/ } reverse + map { /^[$short]{2,5}$/ ? split('') : split(/[\s\,]+/) } @_; +} + +###################################################################### + +# %functions = $mason->filter_functions(); +# $function = $mason->filter_functions( $flag ); +# @functions = $mason->filter_functions( \@flags ); +# $mason->filter_functions( $flag => $function, ... ); +sub filter_functions { + my $self = shift; + my $filters = ( ref $self ) ? $self->{filters} : \%Filters; + if ( scalar @_ == 0 ) { + %$filters + } elsif ( scalar @_ == 1 ) { + my $key = shift; + if ( ! ref $key ) { + $filters->{ $key } + } else { + @{ $filters }{ @$key } + } + } else { + %$filters = ( %$filters, @_ ); + } +} + +# @functions = $mason->get_filter_functions( @flags_or_functions ); +sub get_filter_functions { + my $self = shift; + + map { + ( ref $_ eq 'CODE' ) ? $_ : $self->{filters}{ $_ } + or $self->croak_msg("No definition for a filter named '$_'" ); + } @_ +} + +# $result = $mason->filter( @filters, $content ); +sub filter { + my $self = shift; + local $_ = pop; + + foreach my $function ( $self->get_filter_functions( @_ ) ) { + $_ = &$function($_) + } + $_ +} + +###################################################################### + +1; + +__END__ + +###################################################################### + +=head1 NAME + +Text::MicroMason::Filters - Add Output Filters like "|h" and "|u" + + +=head1 SYNOPSIS + +Instead of using this class directly, pass its name to be mixed in: + + use Text::MicroMason; + my $mason = Text::MicroMason->new( -Filters ); + +Use the standard compile and execute methods to parse and evalute templates: + + print $mason->compile( text=>$template )->( @%args ); + print $mason->execute( text=>$template, @args ); + +Enables filtering of template expressions using HTML::Mason's conventions: + + <%args> $name + Welcome, <% $name |h %>! + Click for More + +You can set a default filter and override it with the "n" flag: + + my $mason = Text::MicroMason->new( -Filters, default_filters => 'h' ); + + <%args> $name + Welcome, <% $name %>! + Click for More + +You can define additional filters and stack them: + + my $mason = Text::MicroMason->new( -Filters ); + $mason->filter_functions( myfilter => \&function ); + $mason->filter_functions( uc => sub { return uc( shift ) } ); + + <%args> $name + Welcome, <% $name |uc,myfilter %>! + + +=head1 DESCRIPTION + +This module enables the filtering of expressions before they are output, using HTML::Mason's "|hun" syntax. + +If you have HTML::Entities and URI::Escape available they are loaded to provide the default "h" and "u" filters. If those modules can not be loaded, no error message is produced but any subsequent use of them will fail. + +Attempted use of an unknown filter name will croak with a message stating "No definition for a filter named 'h'". + +=head2 Public Methods + +=over 4 + +=item filter_functions + +Gets and sets values from the hash mapping filter flags to functions. + +If called with no arguments, returns a hash of all available filter flags and functions: + + %functions = $mason->filter_functions(); + +If called with a filter flag returns the associated function, or if provided with a reference to an array of flag names returns a list of the functions: + + $function = $mason->filter_functions( $flag ); + @functions = $mason->filter_functions( \@flags ); + +If called with one or more pairs of filter flags and associated functions, adds them to the hash. (Any filter that might have existed with the same flag name is overwritten.) + + $mason->filter_functions( $flag => $function, ... ); + +=back + +=head2 Supported Attributes + +=over 4 + +=item default_filters + +Optional comma-separated string of filter flags to be applied to all output expressions unless overridden by the "n" flag. + +=back + +=head2 Private Methods + +=over 4 + +=item assemble() + +This method goes through the lexed template tokens looking for uses of filter flags, which it then rewrites as appropriate method calls before passing the tokens on to the superclass. + +=item parse_filters + +Parses one or more strings containing any number of filter flags and returns a list of flags to be used. + + @flags = $mason->parse_filters( @filter_strings ); + +Flags should be separated by commas, except that the commas may be omitted when using a combination of single-letter flags. Flags are applied from left to right. Any use of the "n" flag wipes out all flags defined to the left of it. + +=item get_filter_functions + +Accepts filter flags or function references and returns a list of the corresponding functions. Dies if an unknown filter flag is used. + + @functions = $mason->get_filter_functions( @flags_or_functions ); + +=item filter + +Applies one or more filters to the provided content string. + + $result = $mason->filter( @flags_or_functions, $content ); + +=back + + +=head1 SEE ALSO + +For an overview of this templating framework, see L. + +This is a mixin class intended for use with L. + +For distribution, installation, support, copyright and license +information, see L. + +=cut + diff -Nru libtext-micromason-perl-2.13/lib/Text/MicroMason/Functions.pm libtext-micromason-perl-2.16/lib/Text/MicroMason/Functions.pm --- libtext-micromason-perl-2.13/lib/Text/MicroMason/Functions.pm 1970-01-01 00:00:00.000000000 +0000 +++ libtext-micromason-perl-2.16/lib/Text/MicroMason/Functions.pm 2015-06-26 18:11:32.000000000 +0000 @@ -0,0 +1,192 @@ +package Text::MicroMason::Functions; + +use strict; +use vars qw( @ISA @EXPORT_OK ); + +use Exporter; +@ISA = 'Exporter'; + +@EXPORT_OK = ( + 'compile', # $code_ref = compile( $mason_text ); + 'compile_file', # $code_ref = compile_file( $filename ); + 'safe_compile', # $code_ref = safe_compile( $mason_text ); + 'safe_compile_file', # $code_ref = safe_compile_file( $filename ); + 'execute', # $result = execute( $filename, %args ); + 'execute_file', # $result = execute_file( $filename, %args ); + 'safe_execute', # $result = safe_execute( $mason_text, %args ); + 'safe_execute_file', # $result = safe_execute_file( $filename, %args ); +); + +push @EXPORT_OK, map "try_$_", @EXPORT_OK; + +###################################################################### + +sub Mason { + () +} + +sub SafeMason { + ( -Safe, (ref($_[0]) =~ /Safe/) ? (safe => shift) : () ) +} + +sub CatchingMason { + ( -CatchErrors ); +} + +sub SafeCatchingMason { + ( -CatchErrors, -Safe, (ref($_[0]) =~ /Safe/) ? (safe => shift) : () ) +} + +foreach my $sub (@EXPORT_OK ) { + no strict 'refs'; + my $method = $sub; + my $source = ( $method =~ s/_file// ) ? 'file' : 'text'; + + my $mason = "Mason"; + $mason = "Catching$mason" if ( $method =~ s/try_// ); + $mason = "Safe$mason" if ( $method =~ s/safe_// ); + *{__PACKAGE__."::$sub"} = sub { + Text::MicroMason->new( &$mason ) + ->$method( (ref($_[0]) eq 'CODE') ? 'code' : $source => @_ ) + } +} + +###################################################################### + +1; + +__END__ + +###################################################################### + +=head1 NAME + +Text::MicroMason::Functions - Function Exporter for Simple Mason Templates + + +=head1 SYNOPSIS + +Use the execute function to parse and evalute a template: + + use Text::MicroMason::Functions qw( execute ); + print execute($template, 'name'=>'Dave'); + +Or compile it into a subroutine, and evaluate repeatedly: + + use Text::MicroMason::Functions qw( compile ); + $coderef = compile($template); + print $coderef->('name'=>'Dave'); + print $coderef->('name'=>'Bob'); + +Templates stored in files can be run directly or included in others: + + use Text::MicroMason::Functions qw( execute_file ); + print execute_file( "./greeting.msn", 'name'=>'Charles'); + +Safe usage restricts templates from accessing your files or data: + + use Text::MicroMason::Functions qw( safe_execute ); + print safe_execute( $template, 'name'=>'Bob'); + +All above functions are available in an error-catching "try_*" form: + + use Text::MicroMason::Functions qw( try_execute ); + ($result, $error) = try_execute( $template, 'name'=>'Alice'); + + +=head1 DESCRIPTION + +As an alternative to the object-oriented interface, text containing MicroMason markup code can be compiled and executed by calling the following functions. + +Please note that this interface is maintained primarily for backward compatibility with version 1 of Text::MicroMason, and it does not provide access to some of the newer features. + +Each function creates a new MicroMason object, including any necessary traits such as Safe compilation or CatchErrors for exceptions, and then passes its arguments to an appropriate method on that object. + +You may import any of these functions by including their names in your +C statement. + +=head2 Basic Invocation + +To evaluate a Mason-like template, pass it to execute(): + + $result = execute( $mason_text ); + +Alternately, you can call compile() to generate a subroutine for your template, and then run the subroutine: + + $result = compile( $mason_text )->(); + +If you will be interpreting the same template repeatedly, you can save the compiled version for faster execution: + + $sub_ref = compile( $mason_text ); + $result = $sub_ref->(); + +(Note that the $sub_ref->() syntax is unavailable in older versions of Perl; use the equivalent &$sub_ref() syntax instead.) + +=head2 Argument Passing + +You can also pass a list of key-value pairs as arguments to execute, or to the compiled subroutine: + + $result = execute( $mason_text, %args ); + + $result = $sub_ref->( %args ); + +Within the scope of your template, any arguments that were provided will be accessible in the global @_, the C<%ARGS> hash, and any variables named in an %args block. + +For example, the below calls will all return 'Foo': + + execute('<% shift(@_) %>', 'Foo'); + execute('<% $ARGS{label} %>', label=>'Foo'); + execute('<%args>$label<% $label %>', label=>'Foo'); + +=head2 Template Files + +A parallel set of functions exist to handle templates which are stored in a file: + + $template = compile_file( './report_tmpl.msn' ); + $result = $template->( %args ); + + $result = execute_file( './report_tmpl.msn', %args ); + +Template documents are just plain text files that contains the string to be parsed. The files may have any name you wish, and the .msn extension shown above is not required. + +=head2 Error Checking + +Both compilation and run-time errors in your template are handled as fatal +exceptions. The provided try_execute() and try_compile() functions use a mixin class which wraps an eval { } block around the basic execute() or compile() +methods. In a scalar context they return the result of the call, or +undef if it failed; in a list context they return the results of the call +(undef if it failed) followed by the error message (undef if it succeeded). +For example: + + ($result, $error) = try_execute( $mason_text ); + if ( ! $error ) { + print $result; + } else { + print "Unable to execute template: $error"; + } + +A matching pair of try_*_file() wrappers are available to catch run-time errors in reading a file or parsing its contents: + + ($template, $error) = try_compile_file( './report_tmpl.msn' ); + + ($result, $error) = try_execute_file( './report_tmpl.msn', %args ); + +For more information, see L. + +=head2 Safe Compartments + +If you wish to restrict the operations that a template can perform, +use the safe_compile() and safe_execute() functions, or their +try_*() wrappers. + +For more information, see L. + + +=head1 SEE ALSO + +For an overview of this templating framework, see L. + +For distribution, installation, support, copyright and license +information, see L. + +=cut diff -Nru libtext-micromason-perl-2.13/lib/Text/MicroMason/HasParams.pm libtext-micromason-perl-2.16/lib/Text/MicroMason/HasParams.pm --- libtext-micromason-perl-2.13/lib/Text/MicroMason/HasParams.pm 1970-01-01 00:00:00.000000000 +0000 +++ libtext-micromason-perl-2.16/lib/Text/MicroMason/HasParams.pm 2015-06-26 18:11:32.000000000 +0000 @@ -0,0 +1,116 @@ +package Text::MicroMason::HasParams; + +###################################################################### + +sub defaults { + (shift)->NEXT('defaults'), params => [ {} ] +} + +###################################################################### + +sub assembler_rules { + my $self = shift; + $self->NEXT('assembler_rules', @_), + init_args => 'local $m->{params} = [ ( @_ == 1 ) ? $_[0] : scalar(@_) ? { @_ } : (), $m->{params} ? @{$m->{params}} : () ];'; +} + +###################################################################### + +sub param { + my $self = shift; + + my @params = $self->{params} ? @{$self->{params}} : (); + + if ( scalar @_ == 0 ) { + return map( keys(%$_), @params ), + $self->{associate} ? $self->{associate}->param() : () + + } elsif ( scalar @_ > 1 ) { + if ( my $associate = $self->{associate} ) { + return $associate->param( @_ ); + } + $self->{params} ||= [ {} ]; + $self->{params}[0] ||= {}; + my $target = $self->{params}[0]; + if ( $self->{case_sensitive} ) { + %$target = ( %$target, @_ ); + } else { + my %hash = @_; + %$target = ( %$target, map { lc($_) => $hash{$_} } keys %hash ); + # warn "set params $self->{params}[0]: " , %{ $self->{params}[0] }; + } + + } elsif ( scalar @_ == 1 and ref( $_[0] ) ) { + push @{$self->{params}}, shift(); + + } else { + my $key = $self->{case_sensitive} ? shift : lc( shift ); + # warn "get params $key: $#params\n"; + foreach my $param ( @params ) { + # warn "get params $param: $key\n"; + my $case_key = ( exists $param->{ $key } ) ? $key : + ( ! $self->{case_sensitive} ) ? ( grep { lc eq $key } keys %$param )[0] : undef; + next unless defined $case_key; + my $value = $param->{ $case_key }; + # warn "get params $param: $key ($case_key) = $value\n"; + return( ( ref($value) eq 'ARRAY' ) ? @$value : $value ) + } + if ( my $associate = $self->{associate} ) { + my $case_key = ( $self->{case_sensitive} ) ? $key : + ( grep { lc eq $key } $associate->param() )[0]; + return $associate->param( $case_key ); + } + return; + } +} + +###################################################################### + +1; + +__END__ + +###################################################################### + +=head1 NAME + +Text::MicroMason::HasParams - mixin class intended for use with Text::MicroMason::Base + +=head1 DESCRIPTION + +This mixin class ... + +' +=head2 Public Methods + +=over 4 + +=item param() + +Gets and sets parameter arguments. Similar to the param() method provied by HTML::Template and the CGI module. + +=back + + +=head2 Private Methods + +=over 4 + +=item assembler_rules() + +Adds initialization for param() at the beginning of each subroutine to be compiled. + +=back + + +=head1 SEE ALSO + +For an overview of this templating framework, see L. + +This is a mixin class intended for use with L. + +For distribution, installation, support, copyright and license +information, see L. + +=cut + diff -Nru libtext-micromason-perl-2.13/lib/Text/MicroMason/HTMLMason.pm libtext-micromason-perl-2.16/lib/Text/MicroMason/HTMLMason.pm --- libtext-micromason-perl-2.13/lib/Text/MicroMason/HTMLMason.pm 1970-01-01 00:00:00.000000000 +0000 +++ libtext-micromason-perl-2.16/lib/Text/MicroMason/HTMLMason.pm 2015-06-26 18:11:32.000000000 +0000 @@ -0,0 +1,511 @@ +package Text::MicroMason::HTMLMason; + +use strict; + +###################################################################### + +my $re_eol = "(?:\\r\\n|\\r|\\n|\\z)"; +my $re_sol = "(?:\\A|(?<=\\r|\\n) )"; +my $re_tag = "perl|args|once|init|cleanup|doc|text|expr|file"; + +# ( $type, $value ) = $mason->lex_token(); +sub lex_token { + # Blocks in <%word> ... <%word> tags. + /\G \<\%($re_tag)\> (.*?) \<\/\%\1\> $re_eol? /xcogs ? ( $1 => $2 ) : + + # Blocks in <% ... %> tags. + /\G \<\% ( .*? ) \%\> /xcogs ? ( 'expr' => $1 ) : + + # Blocks in <& ... &> tags. + /\G \<\& ( .*? ) \&\> /xcogs ? ( 'file' => $1 ) : + + # Lines begining with % + /\G $re_sol \% ( [^\n\r]* ) $re_eol /xcogs ? ( 'perl' => $1 ) : + + # Things that don't match the above + /\G ( (?: [^\<\r\n%]+ | \<(?!\%|\&) | (?<=[^\r\n\<])% | + $re_eol (?:\z|[^\r\n\%\<]|(?=\r\n|\r|\n|\%)|\<[^\%\&]|(?=\<[\%\&])) + )+ (?: $re_eol +(?:\z|(?=\%|\<\[\%\&])) )? + ) /xcogs ? ( 'text' => $1 ) : + + # Lexer error + () +} + +###################################################################### + +# Text elements used for subroutine assembly +sub assembler_rules { + my $self = shift; + $self->NEXT('assembler_rules'), + template => [ qw( @once $sub_start $init_errs $init_output $init_args + @init @perl !@cleanup $return_output $sub_end -@doc ) ] +} + +sub assemble_args { + my ( $self, $token ) = @_; + $token =~ s/^\s*([\$\@\%])(\w+) (?:\s* => \s* ([^\r\n]+))?/ + my $argvar = ($1 eq '$') ? "\$ARGS{$2}" : "$1\{ \$ARGS{$2} }"; + "my $1$2 = exists \$ARGS{$2} ? $argvar : " . + ( defined($3) ? "($argvar = $3)" : + qq{Carp::croak("no value sent for required parameter '$2'")} ) . + ";"/gexm; + return ( 'init' => '($#_ % 2) or Carp::croak("Odd number of parameters passed to sub expecting name/value pairs"); ' . "\n" . $token ); +} + +###################################################################### + +1; + +__END__ + +###################################################################### + +=head1 NAME + +Text::MicroMason::HTMLMason - Simple Compiler for Mason-style Templating + + +=head1 SYNOPSIS + +Create a MicroMason object to interpret the templates: + + use Text::MicroMason; + my $mason = Text::MicroMason->new(); + +Use the standard compile and execute methods to parse and evalute templates: + + print $mason->compile( text=>$template )->( @%args ); + print $mason->execute( text=>$template, @args ); + +Mason syntax provides several ways to mix Perl into a text template: + + <%args> + $name + + + % if ( $name eq 'Dave' ) { + I'm sorry <% $name %>, I'm afraid I can't do that right now. + % } else { + <%perl> + my $hour = (localtime)[2]; + my $daypart = ( $hour > 11 ) ? 'afternoon' : 'morning'; + + Good <% $daypart %>, <% $name %>! + % } + + <& "includes/standard_footer.msn" &> + + <%doc> + Here's a private developr comment describing this template. + + + +=head1 DESCRIPTION + +The Text::MicroMason::HTMLMason class provides lexer and assembler methods that allow Text::MicroMason to handle most elements of HTML::Mason's template syntax. + + +=head2 Compatibility with HTML::Mason + +HTML::Mason is a full-featured application server toolkit with many fatures, of which only the templating functionality is emulated. + +The following sets of HTML::Mason features B supported by Text::MicroMason: + +=over 4 + +=item * + +Template interpolation with <% expr %> + +=item * + +Literal Perl lines with leading % + +=item * + +Named %args, %perl, %once, %init, %cleanup, and %doc blocks + +=item * + +The $m mason object, although with many fewer methods + +=item * + +Expression filtering with |h and |u (via -Filter mixin) + +=back + +The following sets of HTML::Mason features are B supported by Text::MicroMason: + +=over 4 + +=item * + +No %attr, %flag, %shared, %method, or %def blocks. + +=item * + +No shared files like autohandler and dhandler. + +=item * + +No $r request object. No mod_perl integration or configuration capability. + +=back + +Contributed patches to add these features of HTML::Mason would be +welcomed by the author. Possible implemenations are described in +L. + +=head2 Private Methods + +The following internal methods are used to implement the syntax described below. + +=over 4 + +=item lex_token + + ( $type, $value ) = $mason->lex_token(); + +Supports HTML::Mason's markup syntax. + +Attempts to parse a token from the template text stored in the global $_ and returns a token type and value. Returns an empty list if unable to parse further due to an error. + +=item assembler_rules() + +Returns a hash of text elements used for Perl subroutine assembly. Used by assemble(). + +Supports HTML::Mason's named blocks of Perl code and documentation: %once, %init, %cleanup, and %doc. + +=item assemble_args + +Called by assemble(), this method provides support for Mason's <%args> blocks. + +=back + + +=head1 TEMPLATE SYNTAX + +Here's an example of Mason-style templating, taken from L: + + % my $noun = 'World'; + Hello <% $noun %>! + How are ya? + +Interpreting this template with Text::MicroMason produces the same output as it would in HTML::Mason: + + Hello World! + How are ya? + +Text::MicroMason::HTMLMason supports a syntax that is mostly a subset of that used by HTML::Mason. + +=head2 Template Markup + +The following types of markup are recognized in template pages: + +=over 4 + +=item * + +I + +Anything not specifically parsed by one of the below rules is interpreted as literal text. + +=item * + +E% I %E + +A Perl expression to be interpolated into the result. + +For example, the following template text will return a scheduled +greeting: + + Good <% (localtime)[2]>11 ? 'afternoon' : 'morning' %>. + +The block may span multiple lines and is scoped inside a "do" block, +so it may contain multiple Perl statements and it need not end with +a semicolon. + + Good <% my $h = (localtime)[2]; $h > 11 ? 'afternoon' + : 'morning' %>. + +=item * + +% I + +Lines which begin with the % character, without any leading +whitespace, may contain arbitrary Perl code to be executed when +encountering this portion of the template. Their result is not +interpolated into the result. + +For example, the following template text will return a scheduled +greeting: + + % my $daypart = (localtime)[2]>11 ? 'afternoon' : 'morning'; + Good <% $daypart %>. + +The line may contain one or more statements. This code is is not +placed in its own block scope, so it should typically end with a +semicolon; it can still open a spanning block scope closed by a later +perl block. + +For example, the following template text will return one of two different messages each time it's interpreted: + + % if ( int rand 2 ) { + Hello World! + % } else { + Goodbye Cruel World! + % } + +This also allows you to quickly comment out sections of a template by prefacing each line with C<% #>. + +This is equivalent to a <%perl>... block. + +=item * + +E& I, I &E + +Includes the results of a separate file containing MicroMason code, compiling it and executing it with any arguments passed after the filename. + +For example, we could place the following template text into an separate +file: + + Good <% $ARGS{hour} >11 ? 'afternoon' : 'morning' %>. + +Assuming this file was named "greeting.msn", its results could be embedded within the output of another script as follows: + + <& "greeting.msn", hour => (localtime)[2] &> + +=item * + +E%IE ... E/%IE + +A named block contains a span of text. The name at the start and end must match, and must be one of the supported block names. + +Depending on the name, performs one of the behaviors described in L. + +=back + +=head2 Named Blocks + +The following types of named blocks are supported: + +=over 4 + +=item * + +E%perlE I E/%perlE + +Blocks surrounded by %perl tags may contain arbitrary Perl code. +Their result is not interpolated into the result. + +These blocks may span multiple lines in your template file. For +example, the below template initializes a Perl variable inside a +%perl block, and then interpolates the result into a message. + + <%perl> + my $count = join '', map "$_... ", ( 1 .. 9 ); + + Here are some numbers: <% $count %> + +The code may contain one or more statements. This code is is not +placed in its own block scope, so it should typically end with a +semicolon; it can still open a spanning block scope closed by a later +perl block. + +For example, when the below template text is evaluated it will +return a sequence of digits: + + Here are some numbers: + <%perl> + foreach my $digit ( 1 .. 9 ) { + + <% $digit %>... + <%perl> + } + + +If the block is immediately followed by a line break, that break is +discarded. These blocks are not whitespace sensitive, so the template +could be combined into a single line if desired. + +=item * + +E%argsE I => I E/%argsE + +Defines a collection of variables to be initialized from named arguments passed to the subroutine. Arguments are separated by one or more newlines, and may optionally be followed by a default value. If no default value is provided, the argument is required and the subroutine will croak if it is not provided. + +For example, adding the following block to a template will initialize the three named variables, and will fail if no C '...'> argument pair is passed: + + <%args> + $a + @b => qw( foo bar baz ) + %c => () + + +All the arguments are available as lexically scoped ("my") variables in the rest of the component. Default expressions are evaluated in top-to-bottom order, and one expression may reference an earlier one. + +Only valid Perl variable names may be used in <%args> sections. Parameters with non-valid variable names cannot be pre-declared and must be fetched manually out of the %ARGS hash. + +=item * + +E%initE I E/%initE + +Similar to a %perl block, except that the code is moved up to the start of +the subroutine. This allows a template's initialization code to be moved to +the end of the file rather than requiring it to be at the top. + +For example, the following template text will return a scheduled +greeting: + + Good <% $daypart %>. + <%init> + my $daypart = (localtime)[2]>11 ? 'afternoon' : 'morning'; + + +=item * + +E%cleanupE I E/%cleanupE + +Similar to a %perl block, except that the code is moved down to the end of the subroutine. + +=item * + +E%onceE I E/%onceE + +Similar to a %perl block, except that the code is executed once, +when the template is first compiled. (If a caller is using execute, +this code will be run repeatedly, but if they call compile and then +invoke the resulting subroutine multiple times, the %once code will +only execute during the compilation step.) + +This code does not have access to %ARGS and can not generate output. +It can be used to define constants, create persistent variables, +or otherwise prepare the environment. + +For example, the following template text will return a increasing +number each time it is called: + + <%once> + my $counter = 1000; + + The count is <% ++ $counter %>. + +=item * + +E%docE ... E/%docE + +Provides space for template developer documentation or comments which are not included in the output. + +=item * + +E%textE ... E/%textE + +Produces literal text in the template output. Can be used to surround text +that contains other markup tags that should not be interpreted. + +Equivalent to un-marked-up text. + +=back + +The following types of named blocks are not supported by HTML::Mason, but are supported here as a side-effect of the way the lexer and assembler are implemented. + +=over 4 + +=item * + +E%exprE ... E/%exprE + +A Perl expression to be interpolated into the result. +The block may span multiple lines and is scoped inside a "do" block, +so it may contain multiple Perl statements and it need not end with +a semicolon. + +Equivalent to the C% ... %E> markup syntax. + +=item * + +E%fileE I, I E/%fileE + +Includes the results of a separate file containing MicroMason code, compiling it and executing it with any arguments passed after the filename. + + <%file> "greeting.msn", hour => (localtime)[2] + +Equivalent to the C& ... &E> markup syntax. + +=back + + +=head1 TEMPLATE CODING TECHNIQUES + +=head2 Assembling Perl Source Code + +When Text::MicroMason::Base assembles your lexed template into the +equivalent Perl subroutine, all of the literal (non-Perl) pieces are +converted to C<$_out-E('text');> statements, and the interpolated +expressions are converted to C<$_out-E( do { expr } );> statements. +Code from %perl blocks and % lines are included exactly as-is. + +Your code is eval'd in the C package. +The C pragma is enabled by default to simplify debugging. + +=head2 Internal Sub-templates + +You can create sub-templates within your template text by defining +them as anonymous subroutines and then calling them repeatedly. +For example, the following template will concatenate the results of +the draw_item sub-template for each of three items: + +

We've Got Items!

+ + % my $draw_item = sub { +

<% $_[0] %>:
+
See more about <% $_[0] %>.

+ % }; + + <%perl> + foreach my $item ( qw( Foo Bar Baz ) ) { + $draw_item->( $item ); + } + + +=head2 Returning Text from Perl Blocks + +To append to the result from within Perl code, call $_out->(I). +(The $_out->() syntax is unavailable in older versions of Perl; use the +equivalent &$_out() syntax instead.) + +For example, the below template text will return '123456789' when it is +evaluated: + + <%perl> + foreach my $digit ( 1 .. 9 ) { + $_out->( $digit ) + } + + +You can also directly manipulate the value @OUT, which contains the +accumulating result. + +For example, the below template text will return an altered version of its +message if a true value for 'minor' is passed as an argument when the +template is executed: + + This is a funny joke. + % if ( $ARGS{minor} ) { foreach ( @OUT ) { tr[a-z][n-za-m] } } + + +=head1 SEE ALSO + +For a full-featured web application system using this template syntax, see L. + +For an overview of this distribution, see L. + +This is a subclass intended for use with L. + +For distribution, installation, support, copyright and license +information, see L. + +=cut + diff -Nru libtext-micromason-perl-2.13/lib/Text/MicroMason/HTMLTemplate.pm libtext-micromason-perl-2.16/lib/Text/MicroMason/HTMLTemplate.pm --- libtext-micromason-perl-2.13/lib/Text/MicroMason/HTMLTemplate.pm 1970-01-01 00:00:00.000000000 +0000 +++ libtext-micromason-perl-2.16/lib/Text/MicroMason/HTMLTemplate.pm 2015-06-26 18:11:32.000000000 +0000 @@ -0,0 +1,376 @@ +package Text::MicroMason::HTMLTemplate; + +require Text::MicroMason::Base; +require Text::MicroMason::TemplateDir; +require Text::MicroMason::StoreOne; +require Text::MicroMason::HasParams; +push @ISA, map "Text::MicroMason::$_", qw( TemplateDir StoreOne HasParams ); + +use strict; + +###################################################################### + +my %param_mapping = ( ### <<== INCOMPLETE ### + global_vars => 'loop_global_vars', + cache => '-CompileCache', + path => '-TemplatePaths', +); + +###################################################################### + +sub output { (shift)->execute_again( @_ ) } + +###################################################################### + +my $prefix_re = '[tT][mM][pP][lL]_'; + +sub lex_token { + # warn " Lexer: " . pos($_) . " of " . length($_) . "\n"; + # Tags in format "", "", or "" + /\G \<(\/?)($prefix_re\w+)\s*(.*?)\> /gcxs + ? ( ( $1 ? "tmpl_end" : lc($2) ) => { $_[0]->parse_args($3) } ) : + + # Things that don't match the above + /\G ( (?: [^<] | <(?!\/?$prefix_re) )+ ) /gcxs ? ( 'text' => $1 ) : + + # Lexer error + () +} + +sub parse_args { + my $self = shift; + my $args = "$_[0]"; + return () unless length($args); + return ( name => $args ) unless ( $args =~ /=/ ); + my @tokens; + until ( $args =~ /\G\z/gc ) { + push ( @tokens, + $args =~ /\G \s* (\w+) \= (?: \"([^\"]+)\" | ( \w+ ) ) (?= \s | \z ) /gcxs + ? ( lc($1) => ( defined($2) ? $2 : $3 ) ) : + $args =~ /\G ( .{0,20} ) /gcxs + && die "Couldn't find applicable parsing rule at '$1'\n" + ); + } + @tokens; +} + +###################################################################### + +sub assemble_tmpl_var { + my ($self, $args) = @_; + + my $output = "\$m->param( '$args->{name}' )"; + if ( defined $args->{default} ) { + $output = "local \$_ = $output; defined ? \$_ : '$args->{default}'" + } + if ( $args->{escape} ) { + $output = "\$m->filter( $output, '$args->{escape}' )" + } + expr => "$output;" +} + +sub assemble_tmpl_include { + my ($self, $args) = @_; + file => $args->{name} +} + +sub assemble_tmpl_loop { + my ($self, $args) = @_; + if ( ! $self->{loop_context_vars} ) { + perl => q/foreach my $args ( $m->param( '/ . $args->{name} . q/' ) ) { + local $m->{params} = [ $args, $m->{loop_global_vars} ? @{$m->{params}} : () ];/ + } else { + perl => q/my @loop = $m->param( '/ . $args->{name} . q/' ); + foreach my $count ( 0 .. $#loop ) { + my $args = $loop[ $count ]; + my %loop_context = ( + __counter__ => $count, + __odd__ => ( $count % 2 ), + __first__ => ( $count == 0 ), + __inner__ => ( $count > 0 and $count < $#loop ), + __last__ => ( $count == $#loop ), + ); + local $m->{params} = [ $args, \%loop_context, $m->{loop_global_vars} ? @{$m->{params}} : () ]; + / + } +} + +sub assemble_tmpl_if { + my ($self, $args) = @_; + perl => q/if ( $m->param( '/ . $args->{name} . q/' ) ) { / +} + +sub assemble_tmpl_unless { + my ($self, $args) = @_; + perl => q/if ( ! $m->param( '/ . $args->{name} . q/' ) ) { / +} + +sub assemble_tmpl_else { + perl => "} else {" +} + +sub assemble_tmpl_end { + perl => "}" +} + +###################################################################### + +use vars qw( %Filters ); + +sub defaults { + (shift)->NEXT('defaults'), filters => \%Filters, +} + +# Output filtering +$Filters{1} = $Filters{html} = \&HTML::Entities::encode + if eval { require HTML::Entities}; +$Filters{url} = \&URI::Escape::uri_escape if eval { require URI::Escape }; + +# $result = $mason->filter( @filters, $content ); +sub filter { + my $self = shift; + my $content = pop; + + foreach my $filter ( @_ ) { + my $function = ( ref $filter eq 'CODE' ) ? $filter : + $self->{filters}{ $filter } || + $self->croak_msg("No definition for a filter named '$filter'" ); + $content = &$function($content) + } + $content +} + +###################################################################### + +1; + +__END__ + +###################################################################### + +=head1 NAME + +Text::MicroMason::HTMLTemplate - Alternate Syntax like HTML::Template + + +=head1 SYNOPSIS + +Instead of using this class directly, pass its name to be mixed in: + + use Text::MicroMason; + my $mason = Text::MicroMason::Base->new( -HTMLTemplate ); + +Use the standard compile and execute methods to parse and evalute templates: + + print $mason->compile( text=>$template )->( @%args ); + print $mason->execute( text=>$template, @args ); + +Or use HTML::Template's calling conventions: + + $template = Text::MicroMason->new( -HTMLTemplate, filename=>'simple.tmpl' ); + $template->param( %arguments ); + print $template->output(); + +HTML::Template provides a syntax to embed values into a text template: + + + I'm sorry , I'm afraid I can't do that right now. + + + Good morning, ! + + Good afternoon, ! + + + + +=head1 DESCRIPTION + +This mixin class overrides several methods to allow MicroMason to emulate +the template syntax and some of the other features of HTML::Template. + +This class automatically includes the following other mixins: TemplateDir, HasParams, and StoreOne. + +=head2 Compatibility with HTML::Template + +This is not a drop-in replacement for HTML::Template, as the implementation is quite different, but it should be able to process most existing templates without major changes. + +This should allow current HTML::Template users to take advantage of +MicroMason's one-time compilation feature, which in theory could be faster +than HTML::Template's run-time interpretation. (No benchmarking yet.) + +The following features of HTML::Template are not supported yet: + +=over 4 + +=item * + +Search path for files. (Candidate for separate mixin class or addition to TemplateDir.) + +=item * + +Many HTML::Template options are either unsupported or have different names and need to be mapped to equivalent sets of attributes. (Transform these in the new() method or croak if they're unsupported.) + +=back + +The following features of HTML::Template will likely never be supported due to fundamental differences in implementation: + +=over 4 + +=item * + +query() method + +=back + +Contributed patches to more closely support the behavior of HTML::Template +would be welcomed by the author. + +=head2 Template Syntax + +The following elements are recognized by the HTMLTemplate lexer: + +=over 4 + +=item * + +I + +Anything not specifically parsed by the below rule is interpreted as literal text. + +=item * + +ETMPL_IE + +A template tag with no attributes. + +=item * + +ETMPL_I IE + +A template tag with a name attribute. + +=item * + +ETMPL_I NAME=I I

Hello <% $name |h %>! + +The Filters mixin provides this capability for Text::MicroMason +templates. To select it, add its name to your Mason initialization call: + + my $mason = Text::MicroMason->new( -Filters ); + +Output expressions may then be followed by "|h" or "|u" escapes; for +example this line would convert any ampersands in the output to the +equivalent HTML entity: + + Welcome to <% $company_name |h %> + +For more information see L. + +=head2 PassVariables + +Allows you to pass arguments to templates as variables instead of the +basic argument list. + +For details see L. + +=head2 PostProcess + +Allows you to specify one or more functions through which all template +output should be passed before it is returned. + +For details see L. + +=head2 Safe + +By default, the code embedded in a template has accss to all of the +capabilities of your Perl process, and could potentially perform +dangerous activities such as accessing or modifying files and starting +other programs. + +If you need to execute untrusted templates, use the Safe module, +which can restrict the operations and data structures that template +code can access. + +To add this functionality to your MicroMason object, see +L. + +=head2 TemplateDir + +The filenames passed to the compile() or execute() methods can be looked +up relative to a base directory path or the current template file. + +To add this functionality to your MicroMason object, see +L. + +=head2 TemplatePath + +The filenames passed to the compile() or execute() methods are looked up +relative to a list of multiple base directory paths, in order. It tries +as hard as possible to maintain compatibility with caching and <& &> +template includes. + +To add this functionality to your MicroMason object, see +L. + + +=head1 OTHER INTERFACES + +=head2 Function Exporter + +Importable functions are provided for users who prefer a procedural interface. + +The supported functions are listed in L. +(For backwards compatibility, those functions can also be imported from +the main Text::MicroMason package.) + +=head2 Template Frameworks + +Adaptor modules are available to use MicroMason from within other frameworks. +For more information, see L and +L. + +=head2 Inline + +MicroMason templates can be embbeded within your source code using Inline. +For more information, see L. + + +=head1 EXCEPTIONS + +Text::MicroMason croaks on error, with an appropriate error string. Some +commonly occurring error messages are described below (where %s +indicates variable message text). See also the pod for each mixin class, +for additional exception strings that may be thrown. + +=over 4 + +=item * + +MicroMason parsing halted at %s + +Indicates that the parser was unable to finish tokenising the source +text. Generally this means that there is a bug somewhere in the regular +expressions used by lex(). + +(If you encounter this error, please feel free to file a bug report or +send an example of the error to the author using the addresses below, +and I'll attempt to correct it in a future release.) + +=item * + +MicroMason compilation failed: %s + +The template was parsed successfully, but the Perl subroutine declaration +it was converted to failed to compile. This is generally a result of a +syntax error in one of the Perl expressions used within the template. + +=item * + +Error in template subroutine: %s + +Additional diagnostic for compilation errors, showing the text of the +subroutine which failed to compile. + +=item * + +Error in template file %s, interpreted as: %s + +Additional diagnostic for compilation errors in external files, showing +the filename and the text of the subroutine which failed to compile. + +=item * + +MicroMason execution failed: %s + +After parsing and compiling the template successfully, the subroutine was +run and caused a fatal exception, generally because that some Perl code +used within the template caused die() to be called (or an equivalent +function like croak or confess). + +=item * + +MicroMason: filename is missing or empty + +One of the compile or execute methods was called with an empty or +undefined filename, or one of the compile_file or execute_file methods +was called with no arguments. + +=item * + +MicroMason can't read from %s: %s + +One of the compile_file or execute_file functions was called but we were +unable to read the requested file, because the file path is incorrect or +we have insufficient priveleges to read that file. + +=back + + +=head1 SEE ALSO + +For distribution, installation, support, copyright and license +information, see L. + +=cut diff -Nru libtext-micromason-perl-2.13/Makefile.PL libtext-micromason-perl-2.16/Makefile.PL --- libtext-micromason-perl-2.13/Makefile.PL 2011-01-13 17:50:54.000000000 +0000 +++ libtext-micromason-perl-2.16/Makefile.PL 2015-06-26 18:11:32.000000000 +0000 @@ -1,4 +1,4 @@ -# $Id: Makefile.PL,v 1.8 2010/09/07 20:25:48 alan Exp $ +# $Id$ use ExtUtils::MakeMaker; @@ -6,7 +6,7 @@ WriteMakefile( NAME => 'Text::MicroMason', - VERSION_FROM => 'MicroMason.pm', + VERSION_FROM => 'lib/Text/MicroMason.pm', PREREQ_PM => { 'Class::MixinFactory' => 0.9, 'File::Spec' => 0.9, @@ -16,7 +16,7 @@ }, MIN_PERL_VERSION => 5.006, - ABSTRACT_FROM => 'MicroMason.pm', + ABSTRACT_FROM => 'lib/Text/MicroMason.pm', AUTHOR => 'Alan Ferrency ', LICENSE => 'perl', ); @@ -42,27 +42,30 @@ docs : README CHANGES TODO -README: MicroMason/Docs/ReadMe.pod - pod2text MicroMason/Docs/ReadMe.pod > README +README: lib/Text/MicroMason/Docs/ReadMe.pod + pod2text lib/Text/MicroMason/Docs/ReadMe.pod > README -CHANGES: MicroMason/Docs/Changes.pod - pod2text MicroMason/Docs/Changes.pod > CHANGES +CHANGES: lib/Text/MicroMason/Docs/Changes.pod + pod2text lib/Text/MicroMason/Docs/Changes.pod > CHANGES -TODO: MicroMason/Docs/ToDo.pod - pod2text MicroMason/Docs/ToDo.pod > TODO +TODO: lib/Text/MicroMason/Docs/ToDo.pod + pod2text lib/Text/MicroMason/Docs/ToDo.pod > TODO }; } #### # Notes, building a distribution # -# Update version in: MicroMason.pm, MicroMason/Docs/ReadMe.pod -# Update pod in: MicroMason/Docs/Changes.pod +# Update version in: +# lib/Text/MicroMason.pm +# lib/Text/MicroMason/Docs/ReadMe.pod +# Update pod in: +# lib/Text/MicroMason/Docs/Changes.pod # # perl Makefile.PL # make docs # make cleanmanifest # make disttest # make dist -# + diff -Nru libtext-micromason-perl-2.13/MANIFEST libtext-micromason-perl-2.16/MANIFEST --- libtext-micromason-perl-2.13/MANIFEST 2011-01-13 17:54:23.000000000 +0000 +++ libtext-micromason-perl-2.16/MANIFEST 2015-06-26 18:11:54.000000000 +0000 @@ -1,41 +1,45 @@ +CHANGES +lib/Text/MicroMason.pm +lib/Text/MicroMason/AllowGlobals.pm +lib/Text/MicroMason/ApacheHandler.pm +lib/Text/MicroMason/Base.pm +lib/Text/MicroMason/Cache/File.pm +lib/Text/MicroMason/Cache/Null.pm +lib/Text/MicroMason/Cache/Simple.pm +lib/Text/MicroMason/CatchErrors.pm +lib/Text/MicroMason/CompileCache.pm +lib/Text/MicroMason/Debug.pm +lib/Text/MicroMason/Docs/Changes.pod +lib/Text/MicroMason/Docs/ReadMe.pod +lib/Text/MicroMason/Docs/Related.pod +lib/Text/MicroMason/Docs/ToDo.pod +lib/Text/MicroMason/DoubleQuote.pm +lib/Text/MicroMason/Embperl.pm +lib/Text/MicroMason/ExecuteCache.pm +lib/Text/MicroMason/Filters.pm +lib/Text/MicroMason/Functions.pm +lib/Text/MicroMason/HasParams.pm +lib/Text/MicroMason/HTMLMason.pm +lib/Text/MicroMason/HTMLTemplate.pm +lib/Text/MicroMason/LineNumbers.pm +lib/Text/MicroMason/ParseInfo.pm +lib/Text/MicroMason/PassVariables.pm +lib/Text/MicroMason/PLP.pm +lib/Text/MicroMason/PostProcess.pm +lib/Text/MicroMason/QuickTemplate.pm +lib/Text/MicroMason/Safe.pm +lib/Text/MicroMason/ServerPages.pm +lib/Text/MicroMason/Sprintf.pm +lib/Text/MicroMason/StoreOne.pm +lib/Text/MicroMason/TemplateDir.pm +lib/Text/MicroMason/TemplatePath.pm +lib/Text/MicroMason/TextTemplate.pm Makefile.PL -MANIFEST This list of files +MANIFEST MANIFEST.SKIP -MicroMason.pm -MicroMason/AllowGlobals.pm -MicroMason/ApacheHandler.pm -MicroMason/Base.pm -MicroMason/Cache/File.pm -MicroMason/Cache/Null.pm -MicroMason/Cache/Simple.pm -MicroMason/CatchErrors.pm -MicroMason/CompileCache.pm -MicroMason/Debug.pm -MicroMason/Docs/Changes.pod -MicroMason/Docs/ReadMe.pod -MicroMason/Docs/Related.pod -MicroMason/Docs/ToDo.pod -MicroMason/DoubleQuote.pm -MicroMason/Embperl.pm -MicroMason/ExecuteCache.pm -MicroMason/Filters.pm -MicroMason/Functions.pm -MicroMason/HasParams.pm -MicroMason/HTMLMason.pm -MicroMason/HTMLTemplate.pm -MicroMason/LineNumbers.pm -MicroMason/ParseInfo.pm -MicroMason/PassVariables.pm -MicroMason/PLP.pm -MicroMason/PostProcess.pm -MicroMason/QuickTemplate.pm -MicroMason/Safe.pm -MicroMason/ServerPages.pm -MicroMason/Sprintf.pm -MicroMason/StoreOne.pm -MicroMason/TemplateDir.pm -MicroMason/TemplatePath.pm -MicroMason/TextTemplate.pm +MYMETA.json +MYMETA.yml +README samples/die.msn samples/hello_world.msp samples/if.tmpl @@ -88,4 +92,6 @@ t/90-cache-dir-conflict.t t/91-template_path.t t/92-template_path-cache.t -META.yml Module meta-data (added by MakeMaker) +TODO +META.yml Module YAML meta-data (added by MakeMaker) +META.json Module JSON meta-data (added by MakeMaker) diff -Nru libtext-micromason-perl-2.13/META.json libtext-micromason-perl-2.16/META.json --- libtext-micromason-perl-2.13/META.json 1970-01-01 00:00:00.000000000 +0000 +++ libtext-micromason-perl-2.16/META.json 2015-06-26 18:11:54.000000000 +0000 @@ -0,0 +1,46 @@ +{ + "abstract" : "Simple and Extensible Templating", + "author" : [ + "Alan Ferrency " + ], + "dynamic_config" : 1, + "generated_by" : "ExtUtils::MakeMaker version 7.0401, CPAN::Meta::Converter version 2.150001", + "license" : [ + "perl_5" + ], + "meta-spec" : { + "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", + "version" : "2" + }, + "name" : "Text-MicroMason", + "no_index" : { + "directory" : [ + "t", + "inc" + ] + }, + "prereqs" : { + "build" : { + "requires" : { + "ExtUtils::MakeMaker" : "0" + } + }, + "configure" : { + "requires" : { + "ExtUtils::MakeMaker" : "0" + } + }, + "runtime" : { + "requires" : { + "Class::MixinFactory" : "0.9", + "Cwd" : "2.21", + "File::Spec" : "0.9", + "Safe" : "0", + "Test::More" : "0.48", + "perl" : "5.006" + } + } + }, + "release_status" : "stable", + "version" : "2.16" +} diff -Nru libtext-micromason-perl-2.13/META.yml libtext-micromason-perl-2.16/META.yml --- libtext-micromason-perl-2.13/META.yml 2011-01-13 17:54:23.000000000 +0000 +++ libtext-micromason-perl-2.16/META.yml 2015-06-26 18:11:54.000000000 +0000 @@ -1,27 +1,27 @@ ---- #YAML:1.0 -name: Text-MicroMason -version: 2.13 -abstract: Simple and Extensible Templating +--- +abstract: 'Simple and Extensible Templating' author: - - Alan Ferrency -license: perl -distribution_type: module -configure_requires: - ExtUtils::MakeMaker: 0 + - 'Alan Ferrency ' build_requires: - ExtUtils::MakeMaker: 0 -requires: - Class::MixinFactory: 0.9 - Cwd: 2.21 - File::Spec: 0.9 - perl: 5.006 - Safe: 0 - Test::More: 0.48 -no_index: - directory: - - t - - inc -generated_by: ExtUtils::MakeMaker version 6.5601 + ExtUtils::MakeMaker: '0' +configure_requires: + ExtUtils::MakeMaker: '0' +dynamic_config: 1 +generated_by: 'ExtUtils::MakeMaker version 7.0401, CPAN::Meta::Converter version 2.150001' +license: perl meta-spec: - url: http://module-build.sourceforge.net/META-spec-v1.4.html - version: 1.4 + url: http://module-build.sourceforge.net/META-spec-v1.4.html + version: '1.4' +name: Text-MicroMason +no_index: + directory: + - t + - inc +requires: + Class::MixinFactory: '0.9' + Cwd: '2.21' + File::Spec: '0.9' + Safe: '0' + Test::More: '0.48' + perl: '5.006' +version: '2.16' diff -Nru libtext-micromason-perl-2.13/MicroMason/AllowGlobals.pm libtext-micromason-perl-2.16/MicroMason/AllowGlobals.pm --- libtext-micromason-perl-2.13/MicroMason/AllowGlobals.pm 2007-01-29 19:47:01.000000000 +0000 +++ libtext-micromason-perl-2.16/MicroMason/AllowGlobals.pm 1970-01-01 00:00:00.000000000 +0000 @@ -1,149 +0,0 @@ -package Text::MicroMason::AllowGlobals; - -use strict; -use Carp; - -###################################################################### - -sub allow_globals { - my $self = shift; - my $globals = $self->{allow_globals}; - my @current = ref( $globals ) ? @$globals : - ! defined( $globals ) ? () : - split ' ' , $globals; - - if ( scalar @_ ) { - my %once_each; - @current = grep { ! ( $once_each{$_} ++ ) } @current, @_; - $self->{allow_globals} = \@current; - } - - wantarray ? @current : join(' ', @current); -} - -###################################################################### - -sub set_globals { - my ( $self, %globals ) = @_; - - my @globals = keys %globals; - $self->allow_globals( @globals ); - - my $sub = join( "\n", - $self->allow_globals_statement(), - " sub { ", - map( { - my $var = $_; $var =~ s/^[\@\%]/*/; $var =~ s/^(\w)/\$$1/; - "$var = \$_[0]{'$_'};" - } @globals ), - " }" - ); - - $self->eval_sub( $sub )->( \%globals ) -} - -###################################################################### - -sub allow_globals_statement { - my $self = shift; - "use vars qw(" . $self->allow_globals() . ");" -} - -sub assemble { - my $self = shift; - $self->NEXT('assemble', once => $self->allow_globals_statement(), @_); -} - -###################################################################### - -1; - -__END__ - -###################################################################### - -=head1 NAME - -Text::MicroMason::AllowGlobals - Share package vars between templates - - -=head1 SYNOPSIS - -Instead of using this class directly, pass its name to be mixed in: - - use Text::MicroMason; - my $mason = Text::MicroMason->new( -AllowGlobals ); - -Share package variables: - - $mason->set_globals( '$name' => 'Bob' ); - -Use the standard compile and execute methods to parse and evalute templates: - - print $mason->compile( text=>$template )->(); - print $mason->execute( text=>$template ); - -Then, in a template, you can refer to those globals: - - Welcome, <% $name %>! - - -=head1 DESCRIPTION - - -=head2 Public Methods - -=over 4 - -=item set_globals() - -Accepts a list of pairs of global variable names and corresponding values. - -Adds each variable name to the allowed list and sets it to the initial value. - -=item allow_globals() - -Gets or sets the variables names to be allowed. - -If called with arguments, adds them to the list. - -Returns the variables to be allowed as a list, or as a space-separated string in scalar context. - -=back - -=head2 Supported Attributes - -=over 4 - -=item allow_globals - -Optional array or space-separated string of global variable names to be allowed. - -=back - -=head2 Private Methods - -=over 4 - -=item assemble() - -Adds the allow_globals_statement to each token stream before assembling it. - -=item allow_globals_statement() - -This method prepends the "use vars" statement needed for the template subroutines to compile. - -=back - - -=head1 SEE ALSO - -For an overview of this templating framework, see L. - -This is a mixin class intended for use with L. - -For distribution, installation, support, copyright and license -information, see L. - -=cut - diff -Nru libtext-micromason-perl-2.13/MicroMason/ApacheHandler.pm libtext-micromason-perl-2.16/MicroMason/ApacheHandler.pm --- libtext-micromason-perl-2.13/MicroMason/ApacheHandler.pm 2007-01-29 19:47:01.000000000 +0000 +++ libtext-micromason-perl-2.16/MicroMason/ApacheHandler.pm 1970-01-01 00:00:00.000000000 +0000 @@ -1,139 +0,0 @@ -package Text::MicroMason::ApacheHandler; - -use Apache::Constants; -use Apache::Request; - -use Text::MicroMason::Base; - -###################################################################### - -my %configs; - -sub handler ($$) { - my ($package, $r) = @_; - - my $apache = Apache::Request->instance( $r ); - - my $file = $apache->filename; - - # $apache->document_root; - my $syntax = $apache->dir_config('MicroMasonSyntax') || 'HTMLMason'; - my @mixins = $apache->dir_config->get('MicroMasonMixins'); - my @attrs = $apache->dir_config->get('MicroMasonAttribs'); - - my %seen; - unshift @attrs, ( map "-$_", grep { ! $seen{$_} ++ } ( @mixins, $syntax ) ); - - my $config = join ' ', @attrs; - - my $mason = ( $configs{$config} ||= Text::MicroMason::Base->new( @attrs ) ); - - my $template = $mason->compile( file => $file ); - - $apache->content_type( 'text/html' ); - # $apache->header_out(); - - local $Text::MicroMason::Commands::r = $apache; - print $template->( $apache->param() ); - - return Apache::Constants::OK(); -} - -sub configure { - my $apache = Apache::Request->instance( shift ); - - my $file = $apache->filename; - - # $apache->document_root; - my $syntax = $apache->dir_config('MicroMasonSyntax') || 'HTMLMason'; - my @mixins = $apache->dir_config->get('MicroMasonMixins'); - my @attrs = $apache->dir_config->get('MicroMasonAttribs'); - - my %seen; - unshift @attrs, ( map "-$_", grep { ! $seen{$_} ++ } ( @mixins, $syntax ) ); - - my $config = join ' ', @attrs; - - my $mason = ( $configs{$config} ||= Text::MicroMason::Base->new( @attrs ) ); -} - -###################################################################### - -sub translate_params { - MasonAllowGlobals => [ -AllowGlobals, allow_globals => \$1 ], - MasonCompRoot => [ -TemplateDir, template_root => \$1 ], -} - -###################################################################### - -1; - -__END__ - -###################################################################### - -=head1 NAME - -Text::MicroMason::ApacheHandler - Use MicroMason from mod_perl - - -=head1 SYNOPSIS - -In your httpd.conf or equivalent Apache configuration file: - - PerlModule Text::MicroMason::ApacheHandler - - - SetHandler perl-script - PerlHandler Text::MicroMason::ApacheHandler - - -In your document root or other web-accessible directory: - - <% my $visitor = $r->connection->remote_host(); %> - - Hello there <%= $visitor %>! - The time is now <%= localtime() %>. - - -=head1 DESCRIPTION - -B This module is new, experimental, and incomplete. Not intended for production use. Interface subject to change. If you're interested in this capability, your feedback would be appreciated. - -=head2 Configuration - -The following configuration parameters are supported: - -=over 4 - -=item MicroMasonSyntax - - PerlSetVar MicroMasonSyntax HTMLMason - -Name of the syntax class that will compile the templates. Defaults to HTMLMason. - -=item MicroMasonMixins - - PerlAddVar MicroMasonMixins Safe - PerlAddVar MicroMasonMixins CatchErrors - -List of additional mixin classes to be enabled. - -=item MicroMasonAttribs - - PerlAddVar MicroMasonAttribs "-AllowGlobals, allow_globals => '$r'" - -Allows for any set of attributes to be defined. Mixin names prefaced with a dash can also be included. - -=back - -=head1 SEE ALSO - -For an overview of this templating framework, see L. - -This is a mixin class intended for use with L. - -For distribution, installation, support, copyright and license -information, see L. - -=cut diff -Nru libtext-micromason-perl-2.13/MicroMason/Base.pm libtext-micromason-perl-2.16/MicroMason/Base.pm --- libtext-micromason-perl-2.13/MicroMason/Base.pm 2010-01-19 16:52:36.000000000 +0000 +++ libtext-micromason-perl-2.16/MicroMason/Base.pm 1970-01-01 00:00:00.000000000 +0000 @@ -1,602 +0,0 @@ -package Text::MicroMason::Base; - -use strict; -require Carp; - -###################################################################### - -###################################################################### - -use Class::MixinFactory -hasafactory; -for my $factory ( (__PACKAGE__)->mixin_factory ) { - $factory->base_class( "Text::MicroMason::Base" ); - $factory->mixin_prefix( "Text::MicroMason" ); -} - -###################################################################### - -###################################################################### - -sub new { - my $callee = shift; - my ( @traits, @attribs ); - while ( scalar @_ ) { - if ( $_[0] =~ /^\-(\w+)$/ ) { - push @traits, $1; - shift; - } else { - push @attribs, splice(@_, 0, 2); - } - } - if ( scalar @traits ) { - die("Adding moxins to an existing class not supported yet!") - unless ( $callee eq __PACKAGE__ ); - $callee->class( @traits )->create( @attribs ) - } else { - $callee->create( @attribs ) - } -} - -###################################################################### - -# $mason = $class->create( %options ); -# $clone = $object->create( %options ); -sub create { - my $referent = shift; - if ( ! ref $referent ) { - bless { $referent->defaults(), @_ }, $referent; - } else { - bless { $referent->defaults(), %$referent, @_ }, ref $referent; - } -} - -sub defaults { - return () -} - -###################################################################### - -###################################################################### - -# $code_ref = $mason->compile( text => $template, %options ); -# $code_ref = $mason->compile( file => $filename, %options ); -# $code_ref = $mason->compile( handle => $filehandle, %options ); -sub compile { - my ( $self, $src_type, $src_data, %options ) = @_; - - ($self, $src_type, $src_data) = $self->prepare($src_type, $src_data,%options); - - my $code = $self->interpret( $src_type, $src_data ); - - $self->eval_sub( $code ) - or $self->croak_msg( "MicroMason compilation failed: $@\n". _number_lines($code)."\n" ); - -} - -# Internal helper to number the lines in the compiled template when compilation croaks -sub _number_lines { - my $code = shift; - - my $n = 0; - return join("\n", map { sprintf("%4d %s", $n++, $_) } split(/\n/, $code)). - "\n** Please use Text::MicroMason->new\(-LineNumbers\) for better diagnostics!"; -} - - -###################################################################### - -# $result = $mason->execute( code => $subref, @arguments ); -# $result = $mason->execute( $src_type, $src_data, @arguments ); -# $result = $mason->execute( $src_type, $src_data, \%options, @arguments ); -sub execute { - my $self = shift; - my $sub = ( $_[0] eq 'code' ) ? do { shift; shift } : - $self->compile( shift, shift, ref($_[0]) ? %{ shift() } : () ) - or $self->croak_msg("MicroMason compilation failed: $@"); - &$sub( @_ ); -} - -###################################################################### - -###################################################################### - -# ($self, $src_type, $src_data) = $self->prepare($src_type, $src_data, %options) -sub prepare { - my ( $self, $src_type, $src_data, %options ) = @_; - $self = $self->create( %options ) if ( scalar keys %options ); - return ( $self, $src_type, $src_data ); -} - -###################################################################### - -# $perl_code = $mason->interpret( $src_type, $src_data ); -sub interpret { - my ( $self, $src_type, $src_data ) = @_; - my $template = $self->read( $src_type, $src_data ); - my @tokens = $self->lex( $template ); - my $code = $self->assemble( @tokens ); - - # Source file and line number - my $source_line = $self->source_file_line_label( $src_type, $src_data ); - - return $source_line . "\n" . $code; -} - -# $line_number_comment = $mason->source_file_line_label( $src_type, $src_data ); -sub source_file_line_label { - my ( $self, $src_type, $src_data ) = @_; - - if ( $src_type eq 'file' ) { - return qq(# line 1 "$src_data"); - } - - my @caller; - my $call_level; - do { @caller = caller( ++ $call_level ) } - while ( $caller[0] =~ /^Text::MicroMason/ or $self->isa($caller[0]) ); - my $package = ( $caller[1] || $0 ); - qq{# line 1 "text template (compiled at $package line $caller[2])"} -} - - -###################################################################### - -# $code_ref = $mason->eval_sub( $perl_code ); -sub eval_sub { - my $m = shift; - package Text::MicroMason::Commands; - eval( shift ) -} - -###################################################################### - -###################################################################### - -# $template = $mason->read( $src_type, $src_data ); -sub read { - my ( $self, $src_type, $src_data ) = @_; - - my $src_method = "read_$src_type"; - $self->can($src_method) - or $self->croak_msg("Unsupported source type '$src_type'"); - $self->$src_method( $src_data ); -} - -# $template = $mason->read_text( $template ); -sub read_text { - ref($_[1]) ? $$_[1] : $_[1]; -} - -# $contents = $mason->read_file( $filename ); -sub read_file { - my ( $self, $file ) = @_; - local *FILE; - open FILE, "$file" or $self->croak_msg("MicroMason can't open $file: $!"); - local $/ = undef; - local $_ = ; - close FILE or $self->croak_msg("MicroMason can't close $file: $!");; - return $_; -} - -# $contents = $mason->read_handle( $filehandle ); -sub read_handle { - my ( $self, $handle ) = @_; - my $fh = (ref $handle eq 'GLOB') ? $handle : $$handle; - local $/ = undef; - <$fh> -} - -###################################################################### - -# @token_pairs = $mason->lex( $template ); -sub lex { - my $self = shift; - local $_ = "$_[0]"; - my @tokens; - my $lexer = $self->can('lex_token') - or $self->croak_msg('Unable to lex_token(); must select a syntax mixin'); - # warn "Lexing: " . pos($_) . " of " . length($_) . "\n"; - until ( /\G\z/gc ) { - my @parsed = &$lexer( $self ) or - /\G ( .{0,20} ) /gcxs - && die "MicroMason parsing halted at '$1'\n"; - push @tokens, @parsed; - } - return @tokens; -} - -# ( $type, $value ) = $mason->lex_token(); -sub lex_token { - die "The lex_token() method is abstract and must be provided by a subclass"; -} - -###################################################################### - -###################################################################### - -# Text elements used for subroutine assembly -sub assembler_rules { - template => [ qw( $sub_start $init_errs $init_output - $init_args @perl $return_output $sub_end ) ], - - # Subroutine scafolding - sub_start => 'sub { ', - sub_end => '}', - init_errs => - 'local $SIG{__DIE__} = sub { die "MicroMason execution failed: ", @_ };', - - # Argument processing elements - init_args => 'my %ARGS = @_ if ($#_ % 2);', - - # Output generation - init_output => sub { my $m = shift; my $sub = $m->{output_sub} ? '$m->{output_sub}' : 'sub {push @OUT, @_}'; 'my @OUT; my $_out = ' . $sub . ';' }, - add_output => sub { my $m = shift; $m->{output_sub} ? '&$_out' : 'push @OUT,' }, - return_output => 'join("", @OUT)', - - # Mapping between token types - text_token => 'perl OUT( QUOTED );', - expr_token => "perl OUT( \"\".do{\nTOKEN\n} );", - # the "". here forces string context, and should hopefully make - # 'uninitialized' warnings appear closer to their source, rather - # than at the big join "", @OUT; at the end - file_token => "perl OUT( \$m->execute( file => do {\nTOKEN\n} ) );", - # Note that we need newline after TOKEN here in case it ends with a comment. -} - -sub assembler_vars { - my $self = shift; - my %assembler = $self->assembler_rules(); - - my @assembly = @{ delete $assembler{ template } }; - - my %token_map = map { ( /^(.*?)_token$/ )[0] => delete $assembler{$_} } - grep { /_token$/ } keys %assembler; - - my %fragments = map { $_ => map { ref($_) ? &{$_}( $self ) : $_ } $assembler{$_} } keys %assembler; - - return( \@assembly, \%fragments, \%token_map ); -} - -# $perl_code = $mason->assemble( @tokens ); -sub assemble { - my $self = shift; - my @tokens = @_; - - my ( $order, $fragments, $token_map ) = $self->assembler_vars(); - - my %token_streams = map { $_ => [] } map { ( /^\W?\@(\w+)$/ ) } @$order; - - while ( scalar @tokens ) { - my ( $type, $token ) = splice( @tokens, 0, 2 ); - - unless ( $token_streams{$type} or $token_map->{$type} ) { - my $method = "assemble_$type"; - my $sub = $self->can( $method ) - or $self->croak_msg( "Unexpected token type '$type': '$token'" ); - ($type, $token) = &$sub( $self, $token ); - } - - if ( my $typedef = $token_map->{ $type } ) { - # Perform token map substitution in a single pass so that uses of - # OUT in the token text are not improperly converted to output calls. - # -- Simon, 2009-11-14 - my %substitution_map = ( - 'OUT' => $fragments->{add_output}, - 'TOKEN' => $token, - 'QUOTED' => "qq(\Q$token\E)", - ); - $typedef =~ s/\b(OUT|TOKEN|QUOTED)\b/$substitution_map{$1}/g; - - ( $type, $token ) = split ' ', $typedef, 2; - } - - my $ary = $token_streams{$type} - or $self->croak_msg( "Unexpected token type '$type': '$token'" ); - - push @$ary, $token - } - - join( "\n", map { - /^(\W+)(\w+)$/ or $self->croak_msg("Can't assemble $_"); - if ( $1 eq '$' ) { - $fragments->{ $2 } - } elsif ( $1 eq '@' ) { - @{ $token_streams{ $2 } } - } elsif ( $1 eq '!@' ) { - reverse @{ $token_streams{ $2 } } - } elsif ( $1 eq '-@' ) { - () - } else { - $self->croak_msg("Can't assemble $_"); - } - } @$order ); -} - -###################################################################### - -###################################################################### - -sub croak_msg { - local $Carp::CarpLevel = 2; - shift and Carp::croak( ( @_ == 1 ) ? $_[0] : join(' ', map _printable(), @_) ) -} - -my %Escape = ( - ( map { chr($_), unpack('H2', chr($_)) } (0..255) ), - "\\"=>'\\', "\r"=>'r', "\n"=>'n', "\t"=>'t', "\""=>'"' -); - -# $special_characters_escaped = _printable( $source_string ); -sub _printable { - local $_ = scalar(@_) ? (shift) : $_; - return "(undef)" unless defined; - s/([\r\n\t\"\\\x00-\x1f\x7F-\xFF])/\\$Escape{$1}/sgo; - /[^\w\d\-\:\.\']/ ? "q($_)" : $_; -} - -###################################################################### - - -sub cache_key { - my $self = shift; - my ($src_type, $src_data, %options) = @_; - - return $src_data; -} - - -1; - -__END__ - -###################################################################### - -=head1 NAME - -Text::MicroMason::Base - Abstract Template Compiler - - -=head1 SYNOPSIS - -Create a MicroMason object to interpret the templates: - - use Text::MicroMason; - my $mason = Text::MicroMason->new(); - -Use the execute method to parse and evalute a template: - - print $mason->execute( text=>$template, 'name'=>'Dave' ); - -Or compile it into a subroutine, and evaluate repeatedly: - - $coderef = $mason->compile( text=>$template ); - print $coderef->('name'=>'Dave'); - print $coderef->('name'=>'Bob'); - -Templates stored in files can be run directly or included in others: - - print $mason->execute( file=>"./greeting.msn", 'name'=>'Charles'); - - -=head1 DESCRIPTION - -Text::MicroMason::Base is an abstract superclass that provides a parser -and execution environment for an extensible templating system. - -=head2 Public Methods - -=over 4 - -=item new() - - $mason = Text::MicroMason::Base->new( -Mixin1, -Mixin2, %attribs ); - -Creates a new Text::MicroMason object with mixins and attributes. - -Arguments beginning with a dash will be added as mixin classes. -Other arguments are added to the hash of attributes. - -=item compile() - - $code_ref = $mason->compile( text => $template, %options ); - $code_ref = $mason->compile( file => $filename, %options ); - -Parses the provided template and converts it into a new Perl subroutine. - -=item execute() - - $result = $mason->execute( text => $template, @arguments ); - $result = $mason->execute( file => $filename, @arguments ); - $result = $mason->execute( code => $code_ref, @arguments ); - - $result = $mason->execute( $type => $source, \%options, @arguments ); - -Returns the results produced by the template, given the provided arguments. - -=back - -=head2 Attributes - -Attributes can be set in a call to new() and locally overridden in a call to compile(). - -=over 4 - -=item output_sub - -Optional reference to a subroutine to call with each piece of template output. If this is enabled, template subroutines will return an empty string. - -=back - -=head2 Private Methods - -The following internal methods are used to implement the public interface described above, and may be overridden by subclasses and mixins. - -=over 4 - -=item class() - - $class = Text::MicroMason::Base->class( @Mixins ); - -Creates a subclass of this package that also inherits from the other classes named. Provided by Class::MixinFactory::HasAFactory. - -=item create() - - $mason = $class->create( %options ); - $clone = $mason->create( %options ); - -Creates a new instance with the provided key value pairs. - -To obtain the functionality of one of the supported mixin classes, use the class method to generate the mixed class before calling create(), as is done by new(). - -=item defaults() - -This class method is called by new() to provide key-value pairs to be included in the new instance. - -=item prepare() - - ($self, $src_type, $src_data) = $self->prepare($src_type, $src_data, %options) - -Called by compile(), the prepare method allows for single-use attributes and provides a hook for mixin functionality. - -The prepare method provides a hook for mixins to normalize or resolve the template source type and value arguments in various ways before the template is read using one of the read_type() methods. - -It returns an object reference that may be a clone of the original mason object with various compile-time attributes applied. The cloning is a shallow copy performed by the create() method. This means that the $m object visible to a template may not be the same as the MicroMason object on which compile() was originally called. - -Please note that this clone-on-prepare behavior is subject to change in future releases. - -=item interpret - - $perl_code = $mason->interpret( $src_type, $src_data ); - -Called by compile(), the interpret method then calls the read(), lex(), and assemble() methods. - -=item read - - $template = $mason->read( $src_type, $src_data ); - -Called by interpret(). Calls one of the below read_* methods. - -=item read_text - - $template = $mason->read_text( $template ); - -Called by read() when the template source type is "text", this method simply returns the value of the text string passed to it. - -=item read_file - - ( $contents, %path_info ) = $mason->read_file( $filename ); - -Called by read() when the template source type is "file", this method reads and returns the contents of the named file. - -=item read_handle - - $template = $mason->read_handle( $filehandle ); - -Called by read() when the template source type is "handle", this method reads and returns the contents of the filehandle passed to it. - -=item lex - - @token_pairs = $mason->lex( $template ); - -Called by interpret(). Parses the source text and returns a list of pairs of token types and values. Loops through repeated calls to lex_token(). - -=item lex_token - - ( $type, $value ) = $mason->lex_token(); - -Attempts to parse a token from the template text stored in the global $_ and returns a token type and value. Returns an empty list if unable to parse further due to an error. - -Abstract method; must be implemented by subclasses. - -=item assemble - - $perl_code = $mason->assemble( @tokens ); - -Called by interpret(). Assembles the parsed token series into the source code for the equivalent Perl subroutine. - -=item assembler_rules() - -Returns a hash of text elements used for Perl subroutine assembly. Used by assemble(). - -The assembly template defines the types of blocks supported and the order they appear in, as well as where other standard elements should go. Those other elements also appear in the assembler hash. - -=item eval_sub - - $code_ref = $mason->eval_sub( $perl_code ); - -Called by compile(). Compiles the Perl source code for a template using eval(), and returns a code reference. - -=item croak_msg - -Called when a fatal exception has occurred. - -=item NEXT - -Enhanced superclass method dispatch for use inside mixin class methods. Allows mixin classes to redispatch to other classes in the inheritance tree without themselves inheriting from anything. Provided by Class::MixinFactory::NEXT. - -=back - -=head2 Private Functions - -=over 4 - -=item _printable - - $special_characters_escaped = _printable( $source_string ); - -Converts non-printable characters to readable form using the standard backslash notation, such as "\n" for newline. - -=back - -=head1 EXTENDING - -You can add functionality to this module by creating subclasses or mixin classes. - -To create a subclass, just inherit from the base class or some dynamically-assembled class. To create your own mixin classes which can be combined with other mixin features, examine the operation of the class() and NEXT() methods. - -Key areas for subclass writers are: - -=over 4 - -=item prepare - -You can intercept and re-write template source arguments by overriding this method. - -=item read_* - -You can support a new template source type by creating a method with a corresponding name prefixed by "read_". It is passed the template source value and should return the raw text to be lexed. - -For example, if a subclass defined a method named read_from_db, callers could compile templates by calling C<-Ecompile( from_db =E 'welcome-page' )>. - -=item lex_token - -Replace this to parse a new template syntax. Is receives the text to be parsed in $_ and should match from the current position to return the next token type and its contents. - -=item assembler_rules - -The assembler data structure is used to construct the Perl subroutine for a parsed template. - -=item assemble_* - -You can support a new token type be creating a method with a corresponding name prefixed by "assemble_". It is passed the token value or contents, and should return a new token pair that is supported by the assembler template. - -For example, if a subclass defined a method named assemble_sqlquery, callers could compile templates that contained a C%sqlqueryE ... E/%sqlqueryE> block. The assemble_sqlquery method could return a C<< perl => $statements >> pair with Perl code that performed some appropriate action. - -=item compile - -You can wrap or cache the results of this method, which is the primary public interface. - -=item execute - -You typically should not depend on overriding this method because callers can invoke the compiled subroutines directly without calling execute. - -=back - -=head1 SEE ALSO - -For an overview of this templating framework, see L. - -For distribution, installation, support, copyright and license -information, see L. - -=cut diff -Nru libtext-micromason-perl-2.13/MicroMason/Cache/File.pm libtext-micromason-perl-2.16/MicroMason/Cache/File.pm --- libtext-micromason-perl-2.13/MicroMason/Cache/File.pm 2007-12-21 20:42:44.000000000 +0000 +++ libtext-micromason-perl-2.16/MicroMason/Cache/File.pm 1970-01-01 00:00:00.000000000 +0000 @@ -1,103 +0,0 @@ -package Text::MicroMason::Cache::File; -@ISA = 'Text::MicroMason::Cache::Simple'; - -use strict; - -# Array field names -use constant LAST_CHECK => 0; -use constant AGE => 1; -use constant VALUE => 2; - -###################################################################### - -sub get { - my ( $self, $file ) = @_; - my $entry = $self->SUPER::get( $file ) - or return; - unless (ref($entry) eq 'ARRAY' and @$entry == 3 ) { - Carp::croak("MicroMason: cache '$self' data corrupted; " . - "value for '$file' should not be '$entry'"); - } - - my $time = time(); - if ( $entry->[LAST_CHECK] < $time ) { # don't check more than once per second - my $current_age = -M $file; - if ( $entry->[AGE] > $current_age ) { - @$entry = ( 0, 0, undef ); # file has changed; cache invalid - return; - } else { - $entry->[LAST_CHECK] = $time; - } - } - return $entry->[VALUE]; -} - -sub set { - my ($self, $file, $sub) = @_; - $self->SUPER::set( $file => [ time(), -M $file, $sub ] ); - return $sub; -} - -###################################################################### - -1; - -__END__ - -###################################################################### - -=head1 NAME - -Text::MicroMason::Cache::File - Basic Cache with File-Based Expiration - - -=head1 DESCRIPTION - -This simple cache class expects the keys provided to it to be file -pathnames, and considers the cached value to have expired if the -corresponding file is changed. - -It does not perform the following functions: cache size limiting, or -deep copying of complex values. - -=head2 Public Methods - -=over 4 - -=item new() - - $cache = Text::MicroMason::Cache::File->new(); - -=item get() - - $value = $cache->get( $filename ); - -Retrieves the value associated with this key, or undef if there is no value. - -=item set() - - $cache->set( $filename, $value ); - -Stores the provided value in association with this key. - -=item clear() - - $cache->clear(); - -Removes all data from the cache. - -=back - - -=head1 SEE ALSO - -For uses of this cache class, see L. - -Additional cache classes are available in the Text::MicroMason::Cache:: -namespace, or select other caching modules on CPAN that support the -interface described in L. - -For distribution, installation, support, copyright and license -information, see L. - -=cut diff -Nru libtext-micromason-perl-2.13/MicroMason/Cache/Null.pm libtext-micromason-perl-2.16/MicroMason/Cache/Null.pm --- libtext-micromason-perl-2.13/MicroMason/Cache/Null.pm 2007-01-29 19:47:01.000000000 +0000 +++ libtext-micromason-perl-2.16/MicroMason/Cache/Null.pm 1970-01-01 00:00:00.000000000 +0000 @@ -1,70 +0,0 @@ -package Text::MicroMason::Cache::Null; - -use strict; - -###################################################################### - -sub new { my $class = shift; bless { @_ }, $class } - -sub get { return } - -sub set { return $_[2] } - -sub clear { return } - -###################################################################### - -1; - -__END__ - -###################################################################### - -=head1 NAME - -Text::MicroMason::Cache::Null - Trivial Cache with No Data Storage - - -=head1 DESCRIPTION - -This trivial cache class supports the cache interface but doesn't store or retrieve any values. - -=head2 Public Methods - -=over 4 - -=item new() - - $cache = Text::MicroMason::Cache::Null->new(); - -=item get() - - undef = $cache->get( $key ); - -Does nothing. - -=item set() - - $cache->set( $key, $value ); - -Returns the provided value. - -=item clear() - - $cache->clear(); - -Does nothing. - -=back - - -=head1 SEE ALSO - -For uses of this cache class, see L. - -Additional cache classes are available in the Text::MicroMason::Cache:: namespace, or select other caching modules on CPAN that support the interface described in L. - -For distribution, installation, support, copyright and license -information, see L. - -=cut diff -Nru libtext-micromason-perl-2.13/MicroMason/Cache/Simple.pm libtext-micromason-perl-2.16/MicroMason/Cache/Simple.pm --- libtext-micromason-perl-2.13/MicroMason/Cache/Simple.pm 2007-01-29 19:47:01.000000000 +0000 +++ libtext-micromason-perl-2.16/MicroMason/Cache/Simple.pm 1970-01-01 00:00:00.000000000 +0000 @@ -1,72 +0,0 @@ -package Text::MicroMason::Cache::Simple; - -use strict; - -###################################################################### - -sub new { my $class = shift; bless { @_ }, $class } - -sub get { $_[0]->{ $_[1] } } - -sub set { $_[0]->{ $_[1] } = $_[2] } - -sub clear { %{ $_[0] } = () } - -###################################################################### - -1; - -__END__ - -###################################################################### - -=head1 NAME - -Text::MicroMason::Cache::Simple - Basic Cache with Minimal Interface - - -=head1 DESCRIPTION - -This trivial cache class just stores values in a hash. - -It does not perform any of the following functions: expiration, cache size limiting, flatening of complex keys, or deep copying of complex values. - -=head2 Public Methods - -=over 4 - -=item new() - - $cache = Text::MicroMason::Cache::Simple->new(); - -=item get() - - $value = $cache->get( $key ); - -Retrieves the value associated with this key, or undef if there is no value. - -=item set() - - $cache->set( $key, $value ); - -Stores the provided value in association with this key. - -=item clear() - - $cache->clear(); - -Removes all data from the cache. - -=back - - -=head1 SEE ALSO - -For uses of this cache class, see L. - -Additional cache classes are available in the Text::MicroMason::Cache:: namespace, or select other caching modules on CPAN that support the interface described in L. - -For distribution, installation, support, copyright and license -information, see L. - -=cut diff -Nru libtext-micromason-perl-2.13/MicroMason/CatchErrors.pm libtext-micromason-perl-2.16/MicroMason/CatchErrors.pm --- libtext-micromason-perl-2.13/MicroMason/CatchErrors.pm 2007-01-29 19:47:01.000000000 +0000 +++ libtext-micromason-perl-2.16/MicroMason/CatchErrors.pm 1970-01-01 00:00:00.000000000 +0000 @@ -1,103 +0,0 @@ -package Text::MicroMason::CatchErrors; - -use strict; -use Carp; - -###################################################################### - -# sub defaults { -# (shift)->NEXT('assembler_rules'), error_string => 1 -# } - -sub compile { - my $result = eval { local $SIG{__DIE__}; (shift)->NEXT('compile', @_) }; - wantarray ? ($result, $@) : $result; -} - -sub execute { - my $result = eval { local $SIG{__DIE__}; (shift)->NEXT('execute', @_) }; - wantarray ? ($result, $@) : $result; -} - -###################################################################### - -1; - -__END__ - -###################################################################### - -=head1 NAME - -Text::MicroMason::CatchErrors - Add Exception Catching for Templates - - -=head1 SYNOPSIS - -Instead of using this class directly, pass its name to be mixed in: - - use Text::MicroMason; - my $mason = Text::MicroMason->new( -CatchErrors ); - -Use the standard compile and execute methods to parse and evalute templates: - - print scalar $mason->compile( text=>$template )->( @%args ); - print scalar $mason->execute( text=>$template, @args ); - -Result is undef on exception, plus an error message if in list context: - - ($coderef, $error) = $mason->compile( text=>$template ); - ($result, $error) = $mason->execute( text=>$template, 'name'=>'Dave' ); - - -=head1 DESCRIPTION - -This package adds exception catching to MicroMason, allowing you to check -an error variable rather than wrapping every call in an eval. - -Both compilation and run-time errors in your template are handled as fatal -exceptions. The base MicroMason class will croak() if you attempt to -compile or execute a template which contains a incorrect fragment of Perl -syntax. Similarly, if the Perl code in your template causes die() or -croak() to be called, this will interupt your program unless caught by an -eval block. - -This class provides that error catching behavior for the compile and -execute methods. - -In a scalar context they return the result of the call, or undef if it -failed; in a list context they return the results of the call (undef if -it failed) followed by the error message (undef if it succeeded). - -=head2 Public Methods - -=over 4 - -=item compile() - - $code_ref = $mason->compile( text => $template, %options ); - ($coderef, $error) = $mason->compile( text=>$template, %options ); - -Uses an eval block to provide an exception catching wrapper for the compile method. - -=item execute() - - $result = $mason->execute( text => $template, @arguments ); - ($result, $error) = $mason->execute( text=>$template, 'name'=>'Dave' ); - -Uses an eval block to provide an exception catching wrapper for the execute method. - -=back - - -=head1 SEE ALSO - -For an overview of this templating framework, see L. - -This is a mixin class intended for use with L. - -For distribution, installation, support, copyright and license -information, see L. - -=cut - diff -Nru libtext-micromason-perl-2.13/MicroMason/CompileCache.pm libtext-micromason-perl-2.16/MicroMason/CompileCache.pm --- libtext-micromason-perl-2.13/MicroMason/CompileCache.pm 2007-01-29 20:10:22.000000000 +0000 +++ libtext-micromason-perl-2.16/MicroMason/CompileCache.pm 1970-01-01 00:00:00.000000000 +0000 @@ -1,113 +0,0 @@ -package Text::MicroMason::CompileCache; - -use strict; -use Carp; - -require Text::MicroMason::Cache::Simple; -require Text::MicroMason::Cache::File; - -###################################################################### -# What cache class should we use for each src_type? - -my %CACHE_CLASS = ( - file => 'Text::MicroMason::Cache::File', - text => 'Text::MicroMason::Cache::Simple', - ); - -###################################################################### - -# $code_ref = compile( file => $filename ); -sub compile { - my $self = shift; - my ( $src_type, $src_data, %options ) = @_; - my $cache = $self->_compile_cache( $src_type ) - or return $self->NEXT('compile', @_); - my $key = $self->cache_key(@_); - $cache->get( $key ) or $cache->set( $key, - $self->NEXT('compile', @_), - ); -} - -sub _compile_cache { - my ($self, $type) = @_; - $CACHE_CLASS{$type} or return; - - $self->{compile_cache}{$type} ||= $CACHE_CLASS{$type}->new(); -} - -###################################################################### - - -1; - -__END__ - -=head1 NAME - -Text::MicroMason::CompileCache - Use a Cache for Template Compilation - - -=head1 SYNOPSIS - -Instead of using this class directly, pass its name to be mixed in: - - use Text::MicroMason; - my $mason = Text::MicroMason->new( -CompileCache ); - -Use the standard compile and execute methods to parse and evalute templates: - - print $mason->execute( text=>$template, 'name'=>'Dave' ); - -The template does not have to be parsed the second time because it's cached: - - print $mason->execute( text=>$template, 'name'=>'Bob' ); - -Templates stored in files are also cached, until the file changes: - - print $mason->execute( file=>"./greeting.msn", 'name'=>'Charles'); - - -=head1 DESCRIPTION - - -=head2 Public Methods - -=over 4 - -=item compile() - -Caching wrapper around normal compile() behavior. - -=back - -=head2 Supported Attributes - -=over 4 - -=item compile_cache_text - -Defaults to an instance of Text::MicroMason::Cache::Simple. You may pass in your own cache object. - -=item compile_cache_file - -Defaults to an instance of Text::MicroMason::Cache::File. You may pass in your own cache object. - -=back - -This module uses a simple cache interface that is widely supported: the -only methods required are C and C. You can -use the simple cache classes provided in the Text::MicroMason::Cache:: -namespace, or select other caching modules on CPAN that support the -interface described in L. - - -=head1 SEE ALSO - -For an overview of this templating framework, see L. - -This is a mixin class intended for use with L. - -For distribution, installation, support, copyright and license -information, see L. - -=cut diff -Nru libtext-micromason-perl-2.13/MicroMason/Debug.pm libtext-micromason-perl-2.16/MicroMason/Debug.pm --- libtext-micromason-perl-2.13/MicroMason/Debug.pm 2007-01-29 19:47:01.000000000 +0000 +++ libtext-micromason-perl-2.16/MicroMason/Debug.pm 1970-01-01 00:00:00.000000000 +0000 @@ -1,158 +0,0 @@ -package Text::MicroMason::Debug; - -use strict; -use Carp; - -###################################################################### - -use vars qw( %Defaults ); - -sub defaults { - (shift)->NEXT('defaults'), debug => { default => 1 }, -} - -###################################################################### - -sub debug_msg { - my $self = shift; - my $type = shift; - my $flag = ( ! ref $self->{debug} ) ? $self->{debug} : - exists( $self->{debug}{$type} ) ? $self->{debug}{$type} : - $self->{debug}{'default'}; - if ( $flag ) { - warn "MicroMason Debug $type: " . ( ( @_ == 1 ) ? $_[0] : join( ', ', map Text::MicroMason::Base::_printable(), @_ ) ) . "\n"; - } - - wantarray ? @_ : $_[0]; -} - -###################################################################### - -sub new { - my $self = shift; - $self->debug_msg( 'new', $self, @_ ); - $self->NEXT( 'new', @_ ); -} - -sub create { - my $self = (shift)->NEXT( 'create', @_ ); - $self->debug_msg( 'create', ref($self), %$self ); - return $self; -} - -sub prepare { - my ( $self, $src_type, $src_data ) = @_; - my @result = $self->NEXT( 'prepare', $src_type, $src_data ); - if ( scalar @result > 3 or grep { $result[$_] ne $_[$_] } 0 .. 2 ){ - $self->debug_msg( 'prepare', @result ); - } - return @result; -} - -sub interpret { - my $self = shift; - $self->debug_msg( 'interpret', @_ ); - $self->NEXT( 'interpret', @_ ) -} - -# $contents = $mason->read_file( $filename ); -sub read_file { - my $self = shift; - $self->debug_msg( 'read', "Opening file '$_[0]'" ); - $self->NEXT( 'read_file', @_ ) -} - -sub lex { - my $self = shift; - $self->debug_msg( 'source', @_ ); - $self->debug_msg( 'lex', $self->NEXT( 'lex', @_ ) ); -} - -sub assemble { - my $self = shift; - $self->debug_msg( 'assemble', $self->NEXT( 'assemble', @_ ) ); -} - -sub eval_sub { - my $self = shift; - $self->debug_msg( 'eval', @_ ); - $self->NEXT( 'eval_sub', @_ ) -} - -###################################################################### - -1; - -__END__ - -###################################################################### - -=head1 NAME - -Text::MicroMason::Debug - Provide developer info via warn - - -=head1 SYNOPSIS - -Instead of using this class directly, pass its name to be mixed in: - - use Text::MicroMason; - my $mason = Text::MicroMason->new( -Debug ); - -Use the standard compile and execute methods to parse and evalute templates: - - print $mason->compile( text=>$template )->( @%args ); - print $mason->execute( text=>$template, @args ); - -You'll see lots of warning output on STDERR: - - MicroMason Debug create: Text::MicroMason::Base::AUTO::Debug... - MicroMason Debug source: q(Hello <% $noun %>!) - MicroMason Debug lex: text, q(Hello ), expr, q( $noun ), text, q(!) - MicroMason Debug eval: sub { my @OUT; my $_out = sub { push ... - -=head1 DESCRIPTION - -This package provides numerous messages via warn for developer use when debugging templates built with Text::MicroMason. - -=head2 Supported Attributes - -=over 4 - -=item debug - -Activates debugging messages for many methods. Defaults to logging everything. - -Can be set to 0 or 1 to log nothing or everything. - -Alternately, set this to a hash reference containing values for the steps you are interested in to only log this items: - - debug => { source => 1, eval => 1 } - -You can also selectively surpress some warnings: - - debug => { default => 1, source => 0, eval => 0 } - -=back - -=head2 Private Methods - -=over 4 - -=item debug_msg - -Called to provide a debugging message for developer reference. No output is produced unless the object's 'debug' flag is true. - -=back - - -=head1 SEE ALSO - -For an overview of this templating framework, see L. - -This is a mixin class intended for use with L. - -For distribution, installation, support, copyright and license -information, see L. - -=cut diff -Nru libtext-micromason-perl-2.13/MicroMason/Docs/Changes.pod libtext-micromason-perl-2.16/MicroMason/Docs/Changes.pod --- libtext-micromason-perl-2.13/MicroMason/Docs/Changes.pod 2011-01-13 17:54:04.000000000 +0000 +++ libtext-micromason-perl-2.16/MicroMason/Docs/Changes.pod 1970-01-01 00:00:00.000000000 +0000 @@ -1,807 +0,0 @@ -=head1 NAME - -Text::MicroMason::Docs::Changes - Change History for the MicroMason Distribution - - -=head1 VERSION 2 HISTORY - -=over 4 - -=head2 Version 2.13 - -=item 2011-01-13 - -[rt.cpan.org #64192] Skip the Safe-related tests more often, since newer -versions of Safe.pm mark their own failing tests as TODO instead of -changing the module's behavior. - -=head2 Version 2.12 - -=item 2010-09-07 - -Skip more tests that fail due to a bug in Safe.pm. Add a prereq for -Safe.pm so CPAN testers will provide more debug info on failure. - -=head2 Version 2.11 - -=item 2010-09-07 - -[rt.cpan.org #61010] Fix spelling errors and pod example bugs. Thanks to -vshih at yahoo.com for reporting these problems. - -=item 2010-09-07 - -Under Perl 5.13.1 and later with Safe version 2.27, skip failing tests -in t/32-safe.t. The regression tests for Safe 2.27 fail in Perl 5.13.1 -as well, in a similar way. This bug is not fixable in any reasonable way -until Safe.pm is also stable. - -=item 2010-07-26 - -[rt.cpan.org #59081] Fix spelling and pod errors. Thanks to Ansgar -Burchardt and the Debian project for submitting this bug report along -with patches. - -=head2 Version 2.10 - -=item 2010-06-29 - -[rt.cpan.org #57797] Deprecate safe_methods parameter. Unfortunately, -Safe.pm version 2.27 patches a bug we were inadvertantly taking -advantage of to implement the safe_methods parameter. Unless we can -find a working implementation of safe_methods that is smaller than -"make everything unsafe" then we can't continue to support -safe_methods. - -Using safe_methods now issues a deprecation warning, but it should -work with older versions of Safe. I'm in no hurry to remove the -feature, but I don't want anyone to use it who isn't already using it, -until we know it can be supported in the future. - -Thanks to Niko Tyni and the Debian Perl Group for submitting this bug report. - -=item 2010-04-05 - -"uninitialized" warnings in templates were being generated at a line -number within MicroMason instead of a line number within the template -itself. Thanks to Mike Kelly for a patch: by concatenating an empty -string to each TOKEN within the template, the warning's line number is -shifted to inside the template where the interpolation took place. - -=head2 Version 2.09 - -=item 2010-03-24 - -Fix test that was broken by changes in URI::Escape 1.30. Double -quotes aren't reserved characters in URIs but they were previously -encoded anyway. Test modified to use reserved single quotes instead, -for URI::Escape testing. - -=head2 Version 2.08 - -=item 2010-03-08 - -Fixed PassVariables bug: <%init> failed with -PassVariables plugin. -Thanks to William Kern for reporting this. - -=item 2009-11-19 - -Fixed [rt.cpan.org #51727] [Patch] POD nit; thanks to Frank Wiegand for -reporting this. - -=back - -=head2 Version 2.07 - -=over 4 - -=item 2009-11-16 - -Merge patch from Simon Cavalletto: fix bug reported in CPAN forum with -"OUT" appearing in the input template stream. Thanks! - -Update requirement for Test::More 0.48 or later in Makefile.PL. Tests -using unlike() failed with Test::More version 0.47. - -Fix problem in t/08_errors.t which caused test failures in Perl 5.6. The -error message isn't as important as the test made it out to be, but the -code didn't have a problem. - -=item 2009-11-12 - -Remove documentation for unsupported compile(lines => ...) mode. Put it -on ToDo instead. - -=back - -=head2 Version 2.06 - -=over 4 - -=item 2009-11-11 - -Fix bug reported in CPAN forum: substr() in LineNumbers.pm was being -used incorrectly, resulting in incorrect line numbering in some cases. - -=item 2009-11-12 - -#51460: Clean up the tarball and resubmit a version that doesn't -contain a stray .tgz file. - -=back - -=head2 Version 2.05 - -=over 4 - -=item 2009-11-10 - -Modify compilation error reporting: provide line numbers when dumping -the compiled template into $@, and change the #line to match the line -numbering correctly. - -=item 2009-11-11 - -Fix bug reported by CPAN testers on some Windows boxes: use -Cwd::abs_path for strict_root checking to avoid literal path separators -in TemplateDir.pm. - -=item 2009-11-11 - -Add a hint about -LineNumbers in the numbered template dump when a -compilation error occurs. - -=back - -=head2 Version 2.04 - -=over 4 - -=item 2009-11-06 - -Fixed SKIP count in t/33_filters.t to prevent test failures when -URI::Escape isn't installed. - -=back - -=head2 Version 2.03 - -=over 4 - -=item 2009-10-30 - -Happy Halloween. - -Updated tests to use Test::More for better diagnostics via CPAN testers. - -Tweaked t/34 with a longer sleep() since some linux hosts seemed to be -sleeping for less than a second with sleep(1). - -=back - -=head2 Version 2.02 - -=over 4 - -=item 2009-10-29 - -Updated Changes.pod. - -Fixed SKIP count in t/33 which caused test count mismatches when -HTML::Entities wasn't installed. - -=back - -=head2 Version 2.01 - -=over 4 - -=item 2009-10-29 - -Fix a bug with TemplatePath error messages. If a template name was -provided that didn't exist in the path, the error message generated by -read_file didn't specify which template was requested. This version -now croaks in resolve_path instead of returning undef and letting -read_file croak. - -Updated pod to reflect this change and document previously undocumented -exception strings. - -Modified undocumented exception strings for strict_root violations. - -=back - -=head2 Version 2.0 - -=over 4 - -=item 2008-01-02 - -Fix bug with || filter patch: it was erroneously removing the last -character of the filtered token, which made it fail if there was no -space before the |. - -Bump version to 2.0 - -=back - -=head2 Version 1.993_01 - -=over 4 - -=item 2007-12-21 - -Add LineNumbers mixin and associated tests. - -=item 2007-12-21 - -Update TODO: move almost everything into a WISH LIST with a request for -contributions, and make the main TODO list bug fixes and a few likely -developments. - -=item 2007-12-21 - -Merge test and patch from RT bug #21802: cache expiration bug. - -=item 2007-12-21 - -Merge changes from RT bug #18435: filter problem with -<% $thing || "default" %> - -=item 2007-12-21 - -Bump version to 1.993_01 - -=back - - -=head2 Version 1.993 - -=over 4 - -=item 2007-12-20 - -Merge changes from pair Networks local branch, which have been in -testing and production since Q1 2007; bump version to 1.993. - -This includes: - -=over 2 - -=item TemplatePath mixin - -Template lookups on a search path - -=item TemplateDir/ Cache patch - - fix interaction of caching and TemplateDir/TemplatePath - -=item Additional test files - -=item Stop creating cache objects unless/until they're used - -=back - -=back - -=head2 Version 1.992_01 - -=over 4 - -=item 2007-12-20 - -Updated pod and makefiles for maintenance transition from Simon to -Alan. Thanks for the wonderful module, Simon! I hope I can keep things -under control. - -Bumped version number. - -=back - -=head2 Version 1.992 - -=over 4 - -=item 2005-11-13 - -Updated ToDo.pod with a few ideas for upcoming releases. - -Extended t/58-quicktemplate.t to demonstrate use of the pre_fill method. - -=item 2005-11-12 - -Fixed incorrect handling of default values for array or hash variables in an <%args> block. Thanks to Alexander for the bug report. - -Added extra newlines to the do blocks generated by Base's assemble(), so that <% exprs %> can contain a comment. Problem reported by Alexander. - -Improved error reporting by changing the file name embedded in the CPP-style line number comment at the top of each stretch of generated Perl code. Based on a problem report from Alexander. This does not fix the line numbering problem, but at least the file name is more helpful than it used to be. - -=item 2005-08-24 - -Added RoughDraft of "ParseInfo.pm" based on a reply to a question via email from Alexander. - -=item 2005-07-30 - -Fixed return value from Text::MicroMason::Cache::File set() method; thanks to Alan Ferrency for the helpful bug report and test case. - -=item 2005-07-24 - -Extracted HasParams and StoreOne mixins from HTMLTemplate. - -Added QuickTemplate mixin class with emulation for Text::QuickTemplate. - -=item 2005-07-20 - -Added reference links to benchmarking section in Docs/ToDo.pod. - -Added "local $^W;" in two test scripts to silence extra warning on Perl 5.005_04. - -Bumped version number. - -=back - -=head2 Version 1.991 - -=over 4 - -=item 2005-07-19 - -Bumped version number. - -Added ApacheHandler configuration options and basic documentation. - -=item 2005-07-18 - -Added PLP mixin class with emulation for PLP templating package. - -Added the skeleton for a basic ApacheHandler class. - -Improved strict_root support in TemplateDir and added documentation for it. - -Extracted argument passing logic from TextTemplate to create new PassVariables mixin. - -Added Sprintf syntax mixin and basic tests. - -=item 2005-07-17 - -Added DoubleQuote syntax mixin and basic tests. - -=back - -=head2 Version 1.99 - -=over 4 - -=item 2005-07-09 - -Added AllowGlobals mixin based on suggestion and patch from Jonas Alves. Reviewed similar functionality in HTML::Mason and added docs and tests. - -Extracted debug options to separate Debug mixin class. - -Changed name of internal new() method to create(), while propogating the mixin finding behavior from the Text::MicroMason facade up to Text::MicroMason::Base. - -Renamed examples directory to samples. - -Added read_handle method and output_sub attribute. - -Added assembler_vars method and removed %Assembler global. - -=item 2004-12-01 - -Fixed early exit of t/42-text_template.t to skip test if missing Text::Balanced. - -=item 2004-11-30 - -Renamed the Mason compatibilty class to HTMLMason to match other syntax classes. Changed it to be a mixin like the other classes, instead of a subclass. - -Switched to use of Class::MixinFactory and removed old class() and NEXT() methods. - -Extracted new interpret() method from inside of compile(). - -Adjusted setting of options and attributes so that this doesn't happen within interpret(). - -Extracted list of related modules to new Docs::Related POD file. - -=back - -=head2 Version 1.98 - -=over 4 - -=item 2004-11-29 - -Fixed unprotected test dependency on Text::Balanced for TextTemplate emulation. - -Fixed unexpected side-effect of change to parsing for single-character Filter flags. - -Minor adjustments to POD documentation. - -=back - -=head2 Version 1.97 - -=over 4 - -=item 2004-11-28 - -Moved to do list into new pod file. Moved extra pod files into Docs namespace. - -Added _printable to default set of functions in Filters. Tweaked parse_filters and get_filter_functions methods. - -Changed internal names for ouput and include token types to expr and file. Corrected typo in one of the assembler token names. - -Adjusted $Carp::CarpLevel in Base croak_msg(). - -Fixed test failure in t/33-filters.t reported by William Kern. - -=item 2004-10-24 - -Fixed typo in ServerPages example; thanks to William Kern for pointing it out. - -=item 2004-10-20 - -Adjustments to documentation in top-level package. - -=back - - -=head2 Version 1.96 - -=over 4 - -=item 2004-10-19 - -Added PostProcess mixin class at the suggestion of Alan Ferrency. - -Renamed a few keys in the hash returned by assembler_rules(). - -Moved syntax documentation to Mason subclass. - -=back - -=head2 Version 1.95 - -=over 4 - -=item 2004-10-19 - -Fixed problem with extra semicolons breaking code statements broken onto -multiple % code lines; thanks to Alan Ferrency for test code to isolate -the problem, now added to regression tests. - -=item 2004-10-17 - -Documentation updates. - -=back - - -=head2 Version 1.94 - -=over 4 - -=item 2004-10-17 - -Factored subclass-specific lex_token() method out from superclass lex() method. - -Added Embperl mixin class with emulation for HTML::Embperl. - -Merged Devel.pod back in to other package documentation. - -=item 2004-10-16 - -Replaced assembler attribute with assembler_rules() method. - -Added Mason subclass and moved some functionality to there from Base. - -Documentation updates. - -=item 2004-10-15 - -Added HTMLTemplate mixin class with emulation for HTML::Template. - -=item 2004-10-13 - -Added TextTemplate mixin class with emulation for Text::Template. - -=back - - -=head2 Version 1.93 - -=over 4 - -=item 2004-10-12 - -Instead of run-time eval of @MIXIN to fix SUPER resolution, now using a new SUPER method. - -=item 2004-10-11 - -Documentation updates. - -=back - - -=head2 Version 1.92 - -=over 4 - -=item 2004-10-11 - -Uploaded to CPAN to fix packaging issue with 1.9_1. - -=back - - -=head2 Version 1.91 - -=over 4 - -=item 2004-10-10 - -Posted description of mixin mechanism to PerlMonks for discussion. - -Debugged CompileCache and finished ExecuteCache. Added test scripts. - -Debugged TemplateDir and added test script. - -Implemented support for one-time options passed to compile that override other attributes. Adjusted Safe facade to prevent this from being done there, in order to avoid escapes from a Safe compartment. - -=item 2004-10-09 - -Reorganized t/ directory. - -=back - - -=head2 Version 1.90 - -=over 4 - -=item 2004-10-08 - -Documentation updates. - -=item 2004-10-05 - -Documentation updates. - -=back - - -=head2 Version 1.55 - -=over 4 - -=item 2004-09-23 - -Documentation updates. - -=back - - -=head2 Version 1.54 - -=over 4 - -=item 2004-09-22 - -Renamed "interpret" method to "execute" for consistency with function interface. - -Moved try_ functionality to new ErrorCatching mixin. - -Generalized behavior of assemble method; moved template elements into %Assembly hash. - -=back - - -=head2 Version 1.53 - -=over 4 - -=item 2004-09-22 - -Moved Safe functionality to new Safe mixin. - -Moved filtering functionality to new Filters mixin. - -=item 2004-09-21 - -Added mixin inheritance hacking logic based on DBIx::SQLEngine::Record::Class. - -=back - - -=head2 Version 1.52 - -=over 4 - -=item 2004-09-19 - -Extracted Changes to separate POD document. - -=item 2004-09-18 - -Additional work. - -=back - - -=head2 Version 1.51 - -=over 4 - -=item 2004-09-17 - -Refactoring of method interface to merge compie and interpretation into single subroutines with parameters to indicate whether we're reading text or a file. - -Added initial support for filtering interpolated expressions based on a patch and extended discussion with Alan Ferrency. - -Packaged as version 1.51 but not released to CPAN. - -=item 2004-09-16 - -Refactored to object-oriented implementation to allow subclassing. Inspired by discussion with Alan Ferrency about how to extend functionality. - -Started CodeCache subclass based on experimental caching code included in 1.07. - -Started TemplateDir subclass with base directory and relative path calculations based on a patch from Tommi Maekitalo. - -Incorporated patch from Tommi Maekitalo to put default values from an <%args> block into the %ARGS variable as well as the separate named variables. - -Created ServerPages subclass based on feature request from William Kern. - -=item 2004-09-15 - -Moved package documentation into separate ReadMe.pod. - -=back - - -=head1 VERSION 1 HISTORY - -=head2 Version 1.07 - -=over 4 - -=item 2003-09-26 - -Discard line break after <%perl> block as suggested by Tommi -Maekitalo. Note that removing these line breaks may affect the -rendering of your current templates! Although I am typically hesitant -to change established behavior, this does improve the template -output and brings us into line with HTML::Mason's behavior. - -Added $Debug flag and support for <%args> blocks based on a -contribution by Tommi Maekitalo. - -Adjusted internals to allow block reordering, and added support -for <%init> and <%once>. - -Released as Text-MicroMason-1.07.tar.gz. - -=back - -=head2 Version 1.06 - -=over 4 - -=item 2003-09-04 - -Changed the way that subroutines were scoped into the -Text::MicroMason::Commands namespace so that Safe compartments with -separate namespaces and shared symbols have the visibility that -one would expect. - -Fixed a bug in which an unadorned percent sign halted parsing, as -reported by William Kern at PixelGate. Added a test to the end of -6-regression.t that fails under 1.05 but passes under 1.06 to -confirm this. - -Simplified parser regular expressions by using non-greedy matching. - -Added documentation for *_file() functions. -Corrected documentation to reflect the fact that template code is not compiled with "use safe" in effect by default, but that this might change in the future. - -Released as Text-MicroMason-1.06.tar.gz. - -=back - -=head2 Version 1.05 - -=over 4 - -=item 2003-08-11 - -Adjusted regular expression based on parsing problems reported by Philip King and Daniel J. Wright, related to newlines and EOF. Added regression tests that fail under 1.04 but pass under 1.05 to ensure these features keep working as expected. - -Added non-printing-character escaping to parser failure and debugging messages to better track future reports of whitespace-related bugs. - -Moved tests from test.pl into t/ subdirectory. - -Added experimental suppport for file code cache in compile_file_codecache. - -Released as Text-MicroMason-1.05.tar.gz. - -=back - -=head2 Version 1.04 - -=over 4 - -=item 2002-06-23 - -Adjusted regular expression based on parsing problems reported by Mark Hampton. - -Added file-include support with <& ... &> syntax. - -Documentation tweaks. Adjusted version number to simpler 0.00 format. -Released as Text-MicroMason-1.04.tar.gz. - -=item 2002-01-14 - -Documentation tweaks based on feedback from Pascal Barbedor. Updated author's contact information. - -=back - -=head2 Version 1.0.3 - -=over 4 - -=item 2001-07-01 - -Renamed from HTML::MicroMason to Text::MicroMason. Documentation tweaks. Released as Text-MicroMason-1.0.3.tar.gz. - -=back - -=head2 Version 1.0.2 - -=over 4 - -=item 2001-04-10 - -Munged interface for clarity. Added Safe support. -Adjusted docs to reflect feedback from mason-users. -Released as HTML-MicroMason-1.0.2.tar.gz. - -=back - -=head2 Version 1.0.1 - -=over 4 - -=item 2001-03-28 - -Parser tweakage; additional documentation. -Added Exporter support. -Released as HTML-MicroMason-1.0.1.tar.gz. - -=item 2001-03-26 - -Added try_interpret; documented error messages. - -=back - -=head2 Version 1.0.0 - -=over 4 - -=item 2001-03-23 - -Extended documentation; added makefile, test script. -Renamed accumulator to $OUT to match Text::Template. -Released as HTML-MicroMason-1.0.0.tar.gz. - -=item 2001-03-22 - -Created. - -=back - - -=head1 SEE ALSO - -For distribution, installation, support, copyright and license -information, see L. - -=cut diff -Nru libtext-micromason-perl-2.13/MicroMason/Docs/ReadMe.pod libtext-micromason-perl-2.16/MicroMason/Docs/ReadMe.pod --- libtext-micromason-perl-2.13/MicroMason/Docs/ReadMe.pod 2011-01-13 17:54:04.000000000 +0000 +++ libtext-micromason-perl-2.16/MicroMason/Docs/ReadMe.pod 1970-01-01 00:00:00.000000000 +0000 @@ -1,205 +0,0 @@ -=head1 NAME - -Text::MicroMason::Docs::ReadMe - About the MicroMason Distribution - -=head1 MOTIVATION - -The HTML::Mason module provides a useful syntax for dynamic template -interpretation (sometimes called embedded scripting): plain text (or -HTML) containing occasional chunks of Perl code whose results are -interpolated into the text when the template is "executed." - -However, HTML::Mason also provides a full-featured web application -framework with numerous other functions, and there are times in which -I'd like to use the templating capability without configuring a full -Mason installation. - -Thus, the Text::MicroMason module was born: it supports the core aspects -of the HTML::Mason syntax ("<%...%>" expressions, "%...\n" lines and -"<%perl>..." blocks, "<& file &>" includes, "%ARGS" and -"$_out->()"), and omits the features that are web specific (like -autohandlers) or are less widely used (like "<%method>" blocks). - -You may well be thinking "yet another dynamic templating module? -Sheesh!" And you'd have a good point. There certainly are a wide variety -of templating toolkits on CPAN already. (For a brief list see -L.) - -Nonetheless, I think this module occupies a useful niche: it provides a -reasonable subset of HTML::Mason syntax in a very light-weight fashion. -In comparison to the other modules listed, MicroMason aims to be fairly -lightweight, using one eval per parse, converting the template to a -compiled subroutine reference, and requiring less than five hundred -lines of Perl code. - -Although it notoriously difficult to fairly benchmark competing template -frameworks, at least some anecdotal evidence indicates that this module -performs reasonably well. - http://use.perl.org/~hctif/journal/25211 - http://www.gtchat.de/templateengines/templateengines_en.html - -It is also highly modular, allowing users to select and enable the -combination of features they desire. Automatic caching, safe -compartments, post-processing and other features are available as mixin -classes that are loaded on demand. - -I've recently added mixin classes that emulate the template syntax used -by Apache::ASP, Embperl, HTML::Template, PLP, Text::Template, and -Text::QuickTemplate. - - -=head1 DISTRIBUTION STATUS - -This is version 2.13 of Text::MicroMason. - -If you encounter any problems, please inform the current maintainer and -I'll endeavor to patch them promptly. - -This module's CPAN registration should read: - - Name DSLIP Description - -------------- ----- --------------------------------------------- - Text:: Group 11: Text Processing - ::MicroMason Rdpfp Simplified HTML::Mason Templating - -Please see the CPAN Testers report for a sample of systems this module -has been tested successfully on: - - http://testers.cpan.org/show/Text-MicroMason.html - -=head1 PREREQUISITES - -The required version of perl has been increased to 5.6 as of version -1.993_01. It should work with on any standard platform which runs Perl. - -Although almost all currently existing features work on versions of Perl -reaching back to 5.0, it will benefit Text::MicroMason in the long run -if supporting legacy versions of Perl was not necessary. Please contact -the new maintainer to gripe, if you absolutely need Text::MicroMason on -an older version of Perl. - -There is one pre-requisite module not included with the core -distribution which must be installed from CPAN: -L. - -If you want to use the Text::Template compatibility mode, you will also -need to install L. - -Various other mixins included in MicroMason require other modules in -order to be useful, but MicroMason installs and tests without them. (I -should be more specific here in the future.) - -=head1 INSTALLATION - -You should be able to install this module using the CPAN shell interface: - - perl -MCPAN -e 'install Text::MicroMason' - -Alternately, you may retrieve this package from CPAN -(C). - -After downloading the distribution, follow the normal procedure to -unpack and install it, using the commands shown below or their local -equivalents on your system: - - tar xzf Text-MicroMason-*.tar.gz - cd Text-MicroMason-* - perl Makefile.PL - make test && sudo make install - - -=head1 SUPPORT - -If you have questions or feedback about this module, please feel free to -contact the maintainer or original author at the e-mail address listed -below. Although there is no formal support program, I do attempt to -answer email promptly. - -I would be particularly interested in any suggestions towards -improving the documentation, correcting any Perl-version or platform -dependencies, as well as general feedback and suggested additions. - -Bug reports that contain a failing test case are greatly appreciated, -and suggested patches will be promptly considered for inclusion in -future releases. - -You can report bugs via the CPAN web tracking system, or send mail -to C, replacing C<#> with C<@>. - - http://rt.cpan.org/NoAuth/Bugs.html?Dist=Text-MicroMason - - -=head1 COMMUNITY - -If you've found this module useful or have feedback about your -experience with it, consider sharing your opinion with other Perl users -by posting your comment to CPAN's ratings system. - - http://cpanratings.perl.org/rate/?distribution=Text-MicroMason - -For more general discussion, you may wish to post a message on the -CPAN::Forum, on PerlMonks, or on the comp.lang.perl.modules newsgroup. -These are not all monitored by the current maintainer, so if you want a -response, please contact me directly. - - http://www.cpanforum.com/dist/Text-MicroMason - http://perlmonks.org/?node=Seekers%20of%20Perl%20Wisdom - http://groups.google.com/groups?group=comp.lang.perl.modules - - -=head1 THANKS - -My sincere thanks to the following people for their feedback and -contributions: - - Pascal Barbedor - Mark Hampton - Philip King - Daniel J. Wright - William Kern - Tommi Maekitalo - Alan Ferrency - Jonas Alves - Alexander - Matthew Simon Cavalletto - Jon Warbrick - Frank Wiegand - Mike Kelly - Niko Tyni - Ansgar Burchardt - vshih - -=head1 SOURCE MATERIAL - -Portions based on HTML::Mason by Jonathan Swartz. - -Portions based on Embperl by Gerald Richter. - -Portions based on HTML::Template by Sam Tregar. - -Portions based on PLP by Juerd Waalboer. - -Portions based on Text::Template by Mark Jason Dominus. - -Portions based on Text::QuickTemplate by Eric J. Roode. - - -=head1 AUTHOR - -Developed by Matthew Simon Cavalletto at Evolution Softworks. You may -contact the author directly at C or -C, replacing C<#> with C<@>. - -Currently maintained by Alan Ferrency at pair -Networks, Inc. - -=head1 LICENSE - -Copyright 2002, 2003, 2004, 2005 Matthew Simon Cavalletto. - -Portions copyright 2001 Evolution Online Systems, Inc. - -You may use, modify, and distribute this software under the same -terms as Perl. - -=cut diff -Nru libtext-micromason-perl-2.13/MicroMason/Docs/Related.pod libtext-micromason-perl-2.16/MicroMason/Docs/Related.pod --- libtext-micromason-perl-2.13/MicroMason/Docs/Related.pod 2007-01-29 19:47:01.000000000 +0000 +++ libtext-micromason-perl-2.16/MicroMason/Docs/Related.pod 1970-01-01 00:00:00.000000000 +0000 @@ -1,117 +0,0 @@ -=head1 NAME - -Text::MicroMason::Docs::Related - A Brief Survey of Templating Modules - -=head1 RELATED MODULES - -Text::MicroMason is just one of dozens (or hundreds) of templating -distributions on CPAN. - -This document mentions a few related modules and includes a brief discussion of some similarities and differences among them. - - -=head1 OTHER COMPARISONS - -For a more authoritative discussion, see Perrin Harkins' classic article at L. - -For reference, here's a slightly mangled version of the comparison matrix -at the conclusion of that article: - - Scope Style Parsing Language - HTML::Mason Framework Callback Compiled Perl - HTML::Embperl Framework Callback Compiled Perl - Apache::ASP Framework Callback Compiled Perl and XSL - AxKit Framework Pipeline Compiled or Perl, XSL and - Cached Parse Mini-Languages - SSI Templates Callback Repeated Parse Mini-Language - Template Tlkit Templates Pipeline Compiled Mini-Language - HTML::Template Templates Pipeline Cached Parse Mini-Language - Text::Template Templates Pipeline Compiled Perl - - - -=head1 POINTS OF COMPARISON - -There are serveral ways we can differentiate between templating systems: - -=over 4 - -=item Perl Syntax vs. Little Languages - -Some templating systems use Perl syntax for both interpolated expressions -and flow control, including L, -L, and L. - -Others use "little languages", including L and L. - -=item Just Templating vs. Web Application Framework - -Some templating systems just provide functions to fill in templates, like L. - -Others are part of full-blown web application frameworks like -L, ePerl, L, -and L. - -=item Modular vs Monolithic - -Some templating systems are not particularly configurable or extensible. - -Others support various kinds of extensions, including L, L and L. - -=item Interpreted vs. Compiled - -Some templating systems repeatedly parse the template from scratch every time it is used. - -Others parse the template into an intermediate data structure and then iterate over that each time the template is used. - -Others convert the template into equivalent Perl source code which can be compiled into a directly-executable subroutine and used repeatedly, including L and L. - -=back - - -=head1 EMULATED MODULES - -=head2 Apache::ASP - -For an emulation for L, -see L. - -=head2 Embperl - -For an emulation for L, -see L. - -=head2 HTML::Template - -For an emulation for L, -see L. - -See also L. - -=head2 HTML::Mason - -For an emulation for L, -see L. - -(If you've already got HTML::Mason installed, configured, and loaded -into your process, you're probably better off using it rather than -this package. HTML::Mason's C<$interp-Emake_component()> method -allows you to parse a text string without saving it to disk first.) - -=head2 PLP - -For an emulation for L, -see L. - -=head2 Text::Template - -For an emulation for L, -see L. - - -=head1 SEE ALSO - -For distribution, installation, support, copyright and license -information, see L. - -=cut diff -Nru libtext-micromason-perl-2.13/MicroMason/Docs/ToDo.pod libtext-micromason-perl-2.16/MicroMason/Docs/ToDo.pod --- libtext-micromason-perl-2.13/MicroMason/Docs/ToDo.pod 2009-11-12 20:54:48.000000000 +0000 +++ libtext-micromason-perl-2.16/MicroMason/Docs/ToDo.pod 1970-01-01 00:00:00.000000000 +0000 @@ -1,327 +0,0 @@ -=head1 NAME - -Text::MicroMason::Docs::ToDo - Development Plans for the MicroMason Distribution - -=head1 DESCRIPTION - -This document outlines various development plans and ideas for Text::MicroMason. - -The TO DO section describes plans which are likely to happen. - -The WISH LIST section describes a variety of ideas which are likely to -be accepted as patches, but which will most likely not be developed with -any priority any time soon. - -If you are interested in a specific feature, whether it is listed here -or not, please contact the current maintainer as described in -L. - -=head1 TO DO - -=head2 Fix all known bugs - -So, please report them. - -=head2 Distribution - -=over 4 - -=item * - -Move the module files into a lib/ directory as expected in modern CPAN -distributions. - -=back - -=head2 New Mixins - -=over 4 - -=item * - -AutoLoad mixin. Using this mixin adds an AUTOLOADER to the mason object, -which interprets all unknown method calls as template names. - -=back - -=head2 New Features - -=over 4 - -=item * - -Support the previously supported but now unsupported -compile(lines => ...) source type. This was documented but non- -functional, and so the pod was removed. - -=back - -=head1 WISH LIST - -=head2 Distribution - -=over 4 - -=item * - -Use Module::Build instead of ExtUtils::MakeMaker. - -=item * - -Consider reorganizing the Text::MicroMason::* modules into a number of -subdirectories. There are currently over two dozen of them, and it's -bound to get worse as time goes on. Perhaps separate them by intent: -Cache::*, Errors::*, Syntax::*, Features::*, etc. - -=item * - -Finish and test the ParseInfo module to facilitate template -introspection. - -=item * - -Rewrite the MOTIVATION section of the ReadMe pod to reflect the shift -from an HTML::Mason clone to a more general templating engine that has -at least partial compatibilty with quite a few other modules. - -=back - -=head2 Interfaces - -=over 4 - -=item * - -Test and improve the ApacheHandler interface. - -Map user-friendly Apache config directives to mixin and initialization -options. Review HTML::Mason::ApacheHandler, HTML::Mason::Params, and -HTML::Mason::Admin. - -Headers need to be constructed as per -http://modperlbook.org/html/ch06_11.html and not sent until our first -print statement; see PLP::Tie::Print. - -=item * - -Review integration with Inline::Mason. Facilitate use of mixins so this -can also do inline ServerPages and other syntaxes. - -=back - -=head2 Core Syntax - -=over 4 - -=item * - -Determine how to best stack lex_token() method so that multiple syntax -plugins can work together. - -=item * - -Extract named blocks parsing from HTMLMason to form a separate mixin. - -=item * - -Extract variable interpolation syntax to allow it to be stacked with -other lexers. - -=back - -=head2 Syntax Emulations - -=over 4 - -=item * - -Add TemplateToolkit module with support for the basic TT syntax. The key -syntax definition is in Parser.yp, which is used to build -Template::Grammar. (L) The Template::Stash dot notation can be handled -by Data::DRef. - -=item * - -Extend HTMLTemplate module with a hash mapping options that could be -passed to HTML::Template's new() into the equivalent behavior, or croak -if they're unsupported. - -=item * - -Consider extending Embperl module to support dynamic HTML tags. - -=item * - -Consider extending ServerPages module to support dynamic XML tags. - -=back - -=head2 Template Sources - -=over 4 - -=item * - -Provide a mixin to search for all files matching a given regex to -facilitate tree searches and cache pre-fetching. - -=item * - -Ensure template inclusion is always handled correctly. Possibly provide -the current template's location in %ENV. - -=item * - -Add a DHandlers mixin that supports default files. On file requests, if -file not found, look for default file. (Attribute dhandler_name controls -name of file to look for.) - -=item * - -Add an AutoHandlers mixin that supports wrapper files. On file -requests, also search hierarchy for autohandler files. (Attribute -autohandler_name controls name of file to look for.) Build a stack of -autohandlers and store it in a mason attribute. Support ->call_next() -to work through the chain. - -(I've also gotten a user request for "decorator files" which turns out -to be roughly equivalent to the AutoHandler system.) - -=item * - -Add a TemplateDB mixin which shows how to retrieve templates from a -database table. Provides a read_db() method. Accept a DBI connection as -an attribute -- or a reference to a function which will return rows from -a sql statement. - -Consider how to support caching for templates drawn from a TemplateDB. -Perhaps in addition to the source_file there can be some kind of opaque -cache key returned by the prepare method? - -Maybe cache values for db templates can be abstracted into closures -which are run to retrieve the cached value. - -=back - -=head2 Caching - -=over 4 - -=item * - -Add a DataCache mixin that provides a pre-configured cache object for -use within template code. Requires cache() method and configuration -attributes. Cache namespace should be based on source file name or -arbitrary instance for text compilation. - -Alan says: I believe this is intended for use to cache contextual data -across template runs? Is this intended to be persistent across multiple -templates (in memory/singleton), or across multiple process invocations -(in a file)? I use mod_perl, and this sounds at best not useful and at -worst, dangerous. - -=item * - -Add an InterpretCache mixin that allows caching of the parsed and -assembled Perl code for a template file, akin to Mason's var/obj/ - directory. (This would also allow visual review when debugging the -converted code.) - -=item * - -The InterpretCache and CompileCache benefit from using a cache object -that checks the keys as filenames to see if the source file has been -updated and forces cache expiration; find a way to extract and reuse -this capability from Text::MicroMason::Cache::File. - -=back - -=head2 Blessing Templates - -=over 4 - -=item * - -Add a BlessSub mixin that blesses the compiled subroutine. This would -let us add support for template-specific behaviors and attributes. -Override eval_sub() to bless sub before returning. Attribute -bless_sub controls initializer arguments passed to BlessedSub class. -BlessedSub class is base class for blessed template objects. Provides -execute() method. - -BlessedSub classes may need their own mixin factory... To avoid having -to define separate mixins for both packages, perhaps the methods should -be delegated from the coderef to the Mason instance? (This becomes -particularly attractive if each sub is automatically getting its own -cloned mason instance anyway.) - - -=item * - -Add an AttrBlock mixin, using BlessedSub. Override lexer methods to -parse <%attr> blocks. Stores attribute definitions in a %once block. -Provides attr() method. - -=item * - -Add a MethodBlock mixin, using BlessedSub. Override lexer methods to -parse <%method> blocks. Stores method definitions in a %once block. -Hooks AUTOLOAD to catch method calls. - -=back - -=head2 Internals - -=over 4 - -=item * - -Consider moving output_sub to a new OutputHandle mixin which accepts a -handle as an attribute, then prints output to it rather than returning -the results as a string. - -=item * - -Clarify and document the clone-on-change behavior of prepare() and its -effects when making changes to a mason object after compiling a -template. Perhaps we should ensure that we clone every time, or at least -every time that it matters? - -=back - -=head2 Testing - -=over 4 - -=item * - -Set up a benchmarking tool to compare subclasses with other templating -solutions. Take an example from ApacheBench but execute templates -directly rather than via Apache. Store the expected output in a text -file for comparison. - -Other links to consider when benchmarking: - - http://www.chamas.com/bench/ - http://use.perl.org/~hctif/journal/25211 - http://www.gtchat.de/templateengines/templateengines_en.html - -=item * - -Set up a compliance test tool that compares the output of the various -MicroMason mixins with the other modules they emulate. This should be -able to use many of the same data files as the benchmarking tool. - -=item * - -Add more templates to samples directory and test them. - -=back - -=head1 SEE ALSO - -For distribution, installation, support, copyright and license -information, see L. - -=cut diff -Nru libtext-micromason-perl-2.13/MicroMason/DoubleQuote.pm libtext-micromason-perl-2.16/MicroMason/DoubleQuote.pm --- libtext-micromason-perl-2.13/MicroMason/DoubleQuote.pm 2007-01-29 19:47:01.000000000 +0000 +++ libtext-micromason-perl-2.16/MicroMason/DoubleQuote.pm 1970-01-01 00:00:00.000000000 +0000 @@ -1,58 +0,0 @@ -package Text::MicroMason::DoubleQuote; - -use strict; - -###################################################################### - -# ( $type, $value ) = $mason->lex_token(); -sub lex_token { - / (.*) /xcogs ? ( expr => do { my $x = $1; $x =~ s/\|/\\|/g; "qq|$x|" } ) : () -} - -###################################################################### - -1; - -__END__ - -###################################################################### - -=head1 NAME - -Text::MicroMason::DoubleQuote - Minimalist Interpolation Engine - - -=head1 SYNOPSIS - -Instead of using this class directly, pass its name to be mixed in: - - use Text::MicroMason; - my $mason = Text::MicroMason::Base->new( -DoubleQuote ); - -Templates can be written using Perl's double-quote interpolation syntax: - - $coderef = $mason->compile( text => 'Hello $ARGS{name}!' ); - print $coderef->( name => 'World' ); - - -=head1 DESCRIPTION - -Text::MicroMason::DoubleQuote uses Perl's double-quoting interpolation as a minimalist syntax for templating. - -Of course you don't need this module for simple cases of interpolation, but if you're already using the MicroMason framework to process template files from disk, this module should allow you to make your simplest templates run even faster. - -To embed values other than simple scalars in a double-quoted expression you can use the ${ expr } syntax. For example, you can interpolate a function call with C<"${ \( time() ) }"> or C<"@{[mysub(1,2,3)]}">. As noted in L, "this is fraught with quoting and readability problems, but it is possible." In particular, this can quickly become a mess once you start adding loops or conditionals. If you do find yourself making use of this feature, please consider switching to one of the more powerful template syntaxes like L. - - -=head1 SEE ALSO - -To refer to arguments as $name rather than as $ARGS{name}, see L. - -For an overview of this distribution, see L. - -This is a subclass intended for use with L. - -For distribution, installation, support, copyright and license -information, see L. - -=cut diff -Nru libtext-micromason-perl-2.13/MicroMason/Embperl.pm libtext-micromason-perl-2.16/MicroMason/Embperl.pm --- libtext-micromason-perl-2.13/MicroMason/Embperl.pm 2007-01-29 19:47:01.000000000 +0000 +++ libtext-micromason-perl-2.16/MicroMason/Embperl.pm 1970-01-01 00:00:00.000000000 +0000 @@ -1,182 +0,0 @@ -package Text::MicroMason::Embperl; - -use strict; -use Carp; - -use Safe; - -###################################################################### - -my %block_types = ( - '-' => 'perl', # [- perl statements -] - '+' => 'expr', # [+ perl expression +] - '!' => 'once', # [! perl statements !] - '$' => 'ep_meta', # [$ command args $] -); - -sub lex_token { - # Blocks in [-/+/! ... -/+/!] tags. - /\G \[ (\-|\+|\!) \s* (.*?) \s* \1 \] /gcxs ? ( $block_types{$1} => $2 ) : - - # Blocks in [$ command ... $] tags. - /\G \[ \$ \s* (\S+)\s*(.*?) \s* \$ \] /gcxs ? ( "ep_$1" => $2 ) : - - # Things that don't match the above - /\G ( (?: [^\[] | \[(?![\-\+\!\$]) )+ ) /gcxs ? ( 'text' => $1 ) : - - () -} - -###################################################################### - -sub assembler_rules { - my $self = shift; - $self->NEXT('assembler_rules', @_), - ep_if_token => "perl if ( TOKEN ) {", - ep_elsif_token => "perl } elsif ( TOKEN ) {", - ep_else_token => "perl } else {", - ep_endif_token => "perl }", - ep_while_token => "perl while ( TOKEN ) {", - ep_endwhile_token => "perl }", - ep_foreach_token => "perl foreach TOKEN {", - ep_endforeach_token => "perl }", - ep_do_token => "perl do {", - ep_until_token => "perl } until ( TOKEN );", - ep_var_token => "perl use strict; use vars qw( TOKEN );", -} - -###################################################################### - -1; - -__END__ - -###################################################################### - -=head1 NAME - -Text::MicroMason::Embperl - Alternate Syntax like Embperl Templates - - -=head1 SYNOPSIS - -Instead of using this class directly, pass its name to be mixed in: - - use Text::MicroMason; - my $mason = Text::MicroMason::Base->new( -Embperl ); - -Use the standard compile and execute methods to parse and evalute templates: - - print $mason->compile( text=>$template )->( @%args ); - print $mason->execute( text=>$template, @args ); - -Embperl syntax provides several ways to mix Perl into a text template: - - [- my $name = $ARGS{name}; -] - [$ if $name eq 'Dave' $] - I'm sorry [+ $name +], I'm afraid I can't do that right now. - [$ else $] - [- - my $hour = (localtime)[2]; - my $daypart = ( $hour > 11 ) ? 'afternoon' : 'morning'; - -] - Good [+ $daypart +], [+ $name +]! - [$ endif $] - - -=head1 DESCRIPTION - -This subclass replaces MicroMason's normal lexer with one that supports a syntax similar to Embperl. - -=head2 Compatibility with Embperl - -Embperl is a full-featured application server toolkit with many fatures, of which only the templating functionality is emulated. - -This is not a drop-in replacement for Embperl, as the implementation is quite different, but it should be able to process some existing templates without major changes. - -The following features of EmbPerl syntax are supported: - -=over 4 - -=item * - -Square-bracket markup tags - -=back - -The following syntax features of are B supported: - -=over 4 - -=item * - -Dynamic HTML tags - -=back - -=head2 Template Syntax - -The following elements are recognized by the Embperl lexer: - -=over 4 - -=item * - -[- perl statements -] - -Arbitrary Perl code to be executed at this point in the template. - -=item * - -[+ perl expression +] - -A Perl expression to be evaluated and included in the output. - -=item * - -[! perl statements !] - -Arbitrary Perl code to be executed once when the template is compiled. - -=item * - -[$ I ... $] - -Supported command names are: if, elsif, else, endif, foreach, endforeach, while, endwhile, do, until, var. - -=back - -=head2 Private Methods - -=over 4 - -=item lex_token - - ( $type, $value ) = $mason->lex_token(); - -Lexer for [. ... .] tags. - -Attempts to parse a token from the template text stored in the global $_ and returns a token type and value. Returns an empty list if unable to parse further due to an error. - -=item assembler_rules() - -Adds mappings from command names used in [$ ... $] tokens to the equivalent -Perl syntax. - - %syntax_rules = $mason->assembler_rules(); - -=back - -=cut - - -=head1 SEE ALSO - -For an overview of this templating framework, see L. - -This is a mixin class intended for use with L. - -For distribution, installation, support, copyright and license -information, see L. - -=cut diff -Nru libtext-micromason-perl-2.13/MicroMason/ExecuteCache.pm libtext-micromason-perl-2.16/MicroMason/ExecuteCache.pm --- libtext-micromason-perl-2.13/MicroMason/ExecuteCache.pm 2007-01-29 20:10:22.000000000 +0000 +++ libtext-micromason-perl-2.16/MicroMason/ExecuteCache.pm 1970-01-01 00:00:00.000000000 +0000 @@ -1,111 +0,0 @@ -package Text::MicroMason::ExecuteCache; - -use strict; -use Carp; - -require Text::MicroMason::Base; -require Text::MicroMason::Cache::Simple; - -###################################################################### - -# $code_ref = compile( text => $template ); -sub compile { - my $self = shift; - - my $code_ref = $self->NEXT('compile', @_); - - my $cache = $self->_execute_cache() - or return $code_ref; - - sub { - my $key = join("|", $code_ref, @_); - $cache->get( $key ) or $cache->set( $key, $code_ref->( @_ ) ); - } -} - -sub _execute_cache { - my $self = shift; - - $self->{execute_cache} ||= Text::MicroMason::Cache::Simple->new(); -} - -###################################################################### - -1; - -__END__ - -=head1 NAME - -Text::MicroMason::ExecuteCache - Use a Cache for Template Results - - -=head1 SYNOPSIS - -Instead of using this class directly, pass its name to be mixed in: - - use Text::MicroMason; - my $mason = Text::MicroMason->new( -ExecuteCache ); - -Use the standard compile method to parse a template into a subroutine: - - my $subref = $mason->compile( text=>$template ); - print $subref->( 'name'=>'Dave' ); - -The template does not have to be interpreted the second time because -the results are cached: - - print $subref->( 'name'=>'Dave' ); # fast second time - -When run with different arguments, the template is re-interpreted -and the results stored: - - print $subref->( 'name'=>'Bob' ); # first time for Bob - - print $subref->( 'name'=>'Bob' ); # fast second time for Bob - - -=head1 DESCRIPTION - -Caches the output of templates. - -Note that you should not use this feature if your template code interacts with any external state, such as making changes to an external data source or obtaining values that will change in the future. (However, you can still use the caching provided by L.) - - -=head2 Public Methods - -=over 4 - -=item compile() - -Wraps each template that is compiled into a Perl subroutine in a memoizing closure. - -=back - -=head2 Supported Attributes - -=over 4 - -=item execute_cache - -Defaults to an instance of Text::MicroMason::Cache::Simple. - -=back - -This module uses a simple cache interface that is widely supported: the -only methods required are C and C. You can -use the simple cache classes provided in the Text::MicroMason::Cache:: -namespace, or select other caching modules on CPAN that support the -interface described in L. - - -=head1 SEE ALSO - -For an overview of this templating framework, see L. - -This is a mixin class intended for use with L. - -For distribution, installation, support, copyright and license -information, see L. - -=cut diff -Nru libtext-micromason-perl-2.13/MicroMason/Filters.pm libtext-micromason-perl-2.16/MicroMason/Filters.pm --- libtext-micromason-perl-2.13/MicroMason/Filters.pm 2008-01-02 22:21:44.000000000 +0000 +++ libtext-micromason-perl-2.16/MicroMason/Filters.pm 1970-01-01 00:00:00.000000000 +0000 @@ -1,235 +0,0 @@ -package Text::MicroMason::Filters; - -use strict; -use Carp; - -use Safe; - -###################################################################### - -# Output filtering -use vars qw( %Filters ); -$Filters{p} = \&Text::MicroMason::Base::_printable; - -$Filters{h} = eval { - require HTML::Entities; sub { HTML::Entities::encode( $_[0], q[<>&'"] ) } - } || eval { require CGI; \&CGI::escapeHTML }; - -$Filters{u} = eval { require URI::Escape; \&URI::Escape::uri_escape }; - -sub defaults { - (shift)->NEXT('defaults'), filters => \%Filters, default_filters => '' -} - -###################################################################### - -# $perl_code = $mason->assemble( @tokens ); -sub assemble { - my $self = shift; - my @tokens = @_; - # warn "Filter assemble"; - foreach my $position ( 0 .. int( $#tokens / 2 ) ) { - if ( $tokens[$position * 2] eq 'expr' ) { - my $token = $tokens[$position * 2 + 1]; - my $filt_flags = ($token =~ s/(?parse_filters($self->{default_filters}, $filt_flags)) { - $token = '$m->filter( ' . join(', ', map "'$_'", @filters ) . ', ' . - 'join "", do { ' . $token . '} )'; - } - $tokens[$position * 2 + 1] = $token; - } - } - $self->NEXT('assemble', @tokens ); -} - -# @flags = $mason->parse_filters( @filter_strings ); -sub parse_filters { - my $self = shift; - - my $no_ns; - my $short = join '', 'n', grep { length($_) == 1 } keys %{ $self->{filters} }; - reverse grep { not $no_ns ||= /^n$/ } reverse - map { /^[$short]{2,5}$/ ? split('') : split(/[\s\,]+/) } @_; -} - -###################################################################### - -# %functions = $mason->filter_functions(); -# $function = $mason->filter_functions( $flag ); -# @functions = $mason->filter_functions( \@flags ); -# $mason->filter_functions( $flag => $function, ... ); -sub filter_functions { - my $self = shift; - my $filters = ( ref $self ) ? $self->{filters} : \%Filters; - if ( scalar @_ == 0 ) { - %$filters - } elsif ( scalar @_ == 1 ) { - my $key = shift; - if ( ! ref $key ) { - $filters->{ $key } - } else { - @{ $filters }{ @$key } - } - } else { - %$filters = ( %$filters, @_ ); - } -} - -# @functions = $mason->get_filter_functions( @flags_or_functions ); -sub get_filter_functions { - my $self = shift; - - map { - ( ref $_ eq 'CODE' ) ? $_ : $self->{filters}{ $_ } - or $self->croak_msg("No definition for a filter named '$_'" ); - } @_ -} - -# $result = $mason->filter( @filters, $content ); -sub filter { - my $self = shift; - local $_ = pop; - - foreach my $function ( $self->get_filter_functions( @_ ) ) { - $_ = &$function($_) - } - $_ -} - -###################################################################### - -1; - -__END__ - -###################################################################### - -=head1 NAME - -Text::MicroMason::Filters - Add Output Filters like "|h" and "|u" - - -=head1 SYNOPSIS - -Instead of using this class directly, pass its name to be mixed in: - - use Text::MicroMason; - my $mason = Text::MicroMason->new( -Filters ); - -Use the standard compile and execute methods to parse and evalute templates: - - print $mason->compile( text=>$template )->( @%args ); - print $mason->execute( text=>$template, @args ); - -Enables filtering of template expressions using HTML::Mason's conventions: - - <%args> $name - Welcome, <% $name |h %>! - Click for More - -You can set a default filter and override it with the "n" flag: - - my $mason = Text::MicroMason->new( -Filters, default_filters => 'h' ); - - <%args> $name - Welcome, <% $name %>! - Click for More - -You can define additional filters and stack them: - - my $mason = Text::MicroMason->new( -Filters ); - $mason->filter_functions( myfilter => \&function ); - $mason->filter_functions( uc => sub { return uc( shift ) } ); - - <%args> $name - Welcome, <% $name |uc,myfilter %>! - - -=head1 DESCRIPTION - -This module enables the filtering of expressions before they are output, using HTML::Mason's "|hun" syntax. - -If you have HTML::Entities and URI::Escape available they are loaded to provide the default "h" and "u" filters. If those modules can not be loaded, no error message is produced but any subsequent use of them will fail. - -Attempted use of an unknown filter name will croak with a message stating "No definition for a filter named 'h'". - -=head2 Public Methods - -=over 4 - -=item filter_functions - -Gets and sets values from the hash mapping filter flags to functions. - -If called with no arguments, returns a hash of all available filter flags and functions: - - %functions = $mason->filter_functions(); - -If called with a filter flag returns the associated function, or if provided with a reference to an array of flag names returns a list of the functions: - - $function = $mason->filter_functions( $flag ); - @functions = $mason->filter_functions( \@flags ); - -If called with one or more pairs of filter flags and associated functions, adds them to the hash. (Any filter that might have existed with the same flag name is overwritten.) - - $mason->filter_functions( $flag => $function, ... ); - -=back - -=head2 Supported Attributes - -=over 4 - -=item default_filters - -Optional comma-separated string of filter flags to be applied to all output expressions unless overridden by the "n" flag. - -=back - -=head2 Private Methods - -=over 4 - -=item assemble() - -This method goes through the lexed template tokens looking for uses of filter flags, which it then rewrites as appropriate method calls before passing the tokens on to the superclass. - -=item parse_filters - -Parses one or more strings containing any number of filter flags and returns a list of flags to be used. - - @flags = $mason->parse_filters( @filter_strings ); - -Flags should be separated by commas, except that the commas may be omitted when using a combination of single-letter flags. Flags are applied from left to right. Any use of the "n" flag wipes out all flags defined to the left of it. - -=item get_filter_functions - -Accepts filter flags or function references and returns a list of the corresponding functions. Dies if an unknown filter flag is used. - - @functions = $mason->get_filter_functions( @flags_or_functions ); - -=item filter - -Applies one or more filters to the provided content string. - - $result = $mason->filter( @flags_or_functions, $content ); - -=back - - -=head1 SEE ALSO - -For an overview of this templating framework, see L. - -This is a mixin class intended for use with L. - -For distribution, installation, support, copyright and license -information, see L. - -=cut - diff -Nru libtext-micromason-perl-2.13/MicroMason/Functions.pm libtext-micromason-perl-2.16/MicroMason/Functions.pm --- libtext-micromason-perl-2.13/MicroMason/Functions.pm 2007-01-29 19:47:01.000000000 +0000 +++ libtext-micromason-perl-2.16/MicroMason/Functions.pm 1970-01-01 00:00:00.000000000 +0000 @@ -1,192 +0,0 @@ -package Text::MicroMason::Functions; - -use strict; -use vars qw( @ISA @EXPORT_OK ); - -use Exporter; -@ISA = 'Exporter'; - -@EXPORT_OK = ( - 'compile', # $code_ref = compile( $mason_text ); - 'compile_file', # $code_ref = compile_file( $filename ); - 'safe_compile', # $code_ref = safe_compile( $mason_text ); - 'safe_compile_file', # $code_ref = safe_compile_file( $filename ); - 'execute', # $result = execute( $filename, %args ); - 'execute_file', # $result = execute_file( $filename, %args ); - 'safe_execute', # $result = safe_execute( $mason_text, %args ); - 'safe_execute_file', # $result = safe_execute_file( $filename, %args ); -); - -push @EXPORT_OK, map "try_$_", @EXPORT_OK; - -###################################################################### - -sub Mason { - () -} - -sub SafeMason { - ( -Safe, (ref($_[0]) =~ /Safe/) ? (safe => shift) : () ) -} - -sub CatchingMason { - ( -CatchErrors ); -} - -sub SafeCatchingMason { - ( -CatchErrors, -Safe, (ref($_[0]) =~ /Safe/) ? (safe => shift) : () ) -} - -foreach my $sub (@EXPORT_OK ) { - no strict 'refs'; - my $method = $sub; - my $source = ( $method =~ s/_file// ) ? 'file' : 'text'; - - my $mason = "Mason"; - $mason = "Catching$mason" if ( $method =~ s/try_// ); - $mason = "Safe$mason" if ( $method =~ s/safe_// ); - *{__PACKAGE__."::$sub"} = sub { - Text::MicroMason->new( &$mason ) - ->$method( (ref($_[0]) eq 'CODE') ? 'code' : $source => @_ ) - } -} - -###################################################################### - -1; - -__END__ - -###################################################################### - -=head1 NAME - -Text::MicroMason::Functions - Function Exporter for Simple Mason Templates - - -=head1 SYNOPSIS - -Use the execute function to parse and evalute a template: - - use Text::MicroMason::Functions qw( execute ); - print execute($template, 'name'=>'Dave'); - -Or compile it into a subroutine, and evaluate repeatedly: - - use Text::MicroMason::Functions qw( compile ); - $coderef = compile($template); - print $coderef->('name'=>'Dave'); - print $coderef->('name'=>'Bob'); - -Templates stored in files can be run directly or included in others: - - use Text::MicroMason::Functions qw( execute_file ); - print execute_file( "./greeting.msn", 'name'=>'Charles'); - -Safe usage restricts templates from accessing your files or data: - - use Text::MicroMason::Functions qw( safe_execute ); - print safe_execute( $template, 'name'=>'Bob'); - -All above functions are available in an error-catching "try_*" form: - - use Text::MicroMason::Functions qw( try_execute ); - ($result, $error) = try_execute( $template, 'name'=>'Alice'); - - -=head1 DESCRIPTION - -As an alternative to the object-oriented interface, text containing MicroMason markup code can be compiled and executed by calling the following functions. - -Please note that this interface is maintained primarily for backward compatibility with version 1 of Text::MicroMason, and it does not provide access to some of the newer features. - -Each function creates a new MicroMason object, including any necessary traits such as Safe compilation or CatchErrors for exceptions, and then passes its arguments to an appropriate method on that object. - -You may import any of these functions by including their names in your -C statement. - -=head2 Basic Invocation - -To evaluate a Mason-like template, pass it to execute(): - - $result = execute( $mason_text ); - -Alternately, you can call compile() to generate a subroutine for your template, and then run the subroutine: - - $result = compile( $mason_text )->(); - -If you will be interpreting the same template repeatedly, you can save the compiled version for faster execution: - - $sub_ref = compile( $mason_text ); - $result = $sub_ref->(); - -(Note that the $sub_ref->() syntax is unavailable in older versions of Perl; use the equivalent &$sub_ref() syntax instead.) - -=head2 Argument Passing - -You can also pass a list of key-value pairs as arguments to execute, or to the compiled subroutine: - - $result = execute( $mason_text, %args ); - - $result = $sub_ref->( %args ); - -Within the scope of your template, any arguments that were provided will be accessible in the global @_, the C<%ARGS> hash, and any variables named in an %args block. - -For example, the below calls will all return 'Foo': - - execute('<% shift(@_) %>', 'Foo'); - execute('<% $ARGS{label} %>', label=>'Foo'); - execute('<%args>$label<% $label %>', label=>'Foo'); - -=head2 Template Files - -A parallel set of functions exist to handle templates which are stored in a file: - - $template = compile_file( './report_tmpl.msn' ); - $result = $template->( %args ); - - $result = execute_file( './report_tmpl.msn', %args ); - -Template documents are just plain text files that contains the string to be parsed. The files may have any name you wish, and the .msn extension shown above is not required. - -=head2 Error Checking - -Both compilation and run-time errors in your template are handled as fatal -exceptions. The provided try_execute() and try_compile() functions use a mixin class which wraps an eval { } block around the basic execute() or compile() -methods. In a scalar context they return the result of the call, or -undef if it failed; in a list context they return the results of the call -(undef if it failed) followed by the error message (undef if it succeeded). -For example: - - ($result, $error) = try_execute( $mason_text ); - if ( ! $error ) { - print $result; - } else { - print "Unable to execute template: $error"; - } - -A matching pair of try_*_file() wrappers are available to catch run-time errors in reading a file or parsing its contents: - - ($template, $error) = try_compile_file( './report_tmpl.msn' ); - - ($result, $error) = try_execute_file( './report_tmpl.msn', %args ); - -For more information, see L. - -=head2 Safe Compartments - -If you wish to restrict the operations that a template can perform, -use the safe_compile() and safe_execute() functions, or their -try_*() wrappers. - -For more information, see L. - - -=head1 SEE ALSO - -For an overview of this templating framework, see L. - -For distribution, installation, support, copyright and license -information, see L. - -=cut diff -Nru libtext-micromason-perl-2.13/MicroMason/HasParams.pm libtext-micromason-perl-2.16/MicroMason/HasParams.pm --- libtext-micromason-perl-2.13/MicroMason/HasParams.pm 2011-01-13 17:50:54.000000000 +0000 +++ libtext-micromason-perl-2.16/MicroMason/HasParams.pm 1970-01-01 00:00:00.000000000 +0000 @@ -1,116 +0,0 @@ -package Text::MicroMason::HasParams; - -###################################################################### - -sub defaults { - (shift)->NEXT('defaults'), params => [ {} ] -} - -###################################################################### - -sub assembler_rules { - my $self = shift; - $self->NEXT('assembler_rules', @_), - init_args => 'local $m->{params} = [ ( @_ == 1 ) ? $_[0] : scalar(@_) ? { @_ } : (), $m->{params} ? @{$m->{params}} : () ];'; -} - -###################################################################### - -sub param { - my $self = shift; - - my @params = $self->{params} ? @{$self->{params}} : (); - - if ( scalar @_ == 0 ) { - return map( keys(%$_), @params ), - $self->{associate} ? $self->{associate}->param() : () - - } elsif ( scalar @_ > 1 ) { - if ( my $associate = $self->{associate} ) { - return $associate->param( @_ ); - } - $self->{params} ||= [ {} ]; - $self->{params}[0] ||= {}; - my $target = $self->{params}[0]; - if ( $self->{case_sensitive} ) { - %$target = ( %$target, @_ ); - } else { - my %hash = @_; - %$target = ( %$target, map { lc($_) => $hash{$_} } keys %hash ); - # warn "set params $self->{params}[0]: " , %{ $self->{params}[0] }; - } - - } elsif ( scalar @_ == 1 and ref( $_[0] ) ) { - push @{$self->{params}}, shift(); - - } else { - my $key = $self->{case_sensitive} ? shift : lc( shift ); - # warn "get params $key: $#params\n"; - foreach my $param ( @params ) { - # warn "get params $param: $key\n"; - my $case_key = ( exists $param->{ $key } ) ? $key : - ( ! $self->{case_sensitive} ) ? ( grep { lc eq $key } keys %$param )[0] : undef; - next unless defined $case_key; - my $value = $param->{ $case_key }; - # warn "get params $param: $key ($case_key) = $value\n"; - return( ( ref($value) eq 'ARRAY' ) ? @$value : $value ) - } - if ( my $associate = $self->{associate} ) { - my $case_key = ( $self->{case_sensitive} ) ? $key : - ( grep { lc eq $key } $associate->param() )[0]; - return $associate->param( $case_key ); - } - return; - } -} - -###################################################################### - -1; - -__END__ - -###################################################################### - -=head1 NAME - -Text::MicroMason::HasParams - mixin class intended for use with Text::MicroMason::Base - -=head1 DESCRIPTION - -This mixin class ... - -' -=head2 Public Methods - -=over 4 - -=item param() - -Gets and sets parameter arguments. Similar to the param() method provied by HTML::Template and the CGI module. - -=back - - -=head2 Private Methods - -=over 4 - -=item assembler_rules() - -Adds initialization for param() at the beginning of each subroutine to be compiled. - -=back - - -=head1 SEE ALSO - -For an overview of this templating framework, see L. - -This is a mixin class intended for use with L. - -For distribution, installation, support, copyright and license -information, see L. - -=cut - diff -Nru libtext-micromason-perl-2.13/MicroMason/HTMLMason.pm libtext-micromason-perl-2.16/MicroMason/HTMLMason.pm --- libtext-micromason-perl-2.13/MicroMason/HTMLMason.pm 2007-01-29 19:47:01.000000000 +0000 +++ libtext-micromason-perl-2.16/MicroMason/HTMLMason.pm 1970-01-01 00:00:00.000000000 +0000 @@ -1,511 +0,0 @@ -package Text::MicroMason::HTMLMason; - -use strict; - -###################################################################### - -my $re_eol = "(?:\\r\\n|\\r|\\n|\\z)"; -my $re_sol = "(?:\\A|(?<=\\r|\\n) )"; -my $re_tag = "perl|args|once|init|cleanup|doc|text|expr|file"; - -# ( $type, $value ) = $mason->lex_token(); -sub lex_token { - # Blocks in <%word> ... <%word> tags. - /\G \<\%($re_tag)\> (.*?) \<\/\%\1\> $re_eol? /xcogs ? ( $1 => $2 ) : - - # Blocks in <% ... %> tags. - /\G \<\% ( .*? ) \%\> /xcogs ? ( 'expr' => $1 ) : - - # Blocks in <& ... &> tags. - /\G \<\& ( .*? ) \&\> /xcogs ? ( 'file' => $1 ) : - - # Lines begining with % - /\G $re_sol \% ( [^\n\r]* ) $re_eol /xcogs ? ( 'perl' => $1 ) : - - # Things that don't match the above - /\G ( (?: [^\<\r\n%]+ | \<(?!\%|\&) | (?<=[^\r\n\<])% | - $re_eol (?:\z|[^\r\n\%\<]|(?=\r\n|\r|\n|\%)|\<[^\%\&]|(?=\<[\%\&])) - )+ (?: $re_eol +(?:\z|(?=\%|\<\[\%\&])) )? - ) /xcogs ? ( 'text' => $1 ) : - - # Lexer error - () -} - -###################################################################### - -# Text elements used for subroutine assembly -sub assembler_rules { - my $self = shift; - $self->NEXT('assembler_rules'), - template => [ qw( @once $sub_start $init_errs $init_output $init_args - @init @perl !@cleanup $return_output $sub_end -@doc ) ] -} - -sub assemble_args { - my ( $self, $token ) = @_; - $token =~ s/^\s*([\$\@\%])(\w+) (?:\s* => \s* ([^\r\n]+))?/ - my $argvar = ($1 eq '$') ? "\$ARGS{$2}" : "$1\{ \$ARGS{$2} }"; - "my $1$2 = exists \$ARGS{$2} ? $argvar : " . - ( defined($3) ? "($argvar = $3)" : - qq{Carp::croak("no value sent for required parameter '$2'")} ) . - ";"/gexm; - return ( 'init' => '($#_ % 2) or Carp::croak("Odd number of parameters passed to sub expecting name/value pairs"); ' . "\n" . $token ); -} - -###################################################################### - -1; - -__END__ - -###################################################################### - -=head1 NAME - -Text::MicroMason::HTMLMason - Simple Compiler for Mason-style Templating - - -=head1 SYNOPSIS - -Create a MicroMason object to interpret the templates: - - use Text::MicroMason; - my $mason = Text::MicroMason->new(); - -Use the standard compile and execute methods to parse and evalute templates: - - print $mason->compile( text=>$template )->( @%args ); - print $mason->execute( text=>$template, @args ); - -Mason syntax provides several ways to mix Perl into a text template: - - <%args> - $name - - - % if ( $name eq 'Dave' ) { - I'm sorry <% $name %>, I'm afraid I can't do that right now. - % } else { - <%perl> - my $hour = (localtime)[2]; - my $daypart = ( $hour > 11 ) ? 'afternoon' : 'morning'; - - Good <% $daypart %>, <% $name %>! - % } - - <& "includes/standard_footer.msn" &> - - <%doc> - Here's a private developr comment describing this template. - - - -=head1 DESCRIPTION - -The Text::MicroMason::HTMLMason class provides lexer and assembler methods that allow Text::MicroMason to handle most elements of HTML::Mason's template syntax. - - -=head2 Compatibility with HTML::Mason - -HTML::Mason is a full-featured application server toolkit with many fatures, of which only the templating functionality is emulated. - -The following sets of HTML::Mason features B supported by Text::MicroMason: - -=over 4 - -=item * - -Template interpolation with <% expr %> - -=item * - -Literal Perl lines with leading % - -=item * - -Named %args, %perl, %once, %init, %cleanup, and %doc blocks - -=item * - -The $m mason object, although with many fewer methods - -=item * - -Expression filtering with |h and |u (via -Filter mixin) - -=back - -The following sets of HTML::Mason features are B supported by Text::MicroMason: - -=over 4 - -=item * - -No %attr, %flag, %shared, %method, or %def blocks. - -=item * - -No shared files like autohandler and dhandler. - -=item * - -No $r request object. No mod_perl integration or configuration capability. - -=back - -Contributed patches to add these features of HTML::Mason would be -welcomed by the author. Possible implemenations are described in -L. - -=head2 Private Methods - -The following internal methods are used to implement the syntax described below. - -=over 4 - -=item lex_token - - ( $type, $value ) = $mason->lex_token(); - -Supports HTML::Mason's markup syntax. - -Attempts to parse a token from the template text stored in the global $_ and returns a token type and value. Returns an empty list if unable to parse further due to an error. - -=item assembler_rules() - -Returns a hash of text elements used for Perl subroutine assembly. Used by assemble(). - -Supports HTML::Mason's named blocks of Perl code and documentation: %once, %init, %cleanup, and %doc. - -=item assemble_args - -Called by assemble(), this method provides support for Mason's <%args> blocks. - -=back - - -=head1 TEMPLATE SYNTAX - -Here's an example of Mason-style templating, taken from L: - - % my $noun = 'World'; - Hello <% $noun %>! - How are ya? - -Interpreting this template with Text::MicroMason produces the same output as it would in HTML::Mason: - - Hello World! - How are ya? - -Text::MicroMason::HTMLMason supports a syntax that is mostly a subset of that used by HTML::Mason. - -=head2 Template Markup - -The following types of markup are recognized in template pages: - -=over 4 - -=item * - -I - -Anything not specifically parsed by one of the below rules is interpreted as literal text. - -=item * - -E% I %E - -A Perl expression to be interpolated into the result. - -For example, the following template text will return a scheduled -greeting: - - Good <% (localtime)[2]>11 ? 'afternoon' : 'morning' %>. - -The block may span multiple lines and is scoped inside a "do" block, -so it may contain multiple Perl statements and it need not end with -a semicolon. - - Good <% my $h = (localtime)[2]; $h > 11 ? 'afternoon' - : 'morning' %>. - -=item * - -% I - -Lines which begin with the % character, without any leading -whitespace, may contain arbitrary Perl code to be executed when -encountering this portion of the template. Their result is not -interpolated into the result. - -For example, the following template text will return a scheduled -greeting: - - % my $daypart = (localtime)[2]>11 ? 'afternoon' : 'morning'; - Good <% $daypart %>. - -The line may contain one or more statements. This code is is not -placed in its own block scope, so it should typically end with a -semicolon; it can still open a spanning block scope closed by a later -perl block. - -For example, the following template text will return one of two different messages each time it's interpreted: - - % if ( int rand 2 ) { - Hello World! - % } else { - Goodbye Cruel World! - % } - -This also allows you to quickly comment out sections of a template by prefacing each line with C<% #>. - -This is equivalent to a <%perl>... block. - -=item * - -E& I, I &E - -Includes the results of a separate file containing MicroMason code, compiling it and executing it with any arguments passed after the filename. - -For example, we could place the following template text into an separate -file: - - Good <% $ARGS{hour} >11 ? 'afternoon' : 'morning' %>. - -Assuming this file was named "greeting.msn", its results could be embedded within the output of another script as follows: - - <& "greeting.msn", hour => (localtime)[2] &> - -=item * - -E%IE ... E/%IE - -A named block contains a span of text. The name at the start and end must match, and must be one of the supported block names. - -Depending on the name, performs one of the behaviors described in L. - -=back - -=head2 Named Blocks - -The following types of named blocks are supported: - -=over 4 - -=item * - -E%perlE I E/%perlE - -Blocks surrounded by %perl tags may contain arbitrary Perl code. -Their result is not interpolated into the result. - -These blocks may span multiple lines in your template file. For -example, the below template initializes a Perl variable inside a -%perl block, and then interpolates the result into a message. - - <%perl> - my $count = join '', map "$_... ", ( 1 .. 9 ); - - Here are some numbers: <% $count %> - -The code may contain one or more statements. This code is is not -placed in its own block scope, so it should typically end with a -semicolon; it can still open a spanning block scope closed by a later -perl block. - -For example, when the below template text is evaluated it will -return a sequence of digits: - - Here are some numbers: - <%perl> - foreach my $digit ( 1 .. 9 ) { - - <% $digit %>... - <%perl> - } - - -If the block is immediately followed by a line break, that break is -discarded. These blocks are not whitespace sensitive, so the template -could be combined into a single line if desired. - -=item * - -E%argsE I => I E/%argsE - -Defines a collection of variables to be initialized from named arguments passed to the subroutine. Arguments are separated by one or more newlines, and may optionally be followed by a default value. If no default value is provided, the argument is required and the subroutine will croak if it is not provided. - -For example, adding the following block to a template will initialize the three named variables, and will fail if no C '...'> argument pair is passed: - - <%args> - $a - @b => qw( foo bar baz ) - %c => () - - -All the arguments are available as lexically scoped ("my") variables in the rest of the component. Default expressions are evaluated in top-to-bottom order, and one expression may reference an earlier one. - -Only valid Perl variable names may be used in <%args> sections. Parameters with non-valid variable names cannot be pre-declared and must be fetched manually out of the %ARGS hash. - -=item * - -E%initE I E/%initE - -Similar to a %perl block, except that the code is moved up to the start of -the subroutine. This allows a template's initialization code to be moved to -the end of the file rather than requiring it to be at the top. - -For example, the following template text will return a scheduled -greeting: - - Good <% $daypart %>. - <%init> - my $daypart = (localtime)[2]>11 ? 'afternoon' : 'morning'; - - -=item * - -E%cleanupE I E/%cleanupE - -Similar to a %perl block, except that the code is moved down to the end of the subroutine. - -=item * - -E%onceE I E/%onceE - -Similar to a %perl block, except that the code is executed once, -when the template is first compiled. (If a caller is using execute, -this code will be run repeatedly, but if they call compile and then -invoke the resulting subroutine multiple times, the %once code will -only execute during the compilation step.) - -This code does not have access to %ARGS and can not generate output. -It can be used to define constants, create persistent variables, -or otherwise prepare the environment. - -For example, the following template text will return a increasing -number each time it is called: - - <%once> - my $counter = 1000; - - The count is <% ++ $counter %>. - -=item * - -E%docE ... E/%docE - -Provides space for template developer documentation or comments which are not included in the output. - -=item * - -E%textE ... E/%textE - -Produces literal text in the template output. Can be used to surround text -that contains other markup tags that should not be interpreted. - -Equivalent to un-marked-up text. - -=back - -The following types of named blocks are not supported by HTML::Mason, but are supported here as a side-effect of the way the lexer and assembler are implemented. - -=over 4 - -=item * - -E%exprE ... E/%exprE - -A Perl expression to be interpolated into the result. -The block may span multiple lines and is scoped inside a "do" block, -so it may contain multiple Perl statements and it need not end with -a semicolon. - -Equivalent to the C% ... %E> markup syntax. - -=item * - -E%fileE I, I E/%fileE - -Includes the results of a separate file containing MicroMason code, compiling it and executing it with any arguments passed after the filename. - - <%file> "greeting.msn", hour => (localtime)[2] - -Equivalent to the C& ... &E> markup syntax. - -=back - - -=head1 TEMPLATE CODING TECHNIQUES - -=head2 Assembling Perl Source Code - -When Text::MicroMason::Base assembles your lexed template into the -equivalent Perl subroutine, all of the literal (non-Perl) pieces are -converted to C<$_out-E('text');> statements, and the interpolated -expressions are converted to C<$_out-E( do { expr } );> statements. -Code from %perl blocks and % lines are included exactly as-is. - -Your code is eval'd in the C package. -The C pragma is enabled by default to simplify debugging. - -=head2 Internal Sub-templates - -You can create sub-templates within your template text by defining -them as anonymous subroutines and then calling them repeatedly. -For example, the following template will concatenate the results of -the draw_item sub-template for each of three items: - -

We've Got Items!

- - % my $draw_item = sub { -

<% $_[0] %>:
-
See more about <% $_[0] %>.

- % }; - - <%perl> - foreach my $item ( qw( Foo Bar Baz ) ) { - $draw_item->( $item ); - } - - -=head2 Returning Text from Perl Blocks - -To append to the result from within Perl code, call $_out->(I). -(The $_out->() syntax is unavailable in older versions of Perl; use the -equivalent &$_out() syntax instead.) - -For example, the below template text will return '123456789' when it is -evaluated: - - <%perl> - foreach my $digit ( 1 .. 9 ) { - $_out->( $digit ) - } - - -You can also directly manipulate the value @OUT, which contains the -accumulating result. - -For example, the below template text will return an altered version of its -message if a true value for 'minor' is passed as an argument when the -template is executed: - - This is a funny joke. - % if ( $ARGS{minor} ) { foreach ( @OUT ) { tr[a-z][n-za-m] } } - - -=head1 SEE ALSO - -For a full-featured web application system using this template syntax, see L. - -For an overview of this distribution, see L. - -This is a subclass intended for use with L. - -For distribution, installation, support, copyright and license -information, see L. - -=cut - diff -Nru libtext-micromason-perl-2.13/MicroMason/HTMLTemplate.pm libtext-micromason-perl-2.16/MicroMason/HTMLTemplate.pm --- libtext-micromason-perl-2.13/MicroMason/HTMLTemplate.pm 2007-01-29 19:47:01.000000000 +0000 +++ libtext-micromason-perl-2.16/MicroMason/HTMLTemplate.pm 1970-01-01 00:00:00.000000000 +0000 @@ -1,376 +0,0 @@ -package Text::MicroMason::HTMLTemplate; - -require Text::MicroMason::Base; -require Text::MicroMason::TemplateDir; -require Text::MicroMason::StoreOne; -require Text::MicroMason::HasParams; -push @ISA, map "Text::MicroMason::$_", qw( TemplateDir StoreOne HasParams ); - -use strict; - -###################################################################### - -my %param_mapping = ( ### <<== INCOMPLETE ### - global_vars => 'loop_global_vars', - cache => '-CompileCache', - path => '-TemplatePaths', -); - -###################################################################### - -sub output { (shift)->execute_again( @_ ) } - -###################################################################### - -my $prefix_re = '[tT][mM][pP][lL]_'; - -sub lex_token { - # warn " Lexer: " . pos($_) . " of " . length($_) . "\n"; - # Tags in format "", "", or "" - /\G \<(\/?)($prefix_re\w+)\s*(.*?)\> /gcxs - ? ( ( $1 ? "tmpl_end" : lc($2) ) => { $_[0]->parse_args($3) } ) : - - # Things that don't match the above - /\G ( (?: [^<] | <(?!\/?$prefix_re) )+ ) /gcxs ? ( 'text' => $1 ) : - - # Lexer error - () -} - -sub parse_args { - my $self = shift; - my $args = "$_[0]"; - return () unless length($args); - return ( name => $args ) unless ( $args =~ /=/ ); - my @tokens; - until ( $args =~ /\G\z/gc ) { - push ( @tokens, - $args =~ /\G \s* (\w+) \= (?: \"([^\"]+)\" | ( \w+ ) ) (?= \s | \z ) /gcxs - ? ( lc($1) => ( defined($2) ? $2 : $3 ) ) : - $args =~ /\G ( .{0,20} ) /gcxs - && die "Couldn't find applicable parsing rule at '$1'\n" - ); - } - @tokens; -} - -###################################################################### - -sub assemble_tmpl_var { - my ($self, $args) = @_; - - my $output = "\$m->param( '$args->{name}' )"; - if ( defined $args->{default} ) { - $output = "local \$_ = $output; defined ? \$_ : '$args->{default}'" - } - if ( $args->{escape} ) { - $output = "\$m->filter( $output, '$args->{escape}' )" - } - expr => "$output;" -} - -sub assemble_tmpl_include { - my ($self, $args) = @_; - file => $args->{name} -} - -sub assemble_tmpl_loop { - my ($self, $args) = @_; - if ( ! $self->{loop_context_vars} ) { - perl => q/foreach my $args ( $m->param( '/ . $args->{name} . q/' ) ) { - local $m->{params} = [ $args, $m->{loop_global_vars} ? @{$m->{params}} : () ];/ - } else { - perl => q/my @loop = $m->param( '/ . $args->{name} . q/' ); - foreach my $count ( 0 .. $#loop ) { - my $args = $loop[ $count ]; - my %loop_context = ( - __counter__ => $count, - __odd__ => ( $count % 2 ), - __first__ => ( $count == 0 ), - __inner__ => ( $count > 0 and $count < $#loop ), - __last__ => ( $count == $#loop ), - ); - local $m->{params} = [ $args, \%loop_context, $m->{loop_global_vars} ? @{$m->{params}} : () ]; - / - } -} - -sub assemble_tmpl_if { - my ($self, $args) = @_; - perl => q/if ( $m->param( '/ . $args->{name} . q/' ) ) { / -} - -sub assemble_tmpl_unless { - my ($self, $args) = @_; - perl => q/if ( ! $m->param( '/ . $args->{name} . q/' ) ) { / -} - -sub assemble_tmpl_else { - perl => "} else {" -} - -sub assemble_tmpl_end { - perl => "}" -} - -###################################################################### - -use vars qw( %Filters ); - -sub defaults { - (shift)->NEXT('defaults'), filters => \%Filters, -} - -# Output filtering -$Filters{1} = $Filters{html} = \&HTML::Entities::encode - if eval { require HTML::Entities}; -$Filters{url} = \&URI::Escape::uri_escape if eval { require URI::Escape }; - -# $result = $mason->filter( @filters, $content ); -sub filter { - my $self = shift; - my $content = pop; - - foreach my $filter ( @_ ) { - my $function = ( ref $filter eq 'CODE' ) ? $filter : - $self->{filters}{ $filter } || - $self->croak_msg("No definition for a filter named '$filter'" ); - $content = &$function($content) - } - $content -} - -###################################################################### - -1; - -__END__ - -###################################################################### - -=head1 NAME - -Text::MicroMason::HTMLTemplate - Alternate Syntax like HTML::Template - - -=head1 SYNOPSIS - -Instead of using this class directly, pass its name to be mixed in: - - use Text::MicroMason; - my $mason = Text::MicroMason::Base->new( -HTMLTemplate ); - -Use the standard compile and execute methods to parse and evalute templates: - - print $mason->compile( text=>$template )->( @%args ); - print $mason->execute( text=>$template, @args ); - -Or use HTML::Template's calling conventions: - - $template = Text::MicroMason->new( -HTMLTemplate, filename=>'simple.tmpl' ); - $template->param( %arguments ); - print $template->output(); - -HTML::Template provides a syntax to embed values into a text template: - - - I'm sorry , I'm afraid I can't do that right now. - - - Good morning, ! - - Good afternoon, ! - - - - -=head1 DESCRIPTION - -This mixin class overrides several methods to allow MicroMason to emulate -the template syntax and some of the other features of HTML::Template. - -This class automatically includes the following other mixins: TemplateDir, HasParams, and StoreOne. - -=head2 Compatibility with HTML::Template - -This is not a drop-in replacement for HTML::Template, as the implementation is quite different, but it should be able to process most existing templates without major changes. - -This should allow current HTML::Template users to take advantage of -MicroMason's one-time compilation feature, which in theory could be faster -than HTML::Template's run-time interpretation. (No benchmarking yet.) - -The following features of HTML::Template are not supported yet: - -=over 4 - -=item * - -Search path for files. (Candidate for separate mixin class or addition to TemplateDir.) - -=item * - -Many HTML::Template options are either unsupported or have different names and need to be mapped to equivalent sets of attributes. (Transform these in the new() method or croak if they're unsupported.) - -=back - -The following features of HTML::Template will likely never be supported due to fundamental differences in implementation: - -=over 4 - -=item * - -query() method - -=back - -Contributed patches to more closely support the behavior of HTML::Template -would be welcomed by the author. - -=head2 Template Syntax - -The following elements are recognized by the HTMLTemplate lexer: - -=over 4 - -=item * - -I - -Anything not specifically parsed by the below rule is interpreted as literal text. - -=item * - -ETMPL_IE - -A template tag with no attributes. - -=item * - -ETMPL_I IE - -A template tag with a name attribute. - -=item * - -ETMPL_I NAME=I I