File Coverage

blib/lib/MooseX/Types/EmailAddress.pm
Criterion Covered Total %
statement 13 15 86.6
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 18 20 90.0


line stmt bran cond sub pod time code
1             package MooseX::Types::EmailAddress; # -*-perl-*-
2 1     1   829 use strict;
  1         2  
  1         44  
3 1     1   7 use warnings;
  1         2  
  1         46  
4              
5             our $VERSION = '1.1.2';
6              
7 1     1   8991 use Email::Address ();
  1         37623  
  1         83  
8 1     1   1051 use Email::Valid ();
  1         133275  
  1         42  
9              
10 1     1   641 use MooseX::Types -declare => [qw(EmailAddress EmailAddressList)];
  0            
  0            
11             use MooseX::Types::Moose qw(Str ArrayRef);
12              
13             subtype EmailAddress,
14             as Str,
15             where { Email::Valid->address( -address => $_ ) },
16             message { 'Must be a valid email address' };
17              
18             subtype EmailAddressList,
19             as ArrayRef[EmailAddress];
20              
21             coerce EmailAddressList,
22             from Str,
23             via { [ map { $_->format } Email::Address->parse($_) ] },
24             from ArrayRef,
25             via { [ map { $_->format } map { Email::Address->parse($_) } @{$_} ] };
26              
27             1;
28             __END__
29              
30             =head1 NAME
31              
32             MooseX::Types::EmailAddress - Valid email address type constraint for Moose.
33              
34             =head1 VERSION
35              
36             This documentation refers to MooseX::Types::EmailAddress version 1.1.2
37              
38             =head1 SYNOPSIS
39              
40             package FooBar;
41             use Moose;
42             use MooseX::Types::EmailAddress qw/EmailAddress EmailAddressList/;
43             use namespace::autoclean;
44              
45             has address => ( isa => EmailAddress, required => 1, is => "ro" );
46              
47             has addrlist => (
48             traits => ["Array"],
49             is => "ro",
50             isa => EmailAddressList,
51             coerce => 1,
52             default => sub { [] },
53             handles => {
54             "addr_count" => "count",
55             }
56             );
57              
58             =head1 DESCRIPTION
59              
60             This module provides Moose type constraints for valid email
61             addresses. There is support for a type which represents a single valid
62             email address and a type which represents a list of valid email
63             addresses. The validation is done using the L<Email::Valid> module.
64              
65             This module is similar to L<MooseX::Types::Email> but deliberately
66             focuses only on email addresses. This module also provides an
67             additional type to handle lists of addresses.
68              
69             =head1 DEPENDENCIES
70              
71             This module requires L<MooseX::Types> to build the Moose types. It
72             uses L<Email::Valid> to check if a string is a valid email address. It
73             also uses L<Email::Address> for parsing and splitting strings which
74             might contain more than one address into a list.
75              
76             =head1 SEE ALSO
77              
78             L<Moose>, L<Moose::Util::TypeConstraints>, L<MooseX::Types::Email>
79              
80             =head1 PLATFORMS
81              
82             This is the list of platforms on which we have tested this
83             software. We expect this software to work on any Unix-like platform
84             which is supported by Perl.
85              
86             ScientificLinux6
87              
88             =head1 BUGS AND LIMITATIONS
89              
90             If you find a bug please either email the author, or add
91             the bug to cpan-RT L<http://rt.cpan.org>.
92              
93             =head1 AUTHOR
94              
95             Stephen Quinney C<< <squinney@inf.ed.ac.uk> >>
96              
97             =head1 LICENSE AND COPYRIGHT
98              
99             Copyright (C) 2012-2013 University of Edinburgh. All rights reserved.
100              
101             This library is free software; you can redistribute it and/or modify
102             it under the terms of the GPL, version 2 or later.
103              
104             =cut