| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Games::Lacuna::Client::Module; |
|
2
|
|
|
|
|
|
|
{ |
|
3
|
|
|
|
|
|
|
$Games::Lacuna::Client::Module::VERSION = '0.003'; |
|
4
|
|
|
|
|
|
|
} |
|
5
|
1
|
|
|
1
|
|
81
|
use 5.0080000; |
|
|
1
|
|
|
|
|
5
|
|
|
|
1
|
|
|
|
|
62
|
|
|
6
|
1
|
|
|
1
|
|
8
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
46
|
|
|
7
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
57
|
|
|
8
|
1
|
|
|
1
|
|
7
|
use Carp 'croak'; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
90
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use Class::XSAccessor { |
|
11
|
1
|
|
|
|
|
11
|
getters => [qw(client uri)], |
|
12
|
1
|
|
|
1
|
|
1269
|
}; |
|
|
1
|
|
|
|
|
5370
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
require Games::Lacuna::Client; |
|
15
|
|
|
|
|
|
|
|
|
16
|
0
|
|
|
0
|
0
|
|
sub api_methods_without_session { croak("unimplemented"); } |
|
17
|
0
|
|
|
0
|
0
|
|
sub api_methods_with_session { croak("unimplemented"); } |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub module_prefix { |
|
20
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
21
|
0
|
|
0
|
|
|
|
my $class = ref($self)||$self; |
|
22
|
0
|
0
|
|
|
|
|
$class =~ /::(\w+)+$/ or croak("unimplemented"); |
|
23
|
0
|
|
|
|
|
|
return lc($1); |
|
24
|
|
|
|
|
|
|
} |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub session_id { |
|
27
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
28
|
0
|
|
|
|
|
|
return $self->client->assert_session(); |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub new { |
|
32
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
|
33
|
0
|
|
|
|
|
|
my %opt = @_; |
|
34
|
0
|
|
0
|
|
|
|
my $client = $opt{client} || croak("Need Games::Lacuna::Client"); |
|
35
|
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
my $self = bless { |
|
37
|
|
|
|
|
|
|
%opt, |
|
38
|
|
|
|
|
|
|
} => $class; |
|
39
|
0
|
|
|
|
|
|
$self->{uri} = $self->client->uri . '/' . $self->module_prefix; |
|
40
|
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
return $self; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub init { |
|
45
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
|
46
|
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
$class->_generate_api_methods($class->api_methods); |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub _generate_api_methods { |
|
51
|
0
|
|
|
0
|
|
|
my $class = shift; |
|
52
|
0
|
|
0
|
|
|
|
my $method_specs = shift || croak("Missing method specs"); |
|
53
|
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
foreach my $method_name (keys %$method_specs) { |
|
55
|
0
|
|
|
|
|
|
my $target = $class->_find_target_name($method_name); |
|
56
|
0
|
|
|
|
|
|
my $spec = $method_specs->{$method_name}; |
|
57
|
0
|
|
|
|
|
|
$class->_generate_method_per_spec($target, $method_name, $spec); |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub _generate_method_per_spec { |
|
62
|
0
|
|
|
0
|
|
|
my $class = shift; |
|
63
|
0
|
|
|
|
|
|
my $target = shift; |
|
64
|
0
|
|
|
|
|
|
my $method_name = shift; |
|
65
|
0
|
|
|
|
|
|
my $spec = shift; |
|
66
|
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
my $default_args = $spec->{default_args}; |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
my $sub = sub { |
|
70
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
71
|
0
|
|
|
|
|
|
my $client = $self->client; |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# prepend the default parameters to the arguments |
|
74
|
0
|
|
|
|
|
|
my $params = [ |
|
75
|
|
|
|
|
|
|
(map $self->$_(), @$default_args), |
|
76
|
|
|
|
|
|
|
@_ |
|
77
|
|
|
|
|
|
|
]; |
|
78
|
|
|
|
|
|
|
|
|
79
|
0
|
0
|
|
|
|
|
if ($client->debug) { |
|
80
|
0
|
|
|
|
|
|
print STDERR "DEBUG: " . __PACKAGE__ . " request " . Data::Dumper::Dumper([$self->uri, $method_name, $params]); |
|
81
|
|
|
|
|
|
|
} |
|
82
|
0
|
|
|
|
|
|
my $ret = $client->rpc->call($self->uri, $method_name, $params); |
|
83
|
0
|
0
|
|
|
|
|
if ($client->debug) { |
|
84
|
0
|
|
|
|
|
|
print STDERR "DEBUG: " . __PACKAGE__ . " result " . Data::Dumper::Dumper($ret); |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
0
|
0
|
0
|
|
|
|
if (ref $ret eq 'HASH' and exists $ret->{result} and ref $ret->{result} eq 'HASH') { |
|
|
|
|
0
|
|
|
|
|
|
88
|
0
|
0
|
|
|
|
|
$self->client->{rpc_count} = |
|
|
|
0
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
$ret->{result}{status} ? $ret->{result}{status}{empire}{rpc_count} : |
|
90
|
|
|
|
|
|
|
$ret->{result}{empire} ? $ret->{result}{empire}{rpc_count} : |
|
91
|
|
|
|
|
|
|
$self->client->{rpc_count}; |
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
return $ret->{result}; |
|
95
|
0
|
|
|
|
|
|
}; |
|
96
|
|
|
|
|
|
|
|
|
97
|
1
|
|
|
1
|
|
815
|
no strict 'refs'; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
80
|
|
|
98
|
0
|
|
|
|
|
|
*{"$target"} = $sub; |
|
|
0
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub _find_target_name { |
|
102
|
0
|
|
|
0
|
|
|
my $class = shift; |
|
103
|
0
|
|
|
|
|
|
my $method_name = shift; |
|
104
|
1
|
|
|
1
|
|
4
|
no strict 'refs'; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
93
|
|
|
105
|
0
|
|
|
|
|
|
my $target = "${class}::$method_name"; |
|
106
|
0
|
0
|
|
|
|
|
if (defined &{"$target"}) { |
|
|
0
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
$target = "${class}::_$method_name"; |
|
108
|
|
|
|
|
|
|
} |
|
109
|
0
|
|
|
|
|
|
return $target; |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
1; |
|
113
|
|
|
|
|
|
|
__END__ |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 NAME |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Games::Lacuna::Client::Empire - The empire module |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
use Games::Lacuna::Client; |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 AUTHOR |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Steffen Mueller, E<lt>smueller@cpan.orgE<gt> |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Copyright (C) 2010 by Steffen Mueller |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
|
134
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.10.0 or, |
|
135
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=cut |