in reply to Testing Custom Template Filters in Dancer

I don't like this solution much, either. Is there a clean way how to run a custom filter in isolation to test it?

Huh? Put it in one file, $INC{'Template/Plugin/MyFilter.pm]}=__FILE__; ... and run your tests ?

  • Comment on Re: Testing Custom Template Filters in Dancer

Replies are listed 'Best First'.
Re^2: Testing Custom Template Filters in Dancer (in-memory template)
by Anonymous Monk on Feb 05, 2015 at 23:07 UTC

    New app created with  dancer -a YoApp

    With config

    template: "template_toolkit" engines: template_toolkit: PLUGIN_BASE: 'Template::Plugin' start_tag: '<%' end_tag: '%>'

    New test filte that started out as an app:) YoApp/bin/filtertest.pl

    #!/usr/bin/perl -- BEGIN{ $INC{'Template/Plugin/FilterFence.pm'}=__FILE__; package Template::Plugin::FilterFence; use Template::Plugin::Filter; use base qw( Template::Plugin::Filter ); sub filter { my ($self, $text) = @_; return join '&nbsp;', split '', $text ; } sub init { my $self = shift; $self->install_filter('fence'); return $self } 1; }; use Dancer; use YoApp; package YoApp; use Dancer ':syntax'; get '/filtertest' => sub { #~ template 'filtertest'; Dancer::Template->engine->render( \q{ <% USE FilterFence %> bird is "<% "bird" | $FilterFence %>" the word "<% "word" | fence %>" } ); }; #~ dance; exit; ## if you want to view in browser package main; use Dancer::Test; response_status_is [GET => '/filtertest'], 200, "GET /filtertest is fo +und"; response_content_like [GET => '/filtertest'], qr/something/, "somethin +g"; response_content_like [GET => '/filtertest'], qr/something/, "somethin +g"; Test::More::done_testing();