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