App-Dapper

 view release on metacpan or  search on metacpan

lib/App/Dapper/Filters.pm  view on Meta::CPAN

package App::Dapper::Filters;

=head1 NAME

App::Dapper::Filters - Default Liquid filters available to all projects.

=head1 DESCRIPTION

Filters contained here can be called from Liquid template files using
the filter/pipe mechanism built in to Liquid. Example:

    {{ site.time | date_to_xmlschema }}

=cut

use utf8;
use open ':std', ':encoding(UTF-8)';
use 5.8.0;
use strict;
use warnings FATAL => 'all';

use Data::Dumper;
use CGI qw(:standard escapeHTML);

=head2 import

Called when this module is 'used' from somewhere else. This subroutine
registers Liquid filters contained in this file.

=cut

#sub import {
#    $filters = Template::Filters->new({
#        FILTERS => {
#            'xml_escape' => \&xml_escape,
#            'date_to_xmlschema' => \&date_to_xmlschema,
#            'replace_last' => \&replace_last,
#            'smart' => \&smart,
#            'json' => \&json,
#        },
#    });
#}

=head2 xml_escape

Liquid filter to escape strings into formats that can be included
in XML files.

=cut

sub xml_escape {
    my $str = shift;
    my $q = new CGI;
    return $q->escapeHTML( $str );
}

=head2 date_to_xmlschema

Convert a date to an XML-formattted version of the date that also includes
the timezone.

=cut

sub date_to_xmlschema {
    my $str = shift;

    use DateTime;
    use DateTime::Format::XSD;

    return DateTime::Format::XSD->format_datetime($str);
}

=head2 replace_last

Liquid filter to replace the last occurrance of a string with another string.

=cut

sub replace_last {
    my ($input, $string, $replacement) = @_;

    $replacement = defined $replacement ? $replacement : '';



( run in 1.301 second using v1.01-cache-2.11-cpan-39bf76dae61 )