forked from tsee/Games-Lacuna-Client
/
Empire.pm
130 lines (99 loc) · 3.5 KB
/
Empire.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package Games::Lacuna::Client::Empire;
use 5.0080000;
use strict;
use warnings;
use Carp 'croak';
use Games::Lacuna::Client;
use Games::Lacuna::Client::Module;
our @ISA = qw(Games::Lacuna::Client::Module);
use Class::XSAccessor {
getters => [qw(empire_id)],
};
sub api_methods {
return {
(
map {
($_ => { default_args => [qw()] })
}
qw( login
is_name_available
fetch_captcha
send_password_reset_message
reset_password
get_species_templates
)
),
found => { default_args => [qw(empire_id)] },
update_species => { default_args => [qw(empire_id)] },
redefine_species => { default_args => [qw(session_id)] },
invite_friend => { default_args => [qw(session_id)] },
change_password => { default_args => [qw(session_id)] },
logout => { default_args => [qw(session_id)] },
get_status => { default_args => [qw(session_id)] },
view_profile => { default_args => [qw(session_id)] },
edit_profile => { default_args => [qw(session_id)] },
view_public_profile => { default_args => [qw(session_id empire_id)] },
find => { default_args => [qw(session_id)] },
set_status_message => { default_args => [qw(session_id)] },
view_boosts => { default_args => [qw(session_id)] },
boost_storage => { default_args => [qw(session_id)] },
boost_food => { default_args => [qw(session_id)] },
boost_water => { default_args => [qw(session_id)] },
boost_energy => { default_args => [qw(session_id)] },
boost_ore => { default_args => [qw(session_id)] },
boost_happiness => { default_args => [qw(session_id)] },
enable_self_destruct => { default_args => [qw(session_id)] },
disable_self_destruct => { default_args => [qw(session_id)] },
redeem_essentia_code => { default_args => [qw(session_id)] },
view_species_stats => { default_args => [qw(session_id)] },
};
}
sub new {
my $class = shift;
my %opt = @_;
my $self = $class->SUPER::new(@_);
bless $self => $class;
$self->{empire_id} = $opt{id};
return $self;
}
sub logout {
my $self = shift;
my $client = $self->client;
if (not $client->session_id) {
return 0;
}
else {
my $res = $self->_logout;
return delete $client->{session_id};
}
}
__PACKAGE__->init();
1;
__END__
=head1 NAME
Games::Lacuna::Client::Empire - The empire module
=head1 SYNOPSIS
use Games::Lacuna::Client;
use Games::Lacuna::Client::Empire;
my $client = Games::Lacuna::Client->new(...);
my $empire = $client->empire;
my $status = $empire->get_status;
=head1 DESCRIPTION
A subclass of L<Games::Lacuna::Client::Module>.
=head2 new
Creates an object locally, does not connect to the server.
Games::Lacuna::Client::Empire->new(client => $client, @parameters);
The $client is a C<Games::Lacuna::Client> object.
Usually, you can just use the C<empire> factory method of the
client object instead:
my $empire = $client->empire(@parameters); # client set automatically
Optional parameters:
id => "The id of the empire"
=head1 AUTHOR
Steffen Mueller, E<lt>smueller@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2010 by Steffen Mueller
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.10.0 or,
at your option, any later version of Perl 5 you may have available.
=cut