| 1 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | package HTML::FormFu::Filter::Encode; | ||||||||||||||||||||||||||||
| 4 | 2 | $HTML::FormFu::Filter::Encode::VERSION = '2.06'; | |||||||||||||||||||||||||||
| 5 | # ABSTRACT: Encode/Decode Submitted Values | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use MooseX::Attribute::Chained; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | extends 'HTML::FormFu::Filter'; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Encode qw(encode decode FB_CROAK); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 2 | has encode_to => ( is => 'rw', traits => ['Chained'] ); | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 2 | has _candidates => ( is => 'rw' ); | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | sub filter { | ||||||||||||||||||||||||||||
| 18 | 1 | ▶ | my ( $self, $value ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
filter: called CC=3 SCAR=11.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 1 | ▶ | return if !defined $value; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 1 | my $utf8 = $self->decode_to_utf8($value); | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 1 | ▶ | die "HTML::FormFu::Filter::Encode: Unable to decode given string to utf8" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | if !defined $utf8; | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 1 | return $self->encode_from_utf8($utf8); | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | sub get_candidates { | ||||||||||||||||||||||||||||
| 31 | 1 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
get_candidates: called CC=3 SCAR=12.7
Pod
undocumented
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 1 | my $ret = $self->_candidates; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 1 | ▶ | if ( $ret && wantarray ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$ret and wantarray
MC/DC0%0/2
$ret and wantarray
$ret
wantarray
Truth table33%1/3
A and B
A= $retB= wantarray
| |||||||||||||||||||||||||||||
| 36 | 1 | return @$ret; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 0 | return $ret; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | sub candidates { | ||||||||||||||||||||||||||||
| 43 | 1 | ▶ | my ( $self, @candidates ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
candidates: called CC=3 SCAR=11.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 1 | ▶ | if ( @_ > 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 1 | ▶ | if ( ref $candidates[0] eq 'ARRAY' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 0 | $self->_candidates( $candidates[0] ); | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | else { | ||||||||||||||||||||||||||||
| 50 | 1 | $self->_candidates( [@candidates] ); | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 1 | return $self; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | sub decode_to_utf8 { | ||||||||||||||||||||||||||||
| 58 | 1 | ▶ | my ( $self, $value ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
decode_to_utf8: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 1 | my $ret; | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 1 | foreach my $candidate ( $self->get_candidates ) { | |||||||||||||||||||||||||||
| 63 | 2 | eval { $ret = decode( $candidate, $value, FB_CROAK ) }; | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 2 | ▶ | if ( !$@ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 1 | last; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 1 | return $ret; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | sub encode_from_utf8 { | ||||||||||||||||||||||||||||
| 74 | 1 | ▶ | my ( $self, $value ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
encode_from_utf8: called CC=2 SCAR=7.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 1 | my $enc = $self->encode_to; | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 1 | ▶ | if ( !$enc ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 0 | return $value; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 1 | return encode( $enc, $value ); | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 2 | 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.06 | ||||||||||||||||||||||||||||
| 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 | ||||||||||||||||||||||||||||