File Coverage

blib/lib/Email/Sample.pm
Criterion Covered Total %
statement 27 31 87.1
branch n/a
condition 2 4 50.0
subroutine 8 11 72.7
pod 2 8 25.0
total 39 54 72.2


line stmt bran cond sub pod time code
1             package Email::Sample;
2              
3 1     1   30974 use warnings;
  1         2  
  1         33  
4 1     1   5 use strict;
  1         3  
  1         32  
5 1     1   991 use Data::Random qw(:all);
  1         3788  
  1         583  
6             # use Text::Greeking;
7              
8              
9             =head1 NAME
10              
11             Email::Sample - generate sample email for testing
12              
13             =head1 VERSION
14              
15             Version 0.01
16              
17             =cut
18              
19             our $VERSION = '0.01';
20              
21             =head1 SYNOPSIS
22              
23             use Email::Sample;
24              
25             my $emailgen = Email::Sample->new();
26             ...
27              
28             $emailgen->add_valid_domains( [ 'url.com.tw' , 'google2.com.tw' ] );
29              
30             my @valid_emails = $emailgen->valid_emails( size => 20 );
31              
32             my @invalid_emails = $emailgen->invalid_emails();
33              
34             =head1 DESCRIPTION
35              
36             Email::Sample use L to generate a bunch of valid or invalid email
37             for testing.
38              
39             =head1 FUNCTIONS
40              
41             =cut
42              
43             sub new {
44 1     1 0 175 my $class = shift;
45 1         3 my $self = {};
46 1         4 return bless $self, $class;
47             }
48              
49             =head2 valid_emails
50              
51             =cut
52              
53             my @valid_domains = qw(
54             yahoo.com
55             gmail.com
56             );
57              
58             sub valid_emails {
59 1     1 1 5 my $self = shift;
60 1         4 my %args = @_;
61              
62 1   50     4 $args{size} ||= 10;
63 1         2 my @emails = ();
64 1         4 for( 1 .. $args{size} ) {
65 20         69 push @emails, $self->g_valid_identity() . '@' . $self->get_random_valid_domain;
66             }
67 1         11 return \@emails;
68             }
69              
70             sub add_domains {
71 0     0 0 0 my $self = shift;
72 0         0 $self->add_valid_domains(@_);
73             }
74              
75             =head2 add_valid_domains (ARRAY)
76              
77             =cut
78              
79             sub add_valid_domains {
80 1     1 1 7 my $class = shift;
81 1         3 push @valid_domains , @_;
82             }
83              
84 0     0 0 0 sub add_invalid_domains {
85              
86             }
87              
88             sub get_random_valid_domain {
89 20     20 0 164 return $valid_domains[
90             int( rand( scalar(@valid_domains) - 1 ) )
91             ];
92             }
93              
94             sub g_valid_identity {
95 20     20 0 41 my $self = shift;
96 20         44 my %args = @_;
97 20   50     192 $args{seperator} ||= '_';
98 20         83 my @random_words = rand_words( size => 3 );
99 20         2720938 return join( $args{seperator} , @random_words );
100             }
101              
102             sub g_invalid_identity {
103 0     0 0   my ($self, %args ) = @_;
104              
105             }
106              
107              
108              
109             =head1 AUTHOR
110              
111             Cornelius, C<< >>
112              
113             =head1 BUGS
114              
115             Please report any bugs or feature requests to C, or through
116             the web interface at L. I will be notified, and then you'll
117             automatically be notified of progress on your bug as I make changes.
118              
119              
120              
121              
122             =head1 SUPPORT
123              
124             You can find documentation for this module with the perldoc command.
125              
126             perldoc Email::Sample
127              
128              
129             You can also look for information at:
130              
131             =over 4
132              
133             =item * RT: CPAN's request tracker
134              
135             L
136              
137             =item * AnnoCPAN: Annotated CPAN documentation
138              
139             L
140              
141             =item * CPAN Ratings
142              
143             L
144              
145             =item * Search CPAN
146              
147             L
148              
149             =back
150              
151              
152             =head1 ACKNOWLEDGEMENTS
153              
154              
155             =head1 COPYRIGHT & LICENSE
156              
157             Copyright 2009 Cornelius, all rights reserved.
158              
159             This program is released under the following license: MIT
160              
161              
162             =cut
163              
164             1; # End of Email::Sample