line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Acme::POE::Acronym::Generator; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$Acme::POE::Acronym::Generator::VERSION = '1.20'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
#ABSTRACT: Generate random POE acronyms. |
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
104424
|
use strict; |
|
3
|
|
|
|
|
10
|
|
|
3
|
|
|
|
|
134
|
|
9
|
3
|
|
|
3
|
|
19
|
use warnings; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
94
|
|
10
|
3
|
|
|
3
|
|
3110
|
use Math::Random; |
|
3
|
|
|
|
|
24228
|
|
|
3
|
|
|
|
|
1822
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
3
|
|
|
3
|
1
|
54
|
my $package = shift; |
14
|
3
|
|
|
|
|
13
|
my %opts = @_; |
15
|
3
|
|
|
|
|
26
|
$opts{lc $_} = delete $opts{$_} for keys %opts; |
16
|
3
|
100
|
|
|
|
20
|
$opts{dict} = '/usr/share/dict/words' unless $opts{dict}; |
17
|
3
|
50
|
|
|
|
16
|
$opts{key} =~ s/[^A-Za-z]//g if $opts{key}; |
18
|
3
|
50
|
|
|
|
20
|
$opts{key} = lc $opts{key} if $opts{key}; |
19
|
3
|
|
|
|
|
15
|
my $self = bless \%opts, $package; |
20
|
|
|
|
|
|
|
|
21
|
3
|
50
|
|
|
|
43
|
$self->{poe} = [ $opts{key}? split( //, $opts{key} ) : qw(p o e) ]; |
22
|
3
|
|
|
|
|
7
|
my $key = join '', @{$self->{poe}}; |
|
3
|
|
|
|
|
12
|
|
23
|
|
|
|
|
|
|
|
24
|
3
|
100
|
66
|
|
|
24
|
if ( $opts{wordlist} and ref $opts{wordlist} eq 'ARRAY' ) { |
25
|
1
|
|
|
|
|
2
|
for ( @{ $opts{wordlist} } ) { |
|
1
|
|
|
|
|
3
|
|
26
|
11
|
|
|
|
|
18
|
chomp; |
27
|
11
|
50
|
|
|
|
68
|
next unless /^[$key]\w+$/; |
28
|
11
|
|
|
|
|
14
|
push @{ $self->{words}->{ substr($_,0,1) } }, $_; |
|
11
|
|
|
|
|
34
|
|
29
|
|
|
|
|
|
|
} |
30
|
1
|
|
|
|
|
4
|
return $self; |
31
|
|
|
|
|
|
|
} |
32
|
2
|
50
|
|
|
|
69
|
if ( -e $opts{dict} ) { |
33
|
0
|
0
|
|
|
|
0
|
open FH, "< $self->{dict}" or die "$!\n"; |
34
|
0
|
|
|
|
|
0
|
while () { |
35
|
0
|
|
|
|
|
0
|
chomp; |
36
|
0
|
0
|
|
|
|
0
|
next unless /^[$key]\w+$/i; |
37
|
|
|
|
|
|
|
# next unless /^[poe]\w+$/; |
38
|
0
|
|
|
|
|
0
|
push @{ $self->{words}->{ substr($_,0,1) } }, $_; |
|
0
|
|
|
|
|
0
|
|
39
|
|
|
|
|
|
|
} |
40
|
0
|
|
|
|
|
0
|
close FH; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
else { |
43
|
2
|
|
|
|
|
22
|
$self->{words} = |
44
|
|
|
|
|
|
|
{ |
45
|
|
|
|
|
|
|
'p' => [ qw(pickle purple parallel pointed pikey) ], |
46
|
|
|
|
|
|
|
'o' => [ qw(orange oval ostrich olive) ], |
47
|
|
|
|
|
|
|
'e' => [ qw(event enema evening elephant) ], |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
} |
50
|
2
|
|
|
|
|
9
|
return $self; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub generate { |
54
|
6
|
|
|
6
|
1
|
6554
|
my $self = shift; |
55
|
6
|
|
|
|
|
14
|
my $words = $self->{words}; |
56
|
6
|
|
|
|
|
11
|
my @poe; |
57
|
18
|
|
|
|
|
212
|
push @poe, |
58
|
6
|
|
|
|
|
10
|
ucfirst( $words->{$_}->[ scalar random_uniform_integer(1,0,scalar @{ $words->{$_} }-1 ) ] ) for ( @{$self->{poe}} ); |
|
6
|
|
|
|
|
24
|
|
59
|
6
|
100
|
|
|
|
165
|
return wantarray ? @poe : join( ' ', @poe ); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
1; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
__END__ |