summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-08-07 14:54:43 -0400
committerJesse Luehrs <doy@tozt.net>2013-09-03 16:50:15 -0400
commit22adfca628dd4c9933c95d2ae619f98d78d5da46 (patch)
treee675d1054b371d9f2e6ed6debd83c2a711fcca48
parent82416cdb01591c91de38410794877122e5aecc23 (diff)
downloadreply-22adfca628dd4c9933c95d2ae619f98d78d5da46.tar.gz
reply-22adfca628dd4c9933c95d2ae619f98d78d5da46.zip
convert Reply::Config
-rw-r--r--lib/Reply/Config.pm46
1 files changed, 21 insertions, 25 deletions
diff --git a/lib/Reply/Config.pm b/lib/Reply/Config.pm
index b23b623..233293e 100644
--- a/lib/Reply/Config.pm
+++ b/lib/Reply/Config.pm
@@ -1,8 +1,10 @@
-package Reply::Config;
+package main;
use strict;
use warnings;
# ABSTRACT: config loading for Reply
+use mop;
+
use Config::INI::Reader::Ordered;
use File::HomeDir;
use File::Spec;
@@ -37,27 +39,15 @@ be relative to the user's home directory, otherwise it will be used as-is.
=cut
-sub new {
- my $class = shift;
- my %opts = @_;
-
- $opts{file} = '.replyrc'
- unless defined $opts{file};
-
- my $file = File::Spec->catfile(
- (File::Spec->file_name_is_absolute($opts{file})
- ? ()
- : (File::HomeDir->my_home)),
- $opts{file}
- );
+class Reply::Config {
+ has $file = $_->_canonicalize_file('.replyrc');
+ has $config = Config::INI::Reader::Ordered->new;
- my $self = bless {}, $class;
-
- $self->{file} = $file;
- $self->{config} = Config::INI::Reader::Ordered->new;
-
- return $self;
-}
+ submethod BUILD ($args) {
+ if (defined $args->{file}) {
+ $file = $self->_canonicalize_file($args->{file});
+ }
+ }
=method file
@@ -65,7 +55,7 @@ Returns the absolute path to the config file that is to be used.
=cut
-sub file { shift->{file} }
+ method file { $file }
=method data
@@ -73,10 +63,16 @@ Returns the loaded configuration data.
=cut
-sub data {
- my $self = shift;
+ method data { $config->read_file($file) }
- return $self->{config}->read_file($self->{file});
+ method _canonicalize_file ($filename) {
+ return File::Spec->catfile(
+ (File::Spec->file_name_is_absolute($filename)
+ ? ()
+ : (File::HomeDir->my_home)),
+ $filename
+ );
+ }
}
1;