line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package AI::Evolve::Befunge::Util::Config; |
2
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
7169
|
use strict; |
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
314
|
|
4
|
8
|
|
|
8
|
|
44
|
use warnings; |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
251
|
|
5
|
|
|
|
|
|
|
|
6
|
8
|
|
|
8
|
|
44
|
use base 'Class::Accessor::Fast'; |
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
5429
|
|
7
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors( qw(hash host gen physics) ); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
AI::Evolve::Befunge::Util::Config - config database object |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head2 SYNOPSIS |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
use AI::Evolve::Befunge::Util; |
18
|
|
|
|
|
|
|
my $config = custom_config(host => 'test', physics => 'ttt', gen => 1024); |
19
|
|
|
|
|
|
|
my $value = $config->config('value', 'default'); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head2 DESCRIPTION |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
This is a config object. The config file allows overrides based on |
25
|
|
|
|
|
|
|
hostname, physics engine in use, and AI generation. Thus, the config |
26
|
|
|
|
|
|
|
file data needs to be re-assessed every time one of these (usually |
27
|
|
|
|
|
|
|
just the generation) is changed. The result of this is a Config |
28
|
|
|
|
|
|
|
object, which is what this module implements. |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 CONSTRUCTOR |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head2 custom_config |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
This module does not actually implement the constructor - please see |
36
|
|
|
|
|
|
|
custom_config() in L for the details. |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 METHODS |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head2 config |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
my $value = global_config('name'); |
44
|
|
|
|
|
|
|
my $value = global_config('name', 'default'); |
45
|
|
|
|
|
|
|
my @list = global_config('name', 'default'); |
46
|
|
|
|
|
|
|
my @list = global_config('name', ['default1', 'default2']); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
Fetch some data from the config object. |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=cut |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub config { |
53
|
259
|
|
|
259
|
1
|
640
|
my ($self, $keyword, $value) = @_; |
54
|
259
|
100
|
|
|
|
1027
|
$value = $$self{hash}{$keyword} |
55
|
|
|
|
|
|
|
if exists $$self{hash}{$keyword}; |
56
|
|
|
|
|
|
|
|
57
|
259
|
100
|
|
|
|
532
|
if(wantarray()) { |
58
|
5
|
100
|
|
|
|
28
|
return @$value if ref($value) eq 'ARRAY'; |
59
|
4
|
100
|
|
|
|
12
|
if(!defined($value)) { |
60
|
2
|
100
|
|
|
|
13
|
return () if scalar @_ == 2; |
61
|
1
|
|
|
|
|
6
|
return (undef); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
} |
64
|
256
|
|
|
|
|
1232
|
return $value; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
1; |