summaryrefslogtreecommitdiff
path: root/usr/src/libpiny/lib/Piny
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src/libpiny/lib/Piny')
-rw-r--r--usr/src/libpiny/lib/Piny/Config.pm121
-rw-r--r--usr/src/libpiny/lib/Piny/Environment.pm2
-rw-r--r--usr/src/libpiny/lib/Piny/Repo.pm1
3 files changed, 123 insertions, 1 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;
diff --git a/usr/src/libpiny/lib/Piny/Environment.pm b/usr/src/libpiny/lib/Piny/Environment.pm
index fcd4392..6cd3532 100644
--- a/usr/src/libpiny/lib/Piny/Environment.pm
+++ b/usr/src/libpiny/lib/Piny/Environment.pm
@@ -3,7 +3,7 @@
package Piny::Environment;
-use Moose;
+use MooseX::Singleton;
use Piny::User;
diff --git a/usr/src/libpiny/lib/Piny/Repo.pm b/usr/src/libpiny/lib/Piny/Repo.pm
index 5d617f6..62f01f3 100644
--- a/usr/src/libpiny/lib/Piny/Repo.pm
+++ b/usr/src/libpiny/lib/Piny/Repo.pm
@@ -12,6 +12,7 @@ use IO::Dir qw( );
use IkiWiki::FakeSetup qw( readSetup writeSetup );
+use Piny::Config;
use Piny::Environment;
use Piny::Group;
use Piny::User;