diff options
Diffstat (limited to 'usr/src/libpiny/lib/Piny/Config.pm')
-rw-r--r-- | usr/src/libpiny/lib/Piny/Config.pm | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/usr/src/libpiny/lib/Piny/Config.pm b/usr/src/libpiny/lib/Piny/Config.pm new file mode 100644 index 0000000..b30eccb --- /dev/null +++ b/usr/src/libpiny/lib/Piny/Config.pm @@ -0,0 +1,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" ); + } 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_destdir"}; + } 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; |