File Coverage

blib/lib/Data/Validate/WithYAML/Plugin/EMail.pm
Criterion Covered Total %
statement 18 18 100.0
branch 4 4 100.0
condition n/a
subroutine 5 5 100.0
pod 1 1 100.0
total 28 28 100.0


line stmt bran cond sub pod time code
1             package Data::Validate::WithYAML::Plugin::EMail;
2              
3 3     3   1204498 use warnings;
  3         22  
  3         103  
4 3     3   18 use strict;
  3         7  
  3         97  
5              
6 3     3   19 use Carp;
  3         6  
  3         206  
7 3     3   1612 use Regexp::Common qw[Email::Address];
  3         12284  
  3         14  
8              
9             # ABSTRACT: Plugin for Data::Validate::WithYAML to check email addresses
10              
11             our $VERSION = '0.04';
12              
13             sub check {
14 12     12 1 3795 my ($class, $value) = @_;
15              
16 12 100       209 croak "no value to check" unless defined $value;
17              
18 11         20 my $return = 0;
19 11 100       54 if( $value =~ /($RE{Email}{Address})/ ){
20 8         1849 $return = 1;
21             }
22              
23 11         465 return $return;
24             }
25              
26              
27             1; # End of Data::Validate::WithYAML::Plugin::EMail
28              
29             __END__
30              
31             =pod
32              
33             =encoding UTF-8
34              
35             =head1 NAME
36              
37             Data::Validate::WithYAML::Plugin::EMail - Plugin for Data::Validate::WithYAML to check email addresses
38              
39             =head1 VERSION
40              
41             version 0.04
42              
43             =head1 SYNOPSIS
44              
45             use Data::Validate::WithYAML::Plugin::EMail;
46              
47             my $foo = Data::Validate::WithYAML::Plugin::EMail->check( 'test@exampl.com' );
48             ...
49            
50             # use the plugin via Data::Validate::WithYAML
51            
52             use Data::Validate::WithYAML;
53            
54             my $email = 'test@exampl.com';
55             my $validator = Data::Validate::WithYAML->new( 'test.yml' );
56             print "yes" if $validator->check( 'email', $email );
57              
58             test.yml
59              
60             ---
61             step1:
62             email:
63             plugin: EMail
64             type: required
65              
66             =head1 SUBROUTINES
67              
68             =head2 check
69              
70             =head1 AUTHOR
71              
72             Renee Baecker <reneeb@cpan.org>
73              
74             =head1 COPYRIGHT AND LICENSE
75              
76             This software is Copyright (c) 2015 by Renee Baecker.
77              
78             This is free software, licensed under:
79              
80             The Artistic License 2.0 (GPL Compatible)
81              
82             =cut