File Coverage

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


line stmt bran cond sub pod time code
1             package Data::Validate::WithYAML::Plugin::EMail;
2              
3 3     3   1326457 use warnings;
  3         7  
  3         139  
4 3     3   15 use strict;
  3         7  
  3         84  
5              
6 3     3   11 use Carp;
  3         7  
  3         213  
7 3     3   1689 use Regexp::Common qw[Email::Address];
  3         10339  
  3         12  
8              
9             # ABSTRACT: Plugin for Data::Validate::WithYAML to check email addresses
10              
11             our $VERSION = '0.03';
12              
13             sub check {
14 11     11 1 2306 my ($class, $value) = @_;
15              
16 11 50       25 croak "no value to check" unless defined $value;
17              
18 11         12 my $return = 0;
19 11 100       47 if( $value =~ /($RE{Email}{Address})/ ){
20 8         1773 $return = 1;
21             }
22              
23 11         402 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.03
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