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 SCAR 22.2
CC
9
Cov
87%
constrain_value
9.8
__ANON__
1.0
BEGIN
1.0
CRAP 9.2
« lib/HTML/FormFu/Constraint/Regex.pm ↑ Summary lib/HTML/FormFu/Transformer.pm »
1 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package HTML::FormFu::Constraint::File::MIME;
4 2 $HTML::FormFu::Constraint::File::MIME::VERSION = '2.06';
5 # ABSTRACT: MIME Type Constraint
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::Constraint';
10  
11 2 ▶use List::Util 1.33 qw( any );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 has regex => ( is => 'rw', traits => ['Chained'] );
15 2 has types => ( is => 'rw', traits => ['Chained'] );
16  
17 sub constrain_value {
18 4 ▶ my ( $self, $value ) = @_;
Subroutine constrain_value: called CC=9 SCAR=22.9
Pod undocumented
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 2 __PACKAGE__->meta->make_immutable;
44  
45 2 1;
46  
47 __END__
48  
49 =pod
50  
51 =encoding UTF-8
52  
53 =head1 NAME
54  
55 HTML::FormFu::Constraint::File::MIME - MIME Type Constraint
56  
57 =head1 VERSION
58  
59 version 2.06
60  
61 =head1 DESCRIPTION
62  
63 Constraint an uploaded file's MIME-type (Content-Type).
64  
65 L</types> is checked before L</regex>.
66  
67 =head1 METHODS
68  
69 =head2 types
70  
71 Arguments: $mime_type
72  
73 Arguments: \@mime_types
74  
75 Optional.
76  
77 Accepts a single MIME-type or an arrayref of MIME-types. Each is checked
78 against the uploaded file's MIME-type (as given by the browser), and the
79 constraint passes if any one of the given types matches.
80  
81 =head2 regex
82  
83 Arguments: $regex
84  
85 Optional.
86  
87 Accepts a string to be interpreted as a regex, and is checked against the
88 uploaded files's MIME-type (as given by the browser).
89  
90 The regex uses the C</x> flag, so that whitespace in the given string is
91 ignored.
92  
93 =head1 SEE ALSO
94  
95 Is a sub-class of, and inherits methods from L<HTML::FormFu::Constraint>
96  
97 L<HTML::FormFu>
98  
99 =head1 AUTHOR
100  
101 Carl Franks, C<cfranks@cpan.org>
102  
103 =head1 LICENSE
104  
105 This library is free software, you can redistribute it and/or modify it under
106 the same terms as Perl itself.
107  
108 =head1 AUTHOR
109  
110 Carl Franks <cpan@fireartist.com>
111  
112 =head1 COPYRIGHT AND LICENSE
113  
114 This software is copyright (c) 2018 by Carl Franks.
115  
116 This is free software; you can redistribute it and/or modify it under
117 the same terms as the Perl 5 programming language system itself.
118  
119 =cut
« lib/HTML/FormFu/Constraint/Regex.pm ↑ Summary lib/HTML/FormFu/Transformer.pm »