File Coverage

blib/lib/Template/Plugin/HTML_NonAsc.pm
Criterion Covered Total %
statement 22 22 100.0
branch n/a
condition 1 2 50.0
subroutine 7 7 100.0
pod 0 2 0.0
total 30 33 90.9


line stmt bran cond sub pod time code
1             #! perl
2              
3             # Author : Johan Vromans
4             # Created On : Fri Aug 5 20:19:18 2010
5             # Last Modified By: Johan Vromans
6             # Last Modified On: Mon Aug 16 07:53:45 2010
7             # Update Count : 29
8             # Status : Unknown, Use with caution!
9              
10             =head1 NAME
11              
12             Template::Plugin::HTML_NonAsc - Slightly less picky html filter.
13              
14             =head1 SYNOPSIS
15              
16             This filter behaves like the builtin html filter except that it does
17             B escape ASCII characters, I>, C<< > >>, C<< & >>,
18             and C<< " >>>. This makes it possible to write templates in HTML using
19             non-ASCII characters. Pass the contents through this filter and all
20             non-ASCII characters will be escaped using HTML entities.
21              
22             The best place to apply this filter is in your page/wrapper:
23              
24             [%
25             USE HTML_NonAsc; # for html_nonasc filter
26             SWITCH page.type;
27             ...
28             CASE "html";
29             content | html_nonasc
30             WRAPPER page/html
31             + page/layout;
32             ...
33             CASE;
34             THROW page.type "Invalid page type: $page.type";
35             END;
36             -%]
37              
38             =cut
39              
40 2     2   2979699 use 5.008003;
  2         6  
  2         88  
41 2     2   11 use strict;
  2         4  
  2         70  
42 2     2   12 use warnings;
  2         10  
  2         125  
43              
44             package Template::Plugin::HTML_NonAsc;
45              
46             our $VERSION = 0.03;
47              
48 2     2   10 use base qw( Template::Plugin::Filter );
  2         4  
  2         13956  
49              
50 2     2   5919 use HTML::Entities;
  2         7425  
  2         410  
51              
52             sub init {
53 1     1 0 82 my $self = shift;
54 1   50     15 my $name = $self->{ _CONFIG }->{name} || 'html_nonasc';
55 1         9 $self->install_filter($name);
56 1         48 return $self;
57             }
58              
59             sub filter {
60 1     1 0 77 my ( $self, $parameter ) = @_;
61 1         4 encode_entities( $parameter, '^\n\x20-\x7e' );
62 1         238 $parameter;
63             }
64              
65             =head1 AUTHOR
66              
67             Johan Vromans, C<< >>
68              
69             =head1 BUGS
70              
71             Please report any bugs or feature requests to
72             C, or through the web
73             interface at
74             L.
75             I will be notified, and then you'll automatically be notified of
76             progress on your bug as I make changes.
77              
78             =head1 COPYRIGHT & LICENSE
79              
80             Copyright 2010 Johan Vromans, all rights reserved.
81              
82             This program is free software; you can redistribute it and/or modify it
83             under the same terms as Perl itself.
84              
85             =cut
86              
87             1;