File Coverage

blib/lib/Data/RandomPerson/Names.pm
Criterion Covered Total %
statement 30 30 100.0
branch 1 2 50.0
condition n/a
subroutine 8 8 100.0
pod 3 3 100.0
total 42 43 97.6


line stmt bran cond sub pod time code
1             package Data::RandomPerson::Names;
2              
3 5     5   23 use strict;
  5         7  
  5         146  
4 5     5   17 use warnings;
  5         6  
  5         90  
5              
6 5     5   1364 use Data::RandomPerson::Choice;
  5         10  
  5         135  
7 5     5   2007 use File::Share ':all';
  5         34412  
  5         1906  
8              
9             sub new {
10 34     34 1 8724 my ($class) = @_;
11              
12 34         92 my $self = bless {}, $class;
13              
14 34         146 $self->{choice} = Data::RandomPerson::Choice->new();
15              
16 34         116 my $module = (split /::/, $class)[-1];
17              
18 34         122 my $file = dist_file ('Data-RandomPerson', $module . '.txt');
19 5 50   5   41 open ( my $fh, '< :encoding(UTF8)', $file) or die "Can't open '$file': $!";
  5         7  
  5         33  
  34         5150  
20 34         54654 my @file = <$fh>;
21 34         132279 close $fh;
22              
23 34         11087 chomp (@file);
24 34         3086 $self->{choice}->add_list(@file);
25              
26 34         8133 return $self;
27             }
28              
29             sub size {
30 31     31 1 20007 my ($self) = @_;
31              
32 31         94 return $self->{choice}->size();
33             }
34              
35             sub get {
36 1540     1540 1 6380 my ($self) = @_;
37              
38 1540         2396 return ucfirst $self->{choice}->pick();
39             }
40              
41             1;
42              
43             __END__