File Coverage

blib/lib/HTML/FormFu/Filter/Demoroniser.pm
Criterion Covered Total %
statement 1 3 33.3
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 2 4 50.0


line stmt bran cond sub pod time code
1             package HTML::FormFu::Filter::Demoroniser;
2              
3 1     1   1330 use Moose;
  0            
  0            
4             use Text::Demoroniser;
5              
6             extends 'HTML::FormFu::Filter';
7              
8             our $VERSION = '0.02';
9              
10             has 'encoding' => ( is => 'rw', traits => ['Chained'] );
11              
12             sub filter {
13             my ( $self, $value ) = @_;
14             my $encoding = $self->encoding || 'utf8';
15              
16             return $encoding eq 'utf8'
17             ? Text::Demoroniser::demoroniser_utf8( $value )
18             : Text::Demoroniser::demoroniser( $value );
19             }
20              
21             __PACKAGE__->meta->make_immutable;
22              
23             1;
24              
25             __END__
26              
27             =head1 NAME
28              
29             HTML::FormFu::Filter::Demoroniser - Filter Microsoft "smart" characters
30              
31             =head1 SYNOPSIS
32              
33             ---
34             elements:
35             - type: Text
36             name: foo
37             filters:
38             - type: Demoroniser
39              
40             =head1 DESCRIPTION
41              
42             As a user fills out a form, they may copy and paste data from Micrsoft Word.
43             In doing so, they might inadvertently copy Microsoft "smart" characters
44             (fancy quotation marks, for example) into the field.
45              
46             This module aims to help clean up that data in favor of UTF8 or ASCII
47             alternatives.
48              
49             =head1 METHODS
50              
51             =head2 filter( $value )
52              
53             Filters C<$value> through L<Text::Demoronise|Text::Demoronise>. By default it will use
54             C<demoroniser_utf8>, though if you specify any text other than "utf8" in the
55             C<encoding> option, it will convert problem characters to an ASCII
56             alternative.
57              
58             ---
59             elements:
60             - type: Text
61             name: foo
62             filters:
63             - type: Demoroniser
64             encoding: ascii
65              
66             =head1 SEE ALSO
67              
68             =over 4
69              
70             =item * L<HTML::FormFu|HTML::FormFu>
71              
72             =item * L<Text::Demoroniser|Text::Demoroniser>
73              
74             =back
75              
76             =head1 AUTHOR
77              
78             Brian Cassidy E<lt>bricas@cpan.orgE<gt>
79              
80             =head1 COPYRIGHT AND LICENSE
81              
82             Copyright 2009-2011 by Brian Cassidy
83              
84             This library is free software; you can redistribute it and/or modify
85             it under the same terms as Perl itself.
86              
87             =cut
88