line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package AI::Pathfinding::SMAstar::Examples::WordObj; |
2
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
472
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
################################################## |
5
|
|
|
|
|
|
|
## the object constructor (simplistic version) ## |
6
|
|
|
|
|
|
|
################################################## |
7
|
|
|
|
|
|
|
sub new { |
8
|
47
|
|
|
47
|
0
|
55
|
my $invocant = shift; |
9
|
47
|
|
33
|
|
|
141
|
my $class = ref($invocant) || $invocant; |
10
|
47
|
|
|
|
|
130
|
my $self = { |
11
|
|
|
|
|
|
|
_word => undef, |
12
|
|
|
|
|
|
|
@_, # Override previous attributes |
13
|
|
|
|
|
|
|
}; |
14
|
47
|
|
|
|
|
179
|
return bless $self, $class; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
############################################## |
18
|
|
|
|
|
|
|
## methods to access per-object data ## |
19
|
|
|
|
|
|
|
## ## |
20
|
|
|
|
|
|
|
## With args, they set the value. Without ## |
21
|
|
|
|
|
|
|
## any, they only retrieve it/them. ## |
22
|
|
|
|
|
|
|
############################################## |
23
|
|
|
|
|
|
|
sub word { |
24
|
80
|
|
|
80
|
0
|
1391
|
my $self = shift; |
25
|
80
|
50
|
|
|
|
145
|
if (@_) { $self->{_word} = shift } |
|
0
|
|
|
|
|
0
|
|
26
|
80
|
|
|
|
|
213
|
return $self->{_word}; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# compare |
32
|
|
|
|
|
|
|
# |
33
|
|
|
|
|
|
|
# usage: $word_obj->compare($other_word_obj) |
34
|
|
|
|
|
|
|
# |
35
|
|
|
|
|
|
|
# Accepts another WordObj object as an argument. |
36
|
|
|
|
|
|
|
# Returns 1 if greater than argument, 0 if equal, and -1 if |
37
|
|
|
|
|
|
|
# less than argument |
38
|
|
|
|
|
|
|
sub compare{ |
39
|
62
|
|
|
62
|
0
|
253
|
my ($self,$arg_wordobj) = @_; |
40
|
|
|
|
|
|
|
|
41
|
62
|
|
|
|
|
72
|
my $arg_word = $arg_wordobj->{_word}; |
42
|
62
|
|
|
|
|
65
|
my $word = $self->{_word}; |
43
|
|
|
|
|
|
|
|
44
|
62
|
100
|
|
|
|
129
|
if($arg_word gt $word){ |
|
|
100
|
|
|
|
|
|
45
|
41
|
|
|
|
|
88
|
return -1; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
elsif($arg_word eq $word){ |
48
|
3
|
|
|
|
|
6
|
return 0; |
49
|
|
|
|
|
|
|
} |
50
|
18
|
|
|
|
|
38
|
return 1; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# compare_up_to |
55
|
|
|
|
|
|
|
# |
56
|
|
|
|
|
|
|
# usage: $word_obj->compare_up_to($other_word_obj) |
57
|
|
|
|
|
|
|
# |
58
|
|
|
|
|
|
|
# Accepts another WordObj object as an argument. |
59
|
|
|
|
|
|
|
# Returns 1 if greater than argument, 0 if $other_word_obj |
60
|
|
|
|
|
|
|
# is a substring of $word_obj |
61
|
|
|
|
|
|
|
# that appears at the beginning of $word_obj |
62
|
|
|
|
|
|
|
# and -1 if less than argument $other_word_obj |
63
|
|
|
|
|
|
|
sub compare_up_to{ |
64
|
14
|
|
|
14
|
0
|
47
|
my $self = shift; |
65
|
14
|
50
|
|
|
|
34
|
if (@_){ |
66
|
14
|
|
|
|
|
19
|
my $arg_wordobj = shift; |
67
|
14
|
|
|
|
|
18
|
my $arg_word = $arg_wordobj->{_word}; |
68
|
14
|
|
|
|
|
14
|
my $word = $self->{_word}; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# perl's index function works like: index($string, $substr); |
71
|
14
|
100
|
|
|
|
59
|
if(index($word, $arg_word) == 0){ |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
72
|
2
|
|
|
|
|
5
|
return(0); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
elsif($arg_word gt $word){ |
75
|
9
|
|
|
|
|
23
|
return(-1); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
elsif($arg_word lt $word){ |
78
|
3
|
|
|
|
|
8
|
return(1); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# compare_up_to |
85
|
|
|
|
|
|
|
# |
86
|
|
|
|
|
|
|
# usage: $word_obj->compare_down_to($other_word_obj) |
87
|
|
|
|
|
|
|
# |
88
|
|
|
|
|
|
|
# Returns 0 if $word_obj is a substring of |
89
|
|
|
|
|
|
|
# $other_word_obj, that appears at the beginning |
90
|
|
|
|
|
|
|
# of $other_word_obj. |
91
|
|
|
|
|
|
|
# |
92
|
|
|
|
|
|
|
sub compare_down_to{ |
93
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
94
|
0
|
0
|
|
|
|
|
if (@_){ |
95
|
0
|
|
|
|
|
|
my $arg_wordobj = shift; |
96
|
0
|
|
|
|
|
|
my $arg_word = $arg_wordobj->{_word}; |
97
|
0
|
|
|
|
|
|
my $word = $self->{_word}; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# perl's index function works like: index($string, $substr); |
100
|
0
|
0
|
|
|
|
|
if(index($arg_word, $word) == 0){ |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
return(0); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
elsif($arg_word gt $word){ |
104
|
0
|
|
|
|
|
|
return(-1); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
elsif($arg_word lt $word){ |
107
|
0
|
|
|
|
|
|
return(1); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
1; # so the require or use succeeds |
118
|
|
|
|
|
|
|
|