# Copyright © 2010 Julian Blake Kongslie # 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/"; }; }; 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/"; }; }; # Moose boilerplate __PACKAGE__->meta->make_immutable; 1;