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
|
# Copyright © 2010 Julian Blake Kongslie <jblake@omgwallhack.org>
# Licensed under the BSD 3-clause license.
package Piny::Config;
use MooseX::Singleton;
use YAML::Tiny qw( );
# Attributes
has '_conf' =>
( is => 'ro'
, isa => 'HashRef[Str]'
, lazy_build => 1
, init_arg => undef
);
has 'ikiwiki_destdir' =>
( is => 'ro'
, isa => 'Str'
, lazy_build => 1
, init_arg => undef
);
has 'ikiwiki_srcdir' =>
( is => 'ro'
, isa => 'Str'
, lazy_build => 1
, init_arg => undef
);
has 'ikiwiki_url' =>
( is => 'ro'
, isa => 'Str'
, lazy_build => 1
, init_arg => undef
);
has 'ikiwiki_secure_url' =>
( is => 'ro'
, isa => 'Str'
, lazy_build => 1
, init_arg => undef
);
has 'ikiwiki_secure_path' =>
( is => 'ro'
, isa => 'Str'
, lazy_build => 1
, init_arg => undef
);
# Builder methods
sub _build__conf {
my ( $s ) = @_;
if ( -e "/etc/piny.conf" ) {
my $yaml = YAML::Tiny->new;
return $yaml->read( "/etc/piny.conf" )->[0];
} else {
return { };
};
};
sub _build_ikiwiki_destdir {
my ( $s ) = @_;
if ( exists $s->_conf->{"ikiwiki_destdir"} ) {
return $s->_conf->{"ikiwiki_destdir"};
} else {
return "/srv/www/piny.be/";
};
};
sub _build_ikiwiki_srcdir {
my ( $s ) = @_;
if ( exists $s->_conf->{"ikiwiki_srcdir"} ) {
return $s->_conf->{"ikiwiki_srcdir"};
} else {
return "/srv/ikiwiki/";
};
};
sub _build_ikiwiki_url {
my ( $s ) = @_;
if ( exists $s->_conf->{"ikiwiki_url"} ) {
return $s->_conf->{"ikiwiki_url"};
} else {
return "http://piny.be/";
};
};
sub _build_ikiwiki_secure_url {
my ( $s ) = @_;
if ( exists $s->_conf->{"ikiwiki_secure_url"} ) {
return $s->_conf->{"ikiwiki_secure_url"};
} else {
return "https://secure.piny.be/repos/";
};
};
sub _build_ikiwiki_secure_path {
my ( $s ) = @_;
if ( exists $s->_conf->{"ikiwiki_secure_path"} ) {
return $s->_conf->{"ikiwiki_secure_path"};
} else {
return "/srv/www/secure.piny.be/repos/";
};
};
# Moose boilerplate
__PACKAGE__->meta->make_immutable;
1;
|