line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catan::Map::Path; |
2
|
|
|
|
|
|
|
$Catan::Map::Path::VERSION = '0.02'; |
3
|
3
|
|
|
3
|
|
13
|
use strict; |
|
3
|
|
|
1
|
|
6
|
|
|
3
|
|
|
|
|
73
|
|
|
1
|
|
|
|
|
919
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
4
|
3
|
|
|
3
|
|
14
|
use warnings; |
|
3
|
|
|
1
|
|
3
|
|
|
3
|
|
|
|
|
85
|
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
36
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use overload |
7
|
3
|
|
|
|
|
16
|
'""' => 'uuid', |
|
1
|
|
|
|
|
5
|
|
8
|
3
|
|
|
3
|
|
13
|
fallback => 1; |
|
3
|
|
|
1
|
|
6
|
|
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
2
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new |
11
|
|
|
|
|
|
|
{ |
12
|
0
|
|
|
0
|
0
|
|
my ($class, $intersections) = @_; |
13
|
0
|
0
|
0
|
|
|
|
die 'Path->new() requires an arrayref of 2 intersections' |
|
|
|
0
|
|
|
|
|
14
|
|
|
|
|
|
|
unless $intersections && ref $intersections eq 'ARRAY' && @$intersections == 2; |
15
|
|
|
|
|
|
|
|
16
|
0
|
0
|
|
|
|
|
die 'Path->new() start and end intersections must be adjacent' |
17
|
|
|
|
|
|
|
unless $intersections->[0]->is_adjacent($intersections->[1]); |
18
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
bless { |
20
|
|
|
|
|
|
|
uuid => join(' ', sort $intersections->[0]->uuid, $intersections->[1]->uuid), |
21
|
|
|
|
|
|
|
start => $intersections->[0], |
22
|
|
|
|
|
|
|
end => $intersections->[1], |
23
|
|
|
|
|
|
|
}, $class; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
0
|
0
|
|
sub start { $_[0]->{start} } |
27
|
0
|
|
|
0
|
0
|
|
sub end { $_[0]->{end} } |
28
|
0
|
|
|
0
|
0
|
|
sub uuid { $_[0]->{uuid} } |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub is_adjacent |
31
|
|
|
|
|
|
|
{ |
32
|
0
|
|
|
0
|
0
|
|
my ($self, $obj) = @_; |
33
|
|
|
|
|
|
|
|
34
|
0
|
0
|
0
|
|
|
|
die 'is_adjacent requires an intersection or path argument' |
|
|
|
0
|
|
|
|
|
35
|
|
|
|
|
|
|
unless $obj && |
36
|
|
|
|
|
|
|
($obj->isa('Catan::Map::Intersection') |
37
|
|
|
|
|
|
|
|| $obj->isa('Catan::Map::Path')); |
38
|
|
|
|
|
|
|
|
39
|
0
|
0
|
|
|
|
|
if ($obj->isa('Catan::Map::Intersection')) |
|
|
0
|
|
|
|
|
|
40
|
|
|
|
|
|
|
{ |
41
|
0
|
|
0
|
|
|
|
return $obj eq $self->{start} || $obj eq $self->{end}; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
elsif ($obj->isa('Catan::Map::Path')) |
44
|
|
|
|
|
|
|
{ |
45
|
0
|
0
|
|
|
|
|
return 0 if $self->is_colliding($obj); |
46
|
|
|
|
|
|
|
return $obj->{start} eq $self->{start} || $obj->{start} eq $self->{end} |
47
|
0
|
|
0
|
|
|
|
|| $obj->{end} eq $self->{start} || $obj->{end} eq $self->{end}; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub is_colliding |
52
|
|
|
|
|
|
|
{ |
53
|
0
|
|
|
0
|
0
|
|
my ($self, $obj) = @_; |
54
|
|
|
|
|
|
|
|
55
|
0
|
0
|
0
|
|
|
|
die 'is_colliding requires a path argument' |
56
|
|
|
|
|
|
|
unless $obj && $obj->isa('Catan::Map::Path'); |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
return $obj eq $self; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
1; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
__END__ |