This repository has been archived by the owner on Jan 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBuilding.pm
88 lines (64 loc) · 1.38 KB
/
Building.pm
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
78
79
80
81
82
83
84
85
86
87
88
package Building;
use Moose;
use Point;
use WorkInProgress;
use Carp qw( croak );
use overload '""' => \&as_string;
has name => (
is => 'ro',
isa => 'Str',
lazy_build => 1,
);
has location => (
is => 'ro',
isa => 'Point',
handles => [qw( x y )],
);
has url => (
is => 'ro',
isa => 'Str',
);
has level => (
is => 'ro',
isa => 'Int',
);
has image => (
is => 'ro',
isa => 'Str',
);
has efficiency => (
is => 'ro',
isa => 'Int',
);
has pending_build => (
is => 'ro',
isa => 'WorkInProgress',
);
has work => (
is => 'ro',
isa => 'WorkInProgress',
);
sub new_from_id {
my $class = shift;
my $client = shift;
my $id = shift;
my $bs = $client->get_building_status( $id );
my $d = $bs->data;
my %args;
{ my @attrs = qw( id name url level image efficiency );
@args{@attrs} = @{$d}{@attrs};
$args{location} = Point->new( x => $d->{x}, y => $d->{y} );
$args{pending_build} = WorkInProgress->new( %{$d->{pending_build}})
if exists $d->{pending_build};
$args{work} = WorkInProgress->new( %{$d->{work}})
if exists $d->{work};
}
$class->new( %args );
}
sub as_string {
my $self = shift;
return sprintf "%s %0d", $self->name, $self->level;
}
__PACKAGE__->meta->make_immutable;
no Moose;
1;