MuForm/Field/Email.pm

filter: Statementstmt 82.1% 23 / 28 Branchbran 66.6% 4 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 6 / 8 Podpod 0.0% 0 / 2 totaltotal 75.0% 33 / 44 SCAR 14.2
CC
4
Cov
79%
__ANON__
3.1
get_class_messages
2.0
__ANON__
2.0
CRAP 4.1
« MuForm/Field/Password.pm ↑ Summary MuForm/Field/Currency.pm »
1 package Data::MuForm::Field::Email;
2 # ABSTRACT: validates email using Email::Valid
3  
4 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 extends 'Data::MuForm::Field::Text';
6 2 ▶use Types::Standard -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use Email::Valid;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 our $class_messages = {
11 'email_format' => 'Email should be of the format [_1]',
12 };
13  
14 2 has '+html5_input_type' => ( default => 'email' );
15 2 has 'email_valid_params' => ( is => 'rw', isa => HashRef );
16 2 has 'preserve_case' => ( is => 'rw' );
17  
18 sub get_class_messages {
19 0 ▶ my $self = shift;
Subroutine get_class_messages: not called CC=1 SCAR=6.9
Pod undocumented
20 return {
21 0 %{ $self->next::method },
22 %$class_messages,
23 }
24 }
25  
26 sub build_base_apply {
27 [
28 {
29 transform => sub {
30 4 ▶ my ( $value, $field ) = @_;
Subroutine __ANON__: called CC=2 SCAR=6.9
31 4 ▶ return $value
Branch: 1 branch
BranchTrueFalseTotal
if $field->preserve_case 2 2 4
32 if $field->preserve_case;
33 2 return lc( $value );
34 }
35 },
36 {
37 check => sub {
38 4 ▶ my ( $value, $field ) = @_;
Subroutine __ANON__: called CC=3 SCAR=11.4
39 my $checked = Email::Valid->address(
40 4 ▶ %{ $field->email_valid_params || {} },
Branch: 1 branch
BranchTrueFalseTotal
$field->email_valid_params or {} 4 0 4
41 -address => $value,
42 );
43 4 ▶ $field->value($checked)
Branch: 1 branch
BranchTrueFalseTotal
if $checked 4 0 4
44 if $checked;
45 },
46 message => sub {
47 0 ▶ my ( $value, $field ) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
48 0 return [$field->get_message('email_format'), 'someuser@example.com'];
49 },
50 }
51 2 ▶ ]
Subroutine build_base_apply: called CC=1 SCAR=0.0
Pod undocumented
52 }
53  
54  
55 2 1;
56  
57 __END__
58  
59 =pod
60  
61 =encoding UTF-8
62  
63 =head1 NAME
64  
65 Data::MuForm::Field::Email - validates email using Email::Valid
66  
67 =head1 VERSION
68  
69 version 0.04
70  
71 =head1 DESCRIPTION
72  
73 Validates that the input looks like an email address using L<Email::Valid>.
74 Widget type is 'text'.
75  
76 If form has 'is_html5' flag active it will render <input type="email" ... />
77 instead of type="text"
78  
79 This field has an 'email_valid_params' attribute that accepts a hash
80 reference of extra values passed to L<Email::Valid/address> when
81 validating email addresses.
82  
83 If you want to preserve the case of the email address, set the
84 'preserve_case' attribute.
85  
86 =head1 DEPENDENCIES
87  
88 L<Email::Valid>
89  
90 =head1 AUTHOR
91  
92 Gerda Shank
93  
94 =head1 COPYRIGHT AND LICENSE
95  
96 This software is copyright (c) 2017 by Gerda Shank.
97  
98 This is free software; you can redistribute it and/or modify it under
99 the same terms as the Perl 5 programming language system itself.
100  
101 =cut
« MuForm/Field/Password.pm ↑ Summary MuForm/Field/Currency.pm »