Debian Codegraph @

lemonldap-ng-common/lib/Lemonldap/NG/Common/EmailAddress.pm

raw
1 package Lemonldap::NG::Common::EmailAddress;
2
3 use strict;
4 use Exporter;
5
6 our @ISA = qw(Exporter);
7 our $VERSION = '2.0.0';
8
9 our @EXPORT_OK = qw(format_email);
10 our @EXPORT = qw(format_email);
11
12 my $module;
13
14 BEGIN {
15 eval {
16 require Email::Address::XS;
17 $module = 'Email::Address::XS';
18 };
19 if ($@) {
20 eval {
21 require Email::Address;
22 $module = 'Email::Address';
23 };
24 die "Unable to find Email::Address, neither Email::Address::XS: $@"
25 if ($@);
26 }
27 }
28
29 sub format_email {
30 my ( $name, $email ) = @_;
31 my $obj = $module->new( $name, $email );
32 return $obj->as_string;
33 }
34
35 1;