| 1 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | package HTML::FormFu::Filter::Encode; | ||||||||||||||||||||||||||||
| 4 | 4 | $HTML::FormFu::Filter::Encode::VERSION = '2.09'; | |||||||||||||||||||||||||||
| 5 | # ABSTRACT: Encode/Decode Submitted Values | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use MooseX::Attribute::Chained; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 4 | extends 'HTML::FormFu::Filter'; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 4 | ▶ | use Encode qw(encode decode FB_CROAK); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 4 | has encode_to => ( is => 'rw', traits => ['Chained'] ); | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 4 | has _candidates => ( is => 'rw' ); | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 1 | ▶ | sub filter { | ||||||||||||||||||||||||||
|
Subroutine
filter: called CC=3 SCAR=11.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 18 | 1 | my ( $self, $value ) = @_; | |||||||||||||||||||||||||||
| 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 | 1 | ▶ | sub get_candidates { | ||||||||||||||||||||||||||
|
Subroutine
get_candidates: called CC=3 SCAR=12.7
Pod
undocumented
| |||||||||||||||||||||||||||||
| 31 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 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 | 1 | ▶ | sub candidates { | ||||||||||||||||||||||||||
|
Subroutine
candidates: called CC=3 SCAR=11.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 43 | 1 | my ( $self, @candidates ) = @_; | |||||||||||||||||||||||||||
| 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 | 1 | ▶ | sub decode_to_utf8 { | ||||||||||||||||||||||||||
|
Subroutine
decode_to_utf8: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 58 | 1 | my ( $self, $value ) = @_; | |||||||||||||||||||||||||||
| 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 | 1 | ▶ | sub encode_from_utf8 { | ||||||||||||||||||||||||||
|
Subroutine
encode_from_utf8: called CC=2 SCAR=7.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 74 | 1 | my ( $self, $value ) = @_; | |||||||||||||||||||||||||||
| 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 | 4 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 4 | 1; | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | __END__ | ||||||||||||||||||||||||||||