line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
2
|
|
|
2
|
|
717
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
161
|
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package HTML::FormFu::Filter::Encode; |
4
|
|
|
|
|
|
|
$HTML::FormFu::Filter::Encode::VERSION = '2.07'; |
5
|
|
|
|
|
|
|
# ABSTRACT: Encode/Decode Submitted Values |
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
19
|
use Moose; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
15
|
|
8
|
2
|
|
|
2
|
|
13740
|
use MooseX::Attribute::Chained; |
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
104
|
|
9
|
|
|
|
|
|
|
extends 'HTML::FormFu::Filter'; |
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
54
|
use Encode qw(encode decode FB_CROAK); |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
1160
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has encode_to => ( is => 'rw', traits => ['Chained'] ); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has _candidates => ( is => 'rw' ); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub filter { |
18
|
1
|
|
|
1
|
0
|
2
|
my ( $self, $value ) = @_; |
19
|
|
|
|
|
|
|
|
20
|
1
|
50
|
|
|
|
4
|
return if !defined $value; |
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
|
|
5
|
my $utf8 = $self->decode_to_utf8($value); |
23
|
|
|
|
|
|
|
|
24
|
1
|
50
|
|
|
|
3
|
die "HTML::FormFu::Filter::Encode: Unable to decode given string to utf8" |
25
|
|
|
|
|
|
|
if !defined $utf8; |
26
|
|
|
|
|
|
|
|
27
|
1
|
|
|
|
|
4
|
return $self->encode_from_utf8($utf8); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub get_candidates { |
31
|
1
|
|
|
1
|
0
|
2
|
my ($self) = @_; |
32
|
|
|
|
|
|
|
|
33
|
1
|
|
|
|
|
35
|
my $ret = $self->_candidates; |
34
|
|
|
|
|
|
|
|
35
|
1
|
50
|
33
|
|
|
21
|
if ( $ret && wantarray ) { |
36
|
1
|
|
|
|
|
6
|
return @$ret; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
0
|
return $ret; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub candidates { |
43
|
1
|
|
|
1
|
0
|
5
|
my ( $self, @candidates ) = @_; |
44
|
|
|
|
|
|
|
|
45
|
1
|
50
|
|
|
|
4
|
if ( @_ > 1 ) { |
46
|
1
|
50
|
|
|
|
4
|
if ( ref $candidates[0] eq 'ARRAY' ) { |
47
|
0
|
|
|
|
|
0
|
$self->_candidates( $candidates[0] ); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
else { |
50
|
1
|
|
|
|
|
32
|
$self->_candidates( [@candidates] ); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
1
|
|
|
|
|
35
|
return $self; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub decode_to_utf8 { |
58
|
1
|
|
|
1
|
0
|
2
|
my ( $self, $value ) = @_; |
59
|
|
|
|
|
|
|
|
60
|
1
|
|
|
|
|
10
|
my $ret; |
61
|
|
|
|
|
|
|
|
62
|
1
|
|
|
|
|
5
|
foreach my $candidate ( $self->get_candidates ) { |
63
|
2
|
|
|
|
|
5
|
eval { $ret = decode( $candidate, $value, FB_CROAK ) }; |
|
2
|
|
|
|
|
7
|
|
64
|
|
|
|
|
|
|
|
65
|
2
|
100
|
|
|
|
98
|
if ( !$@ ) { |
66
|
1
|
|
|
|
|
2
|
last; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
1
|
|
|
|
|
3
|
return $ret; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub encode_from_utf8 { |
74
|
1
|
|
|
1
|
0
|
2
|
my ( $self, $value ) = @_; |
75
|
|
|
|
|
|
|
|
76
|
1
|
|
|
|
|
35
|
my $enc = $self->encode_to; |
77
|
|
|
|
|
|
|
|
78
|
1
|
50
|
|
|
|
4
|
if ( !$enc ) { |
79
|
0
|
|
|
|
|
0
|
return $value; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
1
|
|
|
|
|
4
|
return encode( $enc, $value ); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
1; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
__END__ |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=pod |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=encoding UTF-8 |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 NAME |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
HTML::FormFu::Filter::Encode - Encode/Decode Submitted Values |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 VERSION |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
version 2.07 |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 SYNOPSIS |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
# in your config: |
106
|
|
|
|
|
|
|
elements: |
107
|
|
|
|
|
|
|
- type: Text |
108
|
|
|
|
|
|
|
filters: |
109
|
|
|
|
|
|
|
- type: Encode |
110
|
|
|
|
|
|
|
candidates: |
111
|
|
|
|
|
|
|
- utf8 |
112
|
|
|
|
|
|
|
- Hebrew |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
# if you want to encode the decoded string to something else |
115
|
|
|
|
|
|
|
elements: |
116
|
|
|
|
|
|
|
- type: Text |
117
|
|
|
|
|
|
|
filters: |
118
|
|
|
|
|
|
|
- type: Encode |
119
|
|
|
|
|
|
|
candidates: |
120
|
|
|
|
|
|
|
- utf8 |
121
|
|
|
|
|
|
|
- Hebrew |
122
|
|
|
|
|
|
|
encode_to: UTF-32BE |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 AUTHOR |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Copyright (c) 2007 Daisuke Maki E<lt>daisuke@endeworks.jpE<gt> |
127
|
|
|
|
|
|
|
All rights reserved. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 LICENSE |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
This library is free software, you can redistribute it and/or modify it |
132
|
|
|
|
|
|
|
under the same terms as Perl itself. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 AUTHOR |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Carl Franks <cpan@fireartist.com> |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
This software is copyright (c) 2018 by Carl Franks. |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
143
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=cut |