Template-AutoFilter-0.143050000755000000000000 012425177711 16133 5ustar00unknownunknown000000000000Changes100644000000000000 322712425177711 17513 0ustar00unknownunknown000000000000Template-AutoFilter-0.143050Revision history for Perl module Template-AutoFilter 0.143050 2014-11-01 16:44:04+01:00 Europe/Berlin - apply auto-filtering to individual directives instead of an entire tag, i.e. [% IF foo; bar; ELSE; baz; END %] 0.140770 2014-03-18 10:49:54-07:00 America/Los_Angeles - removed 'use lib' which breaks some people ( thanks to Aran Deltac ) - skip interpolated text (ITEXT) sections which are not supported ( thanks to Thomas Sibley ) 0.132690 2013-09-26 10:17:29 Europe/Berlin - comments or empty blocks are not autofiltered anymore ( thanks to Ryan Olson ) 0.130420 2013-02-11 15:59:01 Europe/Berlin - PERL/RAWPERL blocks are not autofiltered anymore 0.112350 2011-08-23 15:48:51 Europe/Berlin - blocks with implicit assignments are not autofiltered anymore 0.112120 2011-07-31 22:23:37 Europe/Berlin - load proper test module versions to get the abilities we want 0.112070 2011-07-26 21:53:24 Europe/Berlin - switched test IDE adaption to Test::InDistDir 0.111980 2011-07-17 16:07:35 Europe/Berlin - nested fields do not cause warnings anymore 0.110080 2011-01-08 12:09:13 Europe/Berlin - added an option to customize the directives to be skipped 0.110050 2011-01-05 12:01:50 Europe/Berlin - just a documentation improvement 0.110032 2011-01-03 22:47:24 Europe/Berlin - slightly more efficient exclusion of directives in the parser 0.110030 2011-01-03 01:16:21 Europe/Berlin - better selection of directives to be filtered ( thanks to Tina Müller ) 0.110020 2011-01-02 17:49:56 Europe/Berlin - initial release LICENSE100644000000000000 1640512425177711 17247 0ustar00unknownunknown000000000000Template-AutoFilter-0.143050 Christian Walde has dedicated the work to the Commons by waiving all of his or her rights to the work worldwide under copyright law and all related or neighboring legal rights he or she had in the work, to the extent allowable by law. Works under CC0 do not require attribution. When citing the work, you should not imply endorsement by the author. Creative Commons Legal Code CC0 1.0 Universal CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED HEREUNDER. Statement of Purpose The laws of most jurisdictions throughout the world automatically confer exclusive Copyright and Related Rights (defined below) upon the creator and subsequent owner(s) (each and all, an "owner") of an original work of authorship and/or a database (each, a "Work"). Certain owners wish to permanently relinquish those rights to a Work for the purpose of contributing to a commons of creative, cultural and scientific works ("Commons") that the public can reliably and without fear of later claims of infringement build upon, modify, incorporate in other works, reuse and redistribute as freely as possible in any form whatsoever and for any purposes, including without limitation commercial purposes. These owners may contribute to the Commons to promote the ideal of a free culture and the further production of creative, cultural and scientific works, or to gain reputation or greater distribution for their Work in part through the use and efforts of others. For these and/or other purposes and motivations, and without any expectation of additional consideration or compensation, the person associating CC0 with a Work (the "Affirmer"), to the extent that he or she is an owner of Copyright and Related Rights in the Work, voluntarily elects to apply CC0 to the Work and publicly distribute the Work under its terms, with knowledge of his or her Copyright and Related Rights in the Work and the meaning and intended legal effect of CC0 on those rights. 1. Copyright and Related Rights. A Work made available under CC0 may be protected by copyright and related or neighboring rights ("Copyright and Related Rights"). Copyright and Related Rights include, but are not limited to, the following: i. the right to reproduce, adapt, distribute, perform, display, communicate, and translate a Work; ii. moral rights retained by the original author(s) and/or performer(s); iii. publicity and privacy rights pertaining to a person's image or likeness depicted in a Work; iv. rights protecting against unfair competition in regards to a Work, subject to the limitations in paragraph 4(a), below; v. rights protecting the extraction, dissemination, use and reuse of data in a Work; vi. database rights (such as those arising under Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, and under any national implementation thereof, including any amended or successor version of such directive); vii. and other similar, equivalent or corresponding rights throughout the world based on applicable law or treaty, and any national implementations thereof. 2. Waiver. To the greatest extent permitted by, but not in contravention of, applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and unconditionally waives, abandons, and surrenders all of Affirmer's Copyright and Related Rights and associated claims and causes of action, whether now known or unknown (including existing as well as future claims and causes of action), in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each member of the public at large and to the detriment of Affirmer's heirs and successors, fully intending that such Waiver shall not be subject to revocation, rescission, cancellation, termination, or any other legal or equitable action to disrupt the quiet enjoyment of the Work by the public as contemplated by Affirmer's express Statement of Purpose. 3. Public License Fallback. Should any part of the Waiver for any reason be judged legally invalid or ineffective under applicable law, then the Waiver shall be preserved to the maximum extent permitted taking into account Affirmer's express Statement of Purpose. In addition, to the extent the Waiver is so judged Affirmer hereby grants to each affected person a royalty-free, non transferable, non sublicensable, non exclusive, irrevocable and unconditional license to exercise Affirmer's Copyright and Related Rights in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "License"). The License shall be deemed effective as of the date CC0 was applied by Affirmer to the Work. Should any part of the License for any reason be judged legally invalid or ineffective under applicable law, such partial invalidity or ineffectiveness shall not invalidate the remainder of the License, and in such case Affirmer hereby affirms that he or she will not (i) exercise any of his or her remaining Copyright and Related Rights in the Work or (ii) assert any associated claims and causes of action with respect to the Work, in either case contrary to Affirmer's express Statement of Purpose. 4. Limitations and Disclaimers. a. No trademark or patent rights held by Affirmer are waived, abandoned, surrendered, licensed or otherwise affected by this document. b. Affirmer offers the Work as-is and makes no representations or warranties of any kind concerning the Work, express, implied, statutory or otherwise, including without limitation warranties of title, merchantability, fitness for a particular purpose, non infringement, or the absence of latent or other defects, accuracy, or the present or absence of errors, whether or not discoverable, all to the greatest extent permissible under applicable law. c. Affirmer disclaims responsibility for clearing rights of other persons that may apply to the Work or any use thereof, including without limitation any person's Copyright and Related Rights in the Work. Further, Affirmer disclaims responsibility for obtaining any necessary consents, permissions or other rights required for any use of the Work. d. Affirmer understands and acknowledges that Creative Commons is not a party to this document and has no duty or obligation with respect to this CC0 or use of the Work. dist.ini100644000000000000 511112425177711 17656 0ustar00unknownunknown000000000000Template-AutoFilter-0.143050name = Template-AutoFilter author = Christian Walde license = CC0_1_0 copyright_holder = Christian Walde ; version provider [AutoVersion] ; builds a version automatically from the date major = 0 ; choose files to include [GatherDir] ; everything under top dir [PruneCruft] ; default stuff to skip [ManifestSkip] ; if -f MANIFEST.SKIP, skip those, too ; file modifications [OurPkgVersion] ; add $VERSION = ... to all files [PodWeaver] ; generate Pod config_plugin = @DAGOLDEN ; my own plugin allows Pod::WikiDoc ; generated files [License] ; boilerplate license [ReadmeMarkdownFromPod] ; from Pod (runs after PodWeaver) [CopyReadmeFromBuild] ; for the repo ; t tests [Test::Compile] ; make sure .pm files all compile fake_home = 1 ; fakes $ENV{HOME} just in case ; xt tests [MetaTests] ; xt/release/meta-yaml.t [PodSyntaxTests] ; xt/release/pod-syntax.t [PodCoverageTests] ; xt/release/pod-coverage.t [Test::Portability] ; xt/release/portability.t (of file name) [Test::Kwalitee] ; xt/release/kwalitee.t [Test::Version] ; xt/release/test-version.t ; metadata [AutoPrereqs] ; find prereqs from code [MinimumPerl] ; determine minimum perl version [GithubMeta] [MetaNoIndex] ; sets 'no_index' in META directory = t directory = xt directory = examples directory = corpus package = DB ; just in case [Bugtracker] ; defaults to RT [MetaProvides::Package] ; add 'provides' to META files meta_noindex = 1 ; respect prior no_index directives [MetaYAML] ; generate META.yml (v1.4) [MetaJSON] ; generate META.json (v2) ; build system [ExecDir] ; include 'bin/*' as executables [ShareDir] ; include 'share/' for File::ShareDir [MakeMaker] ; create Makefile.PL ; manifest (after all generated files) [Manifest] ; create MANIFEST ; before release [Git::Check] ; ensure all files checked in allow_dirty = Changes allow_dirty = dist.ini allow_dirty = README.mkdn [CheckPrereqsIndexed] ; ensure prereqs are on CPAN [CheckChangesHasContent] ; ensure Changes has been updated [CheckExtraTests] ; ensure xt/ tests pass [TestRelease] ; ensure t/ tests pass [ConfirmRelease] ; prompt before uploading ; releaser [UploadToCPAN] ; uploads to CPAN ; after release [NextRelease] [Git::Commit] allow_dirty = Changes allow_dirty = dist.ini allow_dirty = README.mkdn [Git::Tag] ; tag repo with custom tag tag_format = release-%v [Git::Push] ; push repo to remote push_to = origin META.yml100644000000000000 231312425177711 17464 0ustar00unknownunknown000000000000Template-AutoFilter-0.143050--- abstract: 'Template::Toolkit with automatic filtering' author: - 'Christian Walde ' build_requires: File::Spec: '0' File::Temp: '0' IO::Handle: '0' IPC::Open3: '0' Test::InDistDir: '0' Test::More: '0.96' Test::Most: '0' perl: '5.006' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 0 generated_by: 'Dist::Zilla version 5.023, CPAN::Meta::Converter version 2.142690' license: unrestricted meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Template-AutoFilter no_index: directory: - t - xt - examples - corpus package: - DB provides: Template::AutoFilter: file: lib/Template/AutoFilter.pm version: '0.143050' Template::AutoFilter::Parser: file: lib/Template/AutoFilter/Parser.pm version: '0.143050' requires: List::MoreUtils: '0' Template: '0' Template::Parser: '0' base: '0' perl: '5.006' strict: '0' warnings: '0' resources: bugtracker: http://rt.cpan.org/Public/Dist/Display.html?Name=Template-AutoFilter homepage: https://github.com/wchristian/Template-AutoFilter repository: https://github.com/wchristian/Template-AutoFilter.git version: '0.143050' MANIFEST100644000000000000 65112425177711 17327 0ustar00unknownunknown000000000000Template-AutoFilter-0.143050# This file was automatically generated by Dist::Zilla::Plugin::Manifest v5.023. Changes LICENSE MANIFEST META.json META.yml Makefile.PL README.mkdn dist.ini lib/Template/AutoFilter.pm lib/Template/AutoFilter/Parser.pm t/00-compile.t t/autofilter.t t/implicit_set.t t/included.tt xt/release/distmeta.t xt/release/kwalitee.t xt/release/pod-coverage.t xt/release/pod-syntax.t xt/release/portability.t xt/release/test-version.t META.json100644000000000000 457012425177711 17643 0ustar00unknownunknown000000000000Template-AutoFilter-0.143050{ "abstract" : "Template::Toolkit with automatic filtering", "author" : [ "Christian Walde " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 5.023, CPAN::Meta::Converter version 2.142690", "license" : [ "unrestricted" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Template-AutoFilter", "no_index" : { "directory" : [ "t", "xt", "examples", "corpus" ], "package" : [ "DB" ] }, "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "develop" : { "requires" : { "Pod::Coverage::TrustPod" : "0", "Test::CPAN::Meta" : "0", "Test::Kwalitee" : "1.21", "Test::Pod" : "1.41", "Test::Pod::Coverage" : "1.08" } }, "runtime" : { "requires" : { "List::MoreUtils" : "0", "Template" : "0", "Template::Parser" : "0", "base" : "0", "perl" : "5.006", "strict" : "0", "warnings" : "0" } }, "test" : { "requires" : { "File::Spec" : "0", "File::Temp" : "0", "IO::Handle" : "0", "IPC::Open3" : "0", "Test::InDistDir" : "0", "Test::More" : "0.96", "Test::Most" : "0", "perl" : "5.006" } } }, "provides" : { "Template::AutoFilter" : { "file" : "lib/Template/AutoFilter.pm", "version" : "0.143050" }, "Template::AutoFilter::Parser" : { "file" : "lib/Template/AutoFilter/Parser.pm", "version" : "0.143050" } }, "release_status" : "stable", "resources" : { "bugtracker" : { "mailto" : "bug-template-autofilter at rt.cpan.org", "web" : "http://rt.cpan.org/Public/Dist/Display.html?Name=Template-AutoFilter" }, "homepage" : "https://github.com/wchristian/Template-AutoFilter", "repository" : { "type" : "git", "url" : "https://github.com/wchristian/Template-AutoFilter.git", "web" : "https://github.com/wchristian/Template-AutoFilter" } }, "version" : "0.143050" } README.mkdn100644000000000000 605612425177711 20033 0ustar00unknownunknown000000000000Template-AutoFilter-0.143050# NAME Template::AutoFilter - Template::Toolkit with automatic filtering # VERSION version 0.143050 # SYNOPSIS use Template::AutoFilter; my $templ = "[% str %] [% str | none %] [% str | url %]"; my $out; Template::AutoFilter->new->process( \$templ, { str => '' }, \$out ); print $out; # "<a> %3Ca%3E" my $out; Template::AutoFilter->new( AUTO_FILTER => 'upper' )->process( \$templ, { str => '' }, \$out ); print $out; # " %3Ca%3E" # DESCRIPTION Template::AutoFilter is a subclass of Template::Toolkit which loads a specific Parser that is subclassed from Template::Parser. It adds a filter instruction to each interpolation token found in templates loaded by the TT engine. Tokens that already have a filter instruction are left unchanged. By default this automatic filter is set to be 'html', but can be modified during object creation by passing the AUTO\_FILTER option with the name of the wanted filter. Additionally a pass-through filter called 'none' is added to the object to allow exclusion of tokens from being filtered. Lastly, if you have problems with the directives which get auto filters applied, you can see the [Template::AutoFilter::Parser](https://metacpan.org/pod/Template::AutoFilter::Parser) docs for how you can customize that. WARNING: This module is highly experimental. I have not done a lot of testing and things might blow up in unexpected ways. The API and behavior might change with any release (until 1.0). If you'd like to see any changes implemented, let me know via RT, email, IRC or by opening a pull request on github. Use at your own risk. # METHODS ## new Pre-processes the parameters passed on to Template's new(). Adds the pass-through filter and creates the AutoFilter Parser. All parameters passed to this new() will also be passed to the parser's new(). # CONTRIBUTORS Ryan Olson (cpan:GIMPSON) Aran Deltac (cpan:BLUEFEET) Thomas Sibley (cpan:TSIBLEY) # SUPPORT ## Bugs / Feature Requests Please report any bugs or feature requests through the issue tracker at [http://rt.cpan.org/Public/Dist/Display.html?Name=Template-AutoFilter](http://rt.cpan.org/Public/Dist/Display.html?Name=Template-AutoFilter). You will be notified automatically of any progress on your issue. ## Source Code This is open source software. The code repository is available for public review and contribution under the terms of the license. [https://github.com/wchristian/Template-AutoFilter](https://github.com/wchristian/Template-AutoFilter) git clone https://github.com/wchristian/Template-AutoFilter.git # AUTHOR Christian Walde # COPYRIGHT AND LICENSE Christian Walde has dedicated the work to the Commons by waiving all of his or her rights to the work worldwide under copyright law and all related or neighboring legal rights he or she had in the work, to the extent allowable by law. Works under CC0 do not require attribution. When citing the work, you should not imply endorsement by the author. Makefile.PL100644000000000000 314312425177711 20167 0ustar00unknownunknown000000000000Template-AutoFilter-0.143050 # This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v5.023. use strict; use warnings; use 5.006; use ExtUtils::MakeMaker; my %WriteMakefileArgs = ( "ABSTRACT" => "Template::Toolkit with automatic filtering", "AUTHOR" => "Christian Walde ", "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => 0 }, "DISTNAME" => "Template-AutoFilter", "EXE_FILES" => [], "LICENSE" => "unrestricted", "MIN_PERL_VERSION" => "5.006", "NAME" => "Template::AutoFilter", "PREREQ_PM" => { "List::MoreUtils" => 0, "Template" => 0, "Template::Parser" => 0, "base" => 0, "strict" => 0, "warnings" => 0 }, "TEST_REQUIRES" => { "File::Spec" => 0, "File::Temp" => 0, "IO::Handle" => 0, "IPC::Open3" => 0, "Test::InDistDir" => 0, "Test::More" => "0.96", "Test::Most" => 0 }, "VERSION" => "0.143050", "test" => { "TESTS" => "t/*.t" } ); my %FallbackPrereqs = ( "ExtUtils::MakeMaker" => 0, "File::Spec" => 0, "File::Temp" => 0, "IO::Handle" => 0, "IPC::Open3" => 0, "List::MoreUtils" => 0, "Template" => 0, "Template::Parser" => 0, "Test::InDistDir" => 0, "Test::More" => "0.96", "Test::Most" => 0, "base" => 0, "strict" => 0, "warnings" => 0 ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { delete $WriteMakefileArgs{TEST_REQUIRES}; delete $WriteMakefileArgs{BUILD_REQUIRES}; $WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs; } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); t000755000000000000 012425177711 16317 5ustar00unknownunknown000000000000Template-AutoFilter-0.143050included.tt100644000000000000 2712425177711 20556 0ustar00unknownunknown000000000000Template-AutoFilter-0.143050/ttest [% test %] autofilter.t100644000000000000 647112425177711 21032 0ustar00unknownunknown000000000000Template-AutoFilter-0.143050/t#!/usr/bin/perl use strict; use warnings; package autofilter; use Test::InDistDir; use Test::More 0.96 (); use Test::Most; run_tests(); done_testing; exit; sub tests {( { name => 'plain text remains unfiltered', tmpl => '', expect => '', }, { name => 'excluded tokens remain unfiltered', tmpl => '[% test | none %]', expect => '', }, { name => 'unfiltered tokens get filtered', tmpl => '[% test %]', expect => '<a>', }, { name => 'specifically filtered tokens get filtered', tmpl => '[% test | html %]', expect => '<a>', }, { name => 'other filters are applied without the autofilter', tmpl => '[% test | upper %]', expect => '', }, { name => 'parameters make it possible to set the autofilter', tmpl => '[% test %]', expect => '', params => { AUTO_FILTER => 'upper' } }, { name => 'includes are not filtered', tmpl => '[% test %] [% INCLUDE included.tt %]', expect => " test \n", params => { AUTO_FILTER => 'upper', INCLUDE_PATH => 't', }, }, { name => 'SKIP_DIRECTIVES modifications are observed', tmpl => '[% test %] [% INCLUDE included.tt %]', expect => " TEST \n", params => { AUTO_FILTER => 'upper', INCLUDE_PATH => 't', SKIP_DIRECTIVES => [], }, }, { name => '[%# comments are parsed correctly', tmpl => 'pre[%# This is a comment -%]post', expect => 'prepost', }, { name => '[% # comments are parsed correctly', tmpl => 'pre[% # This is a comment -%]post', expect => 'prepost', }, { name => 'empty tokens are parsed correctly', tmpl => 'pre[% -%]post', expect => 'prepost', }, { name => "INTERPOLATE => 1 doesn't cause runtime errors (but isn't supported)", tmpl => 'pre $test post', expect => 'pre post', params => { INTERPOLATE => 1, }, }, { name => 'split apart compound statements', tmpl => 'pre [% FOR foo IN ["", "", "&c"]; " $foo "; END %] post', expect => 'pre <Element> <a> <Element> <b> <Element> &c post', }, { name => 'split apart compound statements', tmpl => 'pre [% FOR foo IN ["", "", "&c"]; " $foo " | none; END %] post', expect => 'pre &c post', }, { name => 'tailing semi-colon parsed ok', tmpl => '[% foo=test; %][% foo %]', expect => '<a>', }, )} sub run_tests { use_ok "Template::AutoFilter"; run_test($_) for tests(); return; } sub run_test { my ( $test ) = @_; $test->{params} ||= {}; my $tt = Template::AutoFilter->new( $test->{params} ); my $out; my $res = $tt->process( \$test->{tmpl}, { test => '' }, \$out ); subtest $test->{name} => sub { cmp_deeply( [ $tt->error."", $res ], [ '', 1 ], 'no template errors' ); is( $out, $test->{expect}, 'output is correct' ); }; return; } 00-compile.t100644000000000000 211212425177711 20505 0ustar00unknownunknown000000000000Template-AutoFilter-0.143050/tuse 5.006; use strict; use warnings; # this test was generated with Dist::Zilla::Plugin::Test::Compile 2.043 use Test::More tests => 2 + ($ENV{AUTHOR_TESTING} ? 1 : 0); my @module_files = ( 'Template/AutoFilter.pm', 'Template/AutoFilter/Parser.pm' ); # fake home for cpan-testers use File::Temp; local $ENV{HOME} = File::Temp::tempdir( CLEANUP => 1 ); my $inc_switch = -d 'blib' ? '-Mblib' : '-Ilib'; use File::Spec; use IPC::Open3; use IO::Handle; open my $stdin, '<', File::Spec->devnull or die "can't open devnull: $!"; my @warnings; for my $lib (@module_files) { # see L my $stderr = IO::Handle->new; my $pid = open3($stdin, '>&STDERR', $stderr, $^X, $inc_switch, '-e', "require q[$lib]"); binmode $stderr, ':crlf' if $^O eq 'MSWin32'; my @_warnings = <$stderr>; waitpid($pid, 0); is($?, 0, "$lib loaded ok"); if (@_warnings) { warn @_warnings; push @warnings, @_warnings; } } is(scalar(@warnings), 0, 'no warnings found') if $ENV{AUTHOR_TESTING}; implicit_set.t100644000000000000 116612425177711 21335 0ustar00unknownunknown000000000000Template-AutoFilter-0.143050/t#!/usr/bin/perl use strict; use warnings; use Test::InDistDir; use Test::More tests => 3; use Template; use Template::AutoFilter; my $templ_1 = "[% x = [ 1, 2 ] %] [% x.join(', ') %]"; my $templ_2 = "[% x = [ 1, 2 ] | html %] [% x.join(', ') | html %]"; my $templ_3 = "[% SET x = [ 1, 2 ] %] [% x.join(', ') %]"; for ( $templ_1, $templ_2, $templ_3 ) { my $wanted = process( 'Template', $_ ); my $out = process( 'Template::AutoFilter', $_ ); is( $out, $wanted ); } sub process { my ( $class, $tmpl ) = @_; $class->new->process( \$tmpl, {}, \my $out ); $out =~ s/0x[\da-f]+/hex/; return $out; } release000755000000000000 012425177711 20127 5ustar00unknownunknown000000000000Template-AutoFilter-0.143050/xtdistmeta.t100644000000000000 17212425177711 22246 0ustar00unknownunknown000000000000Template-AutoFilter-0.143050/xt/release#!perl # This file was automatically generated by Dist::Zilla::Plugin::MetaTests. use Test::CPAN::Meta; meta_yaml_ok(); kwalitee.t100644000000000000 27512425177711 22245 0ustar00unknownunknown000000000000Template-AutoFilter-0.143050/xt/release# this test was generated with Dist::Zilla::Plugin::Test::Kwalitee 2.11 use strict; use warnings; use Test::More 0.88; use Test::Kwalitee 1.21 'kwalitee_ok'; kwalitee_ok(); done_testing; pod-syntax.t100644000000000000 22012425177711 22534 0ustar00unknownunknown000000000000Template-AutoFilter-0.143050/xt/release#!perl # This file was automatically generated by Dist::Zilla::Plugin::PodSyntaxTests. use Test::More; use Test::Pod 1.41; all_pod_files_ok(); portability.t100644000000000000 27612425177711 23003 0ustar00unknownunknown000000000000Template-AutoFilter-0.143050/xt/release#!perl use strict; use warnings; use Test::More; eval 'use Test::Portability::Files'; plan skip_all => 'Test::Portability::Files required for testing portability' if $@; run_tests(); pod-coverage.t100644000000000000 33412425177711 23007 0ustar00unknownunknown000000000000Template-AutoFilter-0.143050/xt/release#!perl # This file was automatically generated by Dist::Zilla::Plugin::PodCoverageTests. use Test::Pod::Coverage 1.08; use Pod::Coverage::TrustPod; all_pod_coverage_ok({ coverage_class => 'Pod::Coverage::TrustPod' }); test-version.t100644000000000000 64312425177711 23101 0ustar00unknownunknown000000000000Template-AutoFilter-0.143050/xt/releaseuse strict; use warnings; use Test::More; # generated by Dist::Zilla::Plugin::Test::Version 0.002004 BEGIN { eval "use Test::Version; 1;" or die $@; } my @imports = ( 'version_all_ok' ); my $params = { is_strict => 0, has_version => 1, }; push @imports, $params if version->parse( $Test::Version::VERSION ) >= version->parse('1.002'); Test::Version->import(@imports); version_all_ok; done_testing; Template000755000000000000 012425177711 20375 5ustar00unknownunknown000000000000Template-AutoFilter-0.143050/libAutoFilter.pm100644000000000000 710412425177711 23153 0ustar00unknownunknown000000000000Template-AutoFilter-0.143050/lib/Templateuse strict; use warnings; package Template::AutoFilter; our $VERSION = '0.143050'; # VERSION # ABSTRACT: Template::Toolkit with automatic filtering use base 'Template'; use Template::AutoFilter::Parser; sub new { my $class = shift; my $params = defined($_[0]) && ref($_[0]) eq 'HASH' ? shift : {@_}; $params->{FILTERS}{none} ||= sub { $_[0] }; $params->{PARSER} ||= Template::AutoFilter::Parser->new( $params ); return $class->SUPER::new( $params ); } 1; __END__ =pod =encoding UTF-8 =head1 NAME Template::AutoFilter - Template::Toolkit with automatic filtering =head1 VERSION version 0.143050 =head1 SYNOPSIS use Template::AutoFilter; my $templ = "[% str %] [% str | none %] [% str | url %]"; my $out; Template::AutoFilter->new->process( \$templ, { str => '' }, \$out ); print $out; # "<a> %3Ca%3E" my $out; Template::AutoFilter->new( AUTO_FILTER => 'upper' )->process( \$templ, { str => '' }, \$out ); print $out; # " %3Ca%3E" =head1 DESCRIPTION Template::AutoFilter is a subclass of Template::Toolkit which loads a specific Parser that is subclassed from Template::Parser. It adds a filter instruction to each interpolation token found in templates loaded by the TT engine. Tokens that already have a filter instruction are left unchanged. By default this automatic filter is set to be 'html', but can be modified during object creation by passing the AUTO_FILTER option with the name of the wanted filter. Additionally a pass-through filter called 'none' is added to the object to allow exclusion of tokens from being filtered. Lastly, if you have problems with the directives which get auto filters applied, you can see the L docs for how you can customize that. WARNING: This module is highly experimental. I have not done a lot of testing and things might blow up in unexpected ways. The API and behavior might change with any release (until 1.0). If you'd like to see any changes implemented, let me know via RT, email, IRC or by opening a pull request on github. Use at your own risk. =head1 METHODS =head2 new Pre-processes the parameters passed on to Template's new(). Adds the pass-through filter and creates the AutoFilter Parser. All parameters passed to this new() will also be passed to the parser's new(). =head1 CONTRIBUTORS Ryan Olson (cpan:GIMPSON) Aran Deltac (cpan:BLUEFEET) Thomas Sibley (cpan:TSIBLEY) =for :stopwords cpan testmatrix url annocpan anno bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan =head1 SUPPORT =head2 Bugs / Feature Requests Please report any bugs or feature requests through the issue tracker at L. You will be notified automatically of any progress on your issue. =head2 Source Code This is open source software. The code repository is available for public review and contribution under the terms of the license. L git clone https://github.com/wchristian/Template-AutoFilter.git =head1 AUTHOR Christian Walde =head1 COPYRIGHT AND LICENSE Christian Walde has dedicated the work to the Commons by waiving all of his or her rights to the work worldwide under copyright law and all related or neighboring legal rights he or she had in the work, to the extent allowable by law. Works under CC0 do not require attribution. When citing the work, you should not imply endorsement by the author. =cut AutoFilter000755000000000000 012425177711 22453 5ustar00unknownunknown000000000000Template-AutoFilter-0.143050/lib/TemplateParser.pm100644000000000000 1116612425177711 24432 0ustar00unknownunknown000000000000Template-AutoFilter-0.143050/lib/Template/AutoFilteruse strict; use warnings; package Template::AutoFilter::Parser; our $VERSION = '0.143050'; # VERSION # ABSTRACT: parses TT templates and automatically adds filters to tokens use base 'Template::Parser'; use List::MoreUtils qw< part >; sub new { my ( $class, $params ) = @_; my $self = $class->SUPER::new( $params ); $self->{AUTO_FILTER} = $params->{AUTO_FILTER} || 'html'; $self->{SKIP_DIRECTIVES} = $self->make_skip_directives( $params->{SKIP_DIRECTIVES} ) || $self->default_skip_directives; return $self; } sub split_text { my ( $self, @args ) = @_; my $tokens = $self->SUPER::split_text( @args ) or return; for my $token ( @{$tokens} ) { next if !ref $token; next if !ref $token->[2]; # Skip ITEXT ($bar) # Split a compound statement into individual directives my ($part, $is_directive) = (0, 1); my @directives = part { # Skip over interpolated fields; they are unpaired unless (ref) { $part++ if $is_directive and $_ eq ';'; $is_directive = !$is_directive; } $part; } @{$token->[2]}; for my $directive (@directives) { # Filter out interpolated values in strings; they don't matter for # our decision of whether to autofilter or not (e.g. an existing # filter). Note, this is not the same as ITEXT. Also ignore # semi-colon tokens, as they may make an empty directive look # non-empty. They are also inconsequential to our decision to # autofilter or not. my %fields = grep { !ref and $_ ne ';' } @$directive; next if $self->has_skip_field( \%fields ); next if ! %fields; push @$directive, qw( FILTER | IDENT ), $self->{AUTO_FILTER}; } $token->[2] = [ map { @$_ } @directives ]; } return $tokens; } sub has_skip_field { my ( $self, $fields ) = @_; my $skip_directives = $self->{SKIP_DIRECTIVES}; for my $field ( keys %{$fields} ) { return 1 if $skip_directives->{$field}; } return 0; } sub default_skip_directives { my ( $self ) = @_; my @skip_directives = qw( CALL SET DEFAULT INCLUDE PROCESS WRAPPER BLOCK IF UNLESS ELSIF ELSE END SWITCH CASE FOREACH FOR WHILE FILTER USE MACRO TRY CATCH FINAL THROW NEXT LAST RETURN STOP CLEAR META TAGS DEBUG ASSIGN PERL RAWPERL ); return $self->make_skip_directives( \@skip_directives ); } sub make_skip_directives { my ( $self, $skip_directives_list ) = @_; return if !$skip_directives_list; my %skip_directives = map { $_ => 1 } @{$skip_directives_list}; return \%skip_directives; } 1; __END__ =pod =encoding UTF-8 =head1 NAME Template::AutoFilter::Parser - parses TT templates and automatically adds filters to tokens =head1 VERSION version 0.143050 =head1 DESCRIPTION Sub-class of Template::Parser. =head1 METHODS See L for most of these, documented here are added methods. =head2 new Accepts all the standard L parameters, plus some extra: =head3 AUTO_FILTER Accepts a single string, which defines the name of a filter to be applied to all directives omitted from the skip list. This parameter defaults to 'html'. =head3 SKIP_DIRECTIVES Allows customization of which L should be exempt from having auto filters applied. Expects an array ref of strings. Default value is the output from $self->default_skip_directives. =head2 split_text Modifies token processing by adding the filter specified in AUTO_FILTER to all filter-less interpolation tokens. =head2 has_skip_field Checks the field list of a token to see if it contains directives that should be excluded from filtering. =head2 default_skip_directives Provides a reference to a hash containing the default directives to be excluded. Default value is: CALL SET DEFAULT INCLUDE PROCESS WRAPPER BLOCK IF UNLESS ELSIF ELSE END SWITCH CASE FOREACH FOR WHILE FILTER USE MACRO TRY CATCH FINAL THROW NEXT LAST RETURN STOP CLEAR META TAGS DEBUG =head2 make_skip_directives Prebuilds a hash of directives to be skipped while applying auto filters. =head1 AUTHOR Christian Walde =head1 COPYRIGHT AND LICENSE Christian Walde has dedicated the work to the Commons by waiving all of his or her rights to the work worldwide under copyright law and all related or neighboring legal rights he or she had in the work, to the extent allowable by law. Works under CC0 do not require attribution. When citing the work, you should not imply endorsement by the author. =cut