lib/HTML/FormFu/Filter/Encode.pm

filter: Statementstmt 93.6% 44 / 47 Branchbran 57.1% 8 / 14 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 5 totaltotal 77.5% 62 / 80 CC 10 SCAR 9.6
CC
10
Cov
83%
get_candidates
3.6
candidates
3.2
filter
3.1
CRAP 2.6
« lib/HTML/FormFu/Exception/Validator.pm ↑ Summary lib/HTML/FormFu/Filter/CompoundJoin.pm »
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
BranchTrueFalseTotal
unless defined $value 0 1 1
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
BranchTrueFalseTotal
unless defined $utf8 0 1 1
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
BranchTrueFalseTotal
if ($ret and wantarray) 1 0 1
Condition33%1/3
$ret and wantarray
!ll&&!rl&&r
001
MC/DC0%0/2
$ret and wantarray
$ret wantarray
Truth table33%1/3
A and B
A= $retB= wantarray
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if (@_ > 1) 1 0 1
46 1 ▶ if ( ref $candidates[0] eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $candidates[0] eq 'ARRAY') { } 0 1 1
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
BranchTrueFalseTotal
unless ($@) 1 1 2
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
BranchTrueFalseTotal
unless ($enc) 0 1 1
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__
« lib/HTML/FormFu/Exception/Validator.pm ↑ Summary lib/HTML/FormFu/Filter/CompoundJoin.pm »