summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2014-11-18 13:11:21 -0500
committerJesse Luehrs <doy@tozt.net>2014-11-18 13:11:21 -0500
commit5cf58902c0bb892e5f37fa2a89e53ca5ebdc2c47 (patch)
treea23c4e2a8d3367fa70ddfb3ba5f6fd03f8184b4e
parent288a55d69508c52b30028d6d3d2a4e78adcafde3 (diff)
parentdd08b40718deb70aba8d770495bb70cf6955a8c8 (diff)
downloadreply-5cf58902c0bb892e5f37fa2a89e53ca5ebdc2c47.tar.gz
reply-5cf58902c0bb892e5f37fa2a89e53ca5ebdc2c47.zip
Merge pull request #41 from sergeyromanov/gen-replyrc
refactor default config generation to a separate method
-rw-r--r--lib/Reply/App.pm40
1 files changed, 29 insertions, 11 deletions
diff --git a/lib/Reply/App.pm b/lib/Reply/App.pm
index baeb0e4..66f9adb 100644
--- a/lib/Reply/App.pm
+++ b/lib/Reply/App.pm
@@ -75,17 +75,7 @@ sub run {
my $file = $cfg->file;
if (!-e $file) {
print("$file not found. Generating a default...\n");
- if (open my $fh, '>', $file) {
- my $contents = do {
- local $/;
- <DATA>
- };
- $contents =~ s/use 5.XXX/use $]/;
- print $fh $contents;
- close $fh;
- }
- else {
- warn "Couldn't write to $file";
+ unless ($self->generate_default_config($file)) {
%args = ();
}
}
@@ -99,6 +89,34 @@ sub run {
return 0;
}
+=method generate_default_config($file)
+
+Generates default configuration file as per specified destination.
+
+=cut
+
+sub generate_default_config {
+ my $self = shift;
+ my ($file) = @_;
+
+ if (open my $fh, '>', $file) {
+ my $contents = do {
+ local $/;
+ <DATA>
+ };
+ $contents =~ s/use 5.XXX/use $]/;
+ print $fh $contents;
+ close $fh;
+
+ return 1;
+ }
+ else {
+ warn "Couldn't write to $file";
+
+ return 0;
+ }
+}
+
=method usage($exitcode)
Prints usage information to the screen. If C<$exitcode> is 0, it will be