File Coverage

blib/lib/Mo/utils/Email.pm
Criterion Covered Total %
statement 25 25 100.0
branch 4 4 100.0
condition n/a
subroutine 7 7 100.0
pod 1 1 100.0
total 37 37 100.0


line stmt bran cond sub pod time code
1             package Mo::utils::Email;
2              
3 3     3   121800 use base qw(Exporter);
  3         4  
  3         418  
4 3     3   25 use strict;
  3         9  
  3         97  
5 3     3   18 use warnings;
  3         5  
  3         211  
6              
7 3     3   1930 use Email::Valid;
  3         490042  
  3         251  
8 3     3   1463 use Error::Pure qw(err);
  3         19585  
  3         75  
9 3     3   211 use Readonly;
  3         6  
  3         632  
10              
11             Readonly::Array our @EXPORT_OK => qw(check_email);
12              
13             our $VERSION = 0.02;
14              
15             sub check_email {
16 4     4 1 434132 my ($self, $key) = @_;
17              
18 4 100       20 if (! exists $self->{$key}) {
19 1         4 return;
20             }
21              
22 3         31 my $address = Email::Valid->address($self->{$key});
23 3 100       6307 if (! $address) {
24             err "Parameter '".$key."' doesn't contain valid email.",
25 1         11 'Value', $self->{$key},
26             ;
27             }
28              
29 2         11 return;
30             }
31              
32             1;
33              
34             __END__
35              
36             =pod
37              
38             =encoding utf8
39              
40             =head1 NAME
41              
42             Mo::utils::Email - Mo utilities for email.
43              
44             =head1 SYNOPSIS
45              
46             use Mo::utils::Email qw(check_email);
47              
48             check_email($self, $key);
49              
50             =head1 DESCRIPTION
51              
52             Mo utilities for email checking of data objects.
53              
54             =head1 SUBROUTINES
55              
56             =head2 C<check_email>
57              
58             check_email($self, $key);
59              
60             Check parameter defined by C<$key> which is valid email.
61              
62             Put error if check isn't ok.
63              
64             Returns undef.
65              
66             =head1 ERRORS
67              
68             check_email():
69             Parameter '%s' doesn't contain valid email.
70             Value: %s
71              
72             =head1 EXAMPLE1
73              
74             =for comment filename=check_email_ok.pl
75              
76             use strict;
77             use warnings;
78              
79             use Mo::utils::Email qw(check_email);
80              
81             my $self = {
82             'key' => 'michal.josef.spacek@gmail.com',
83             };
84             check_email($self, 'key');
85              
86             # Print out.
87             print "ok\n";
88              
89             # Output:
90             # ok
91              
92             =head1 EXAMPLE2
93              
94             =for comment filename=check_email_fail.pl
95              
96             use strict;
97             use warnings;
98              
99             use Error::Pure;
100             use Mo::utils::Email qw(check_email);
101              
102             $Error::Pure::TYPE = 'Error';
103              
104             my $self = {
105             'key' => 'michal.josef.špaček@gmail.com',
106             };
107             check_email($self, 'key');
108              
109             # Print out.
110             print "ok\n";
111              
112             # Output like:
113             # #Error [..utils.pm:?] Parameter 'key' doesn't contain valid email.
114              
115             =head1 DEPENDENCIES
116              
117             L<Email::Valid>,
118             L<Error::Pure>,
119             L<Exporter>,
120             L<Readonly>.
121              
122             =head1 SEE ALSO
123              
124             =over
125              
126             =item L<Mo>
127              
128             Micro Objects. Mo is less.
129              
130             =item L<Mo::utils::Language>
131              
132             Mo language utilities.
133              
134             =item L<Wikibase::Datatype::Utils>
135              
136             Wikibase datatype utilities.
137              
138             =back
139              
140             =head1 REPOSITORY
141              
142             L<https://github.com/michal-josef-spacek/Mo-utils-Email>
143              
144             =head1 AUTHOR
145              
146             Michal Josef Špaček L<mailto:skim@cpan.org>
147              
148             L<http://skim.cz>
149              
150             =head1 LICENSE AND COPYRIGHT
151              
152             © 2023-2024 Michal Josef Špaček
153              
154             BSD 2-Clause License
155              
156             =head1 VERSION
157              
158             0.02
159              
160             =cut