This repository was archived by the owner on Jan 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEmpire.pm
More file actions
77 lines (59 loc) · 1.3 KB
/
Empire.pm
File metadata and controls
77 lines (59 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package Empire;
use Moose;
use LazyObjectPool;
has [qw( id name status_message home_planet_id )] => (
is => 'ro',
isa => 'Str',
);
has [qw(
has_new_messages
essentia
)] => (
is => 'ro',
isa => 'Int',
);
has is_isolationist => (
is => 'ro',
isa => 'Bool',
);
has planets => (
isa => 'LazyObjectPool',
handles => {
planets => 'members',
get_planet => 'get',
planet_ids => 'keys',
has_planet => 'has',
},
);
has newest_message => (
is => 'ro',
isa => 'Message',
);
sub home_planet {
my $self = shift;
my $p = $self->get_planet( $self->home_planet_id );
return $p;
}
sub get_mine {
my $class = shift;
my $client = shift;
my $es = $client->get_empire_status;
my $d = $es->data;
my %args;
{ my @attrs = qw(
id name is_isolationist home_planet_id
status_message has_new_messages essentia
);
@args{@attrs} = @{$d}{@attrs};
$args{planets} = LazyObjectPool->new(
client => $client,
class => 'Body',
builder => 'new_from_id',
store => [ keys %{$d->{planets}} ],
);
}
return $class->new( %args );
}
__PACKAGE__->meta->make_immutable;
no Moose;
1;