line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WordListBase::MetaSyntactic; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY |
4
|
|
|
|
|
|
|
our $DATE = '2020-05-23'; # DATE |
5
|
|
|
|
|
|
|
our $DIST = 'WordListBase-MetaSyntactic'; # DIST |
6
|
|
|
|
|
|
|
our $VERSION = '0.007'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
456
|
use strict 'subs', 'vars'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
480
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# IFUNBUILT |
11
|
|
|
|
|
|
|
# use Role::Tiny::With; |
12
|
|
|
|
|
|
|
# with 'WordListRole::WordList'; |
13
|
|
|
|
|
|
|
# END IFUNBUILT |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
1
|
|
|
1
|
0
|
93
|
my $package = shift; |
17
|
1
|
50
|
|
|
|
6
|
die "Must be subclassed by WordList::MetaSyntactic::*, not '$package'" |
18
|
|
|
|
|
|
|
unless $package =~ /\AWordList::MetaSyntactic::(\w+)\z/; |
19
|
1
|
|
|
|
|
460
|
require Acme::MetaSyntactic; |
20
|
1
|
|
|
|
|
2683
|
bless { |
21
|
|
|
|
|
|
|
# Acme::MetaSyntactic object |
22
|
|
|
|
|
|
|
_am => Acme::MetaSyntactic->new($1), |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
_iterator_idx => 0, |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# the whole array of words, for when iterating |
27
|
|
|
|
|
|
|
_all_words => undef, |
28
|
|
|
|
|
|
|
}, $package; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub each_word { |
32
|
1
|
|
|
1
|
0
|
28
|
my ($self, $code) = @_; |
33
|
|
|
|
|
|
|
|
34
|
1
|
|
|
|
|
7
|
for my $word (sort $self->{_am}->name(0)) { |
35
|
26
|
|
|
|
|
235
|
$code->($word); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub pick { |
40
|
1
|
|
|
1
|
0
|
4
|
my ($self, $n) = @_; |
41
|
|
|
|
|
|
|
|
42
|
1
|
|
50
|
|
|
8
|
$n ||= 1; |
43
|
1
|
|
|
|
|
5
|
$self->{_am}->name($n); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub word_exists { |
47
|
2
|
|
|
2
|
0
|
5
|
my ($self, $word) = @_; |
48
|
|
|
|
|
|
|
|
49
|
2
|
|
|
|
|
7
|
for my $w ($self->{_am}->name(0)) { |
50
|
46
|
100
|
|
|
|
147
|
return 1 if $word eq $w; |
51
|
|
|
|
|
|
|
} |
52
|
1
|
|
|
|
|
5
|
0; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub all_words { |
56
|
2
|
|
|
2
|
0
|
5
|
my ($self) = @_; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# A:M doesn't provide a method to get a sorted list, so we sort it ourselves |
59
|
2
|
|
|
|
|
8
|
sort $self->{_am}->name(0); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub reset_iterator { |
63
|
2
|
|
|
2
|
0
|
5
|
my $self = shift; |
64
|
2
|
|
|
|
|
5
|
$self->{_iterator_idx} = 0; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub next_word { |
68
|
3
|
|
|
3
|
0
|
11
|
my $self = shift; |
69
|
3
|
100
|
|
|
|
10
|
unless (defined $self->{_all_words}) { |
70
|
1
|
|
|
|
|
5
|
$self->{_all_words} = [$self->all_words]; |
71
|
|
|
|
|
|
|
} |
72
|
3
|
|
|
|
|
69
|
my $word = $self->{_all_words}[ $self->{_iterator_idx} ]; |
73
|
3
|
|
|
|
|
7
|
$self->{_iterator_idx}++; |
74
|
|
|
|
|
|
|
$self->{_iterator_idx} = 0 |
75
|
3
|
50
|
|
|
|
5
|
if $self->{_iterator_idx} > @{ $self->{_all_words} }; |
|
3
|
|
|
|
|
9
|
|
76
|
3
|
|
|
|
|
13
|
$word; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub first_word { |
80
|
1
|
|
|
1
|
0
|
815
|
my $self = shift; |
81
|
1
|
|
|
|
|
7
|
$self->reset_iterator; |
82
|
1
|
|
|
|
|
12
|
$self->next_word; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
1; |
86
|
|
|
|
|
|
|
# ABSTRACT: Base class for WordList::MetaSyntactic::* |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
__END__ |