lib/HTML/FormFu/Constraint/File/MIME.pm

filter: Statementstmt 94.2% 33 / 35 Branchbran 75.0% 9 / 12 Conditioncond 66.6% 4 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 1 totaltotal 84.6% 55 / 65 CC 9 SCAR 18.4
CC
9
Cov
87%
constrain_value
9.8
__ANON__
1.0
BEGIN
1.0
CRAP 6.3
« lib/HTML/FormFu/Constraint/File/Size.pm ↑ Summary lib/HTML/FormFu/Role/Element/SingleValueField.pm »
1 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package HTML::FormFu::Constraint::File::MIME;
4 4 $HTML::FormFu::Constraint::File::MIME::VERSION = '2.09';
5 # ABSTRACT: MIME Type Constraint
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::Constraint';
10  
11 4 ▶use List::Util 1.33 qw( any );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 4 has regex => ( is => 'rw', traits => ['Chained'] );
15 4 has types => ( is => 'rw', traits => ['Chained'] );
16  
17 4 ▶sub constrain_value {
Subroutine constrain_value: called CC=9 SCAR=22.9
Pod undocumented
18 4 my ( $self, $value ) = @_;
19  
20 4 ▶ return 1 if !defined $value || $value eq '';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $value or $value eq "" 1 3 4
Condition66%2/3
not defined $value or $value eq ""
l!l&&r!l&&!r
103
MC/DC50%1/2
not defined $value or $value eq ""
not defined $value $value eq ""
Truth table66%2/3
not(A) or B
A= not defined $valueB= $value eq ""
ABresult
1X1
011
000
21  
22 3 ▶ return if !blessed($value) || !$value->isa('HTML::FormFu::Upload');
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($value) and $value->isa("HTML::FormFu::Upload") 1 2 3
Condition66%2/3
builtin::blessed($value) and $value->isa("HTML::FormFu::Upload")
!ll&&!rl&&r
102
MC/DC50%1/2
builtin::blessed($value) and $value->isa("HTML::FormFu::Upload")
builtin::blessed($value) $value->isa("HTML::FormFu::Upload")
Truth table66%2/3
A and B
A= builtin::blessed($value)B= $value->isa("HTML::FormFu::Upload")
ABresult
0X0
100
111
23  
24 2 my $input = $value->headers->content_type;
25 2 my $types = $self->types;
26 2 my $regex = $self->regex;
27  
28 2 ▶ if ( defined $types ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $types) 1 1 2
29 1 ▶ if ( ref $types ne 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $types ne "ARRAY") 0 1 1
30 0 $types = [$types];
31 }
32  
33 1 ▶ return 1 if any { $input eq $_ } @$types;
Subroutine __ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
if &any(sub { $input eq $_; } , @$types) 1 0 1
34 }
35  
36 1 ▶ if ( defined $regex ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $regex) 1 0 1
37 1 return $input =~ /$regex/x;
38 }
39  
40 0 return;
41 }
42  
43 4 __PACKAGE__->meta->make_immutable;
44  
45 4 1;
46  
47 __END__
« lib/HTML/FormFu/Constraint/File/Size.pm ↑ Summary lib/HTML/FormFu/Role/Element/SingleValueField.pm »