From dd08b40718deb70aba8d770495bb70cf6955a8c8 Mon Sep 17 00:00:00 2001 From: Sergey Romanov Date: Tue, 18 Nov 2014 17:09:31 +0300 Subject: refactor default config generation to a separate method --- lib/Reply/App.pm | 40 +++++++++++++++++++++++++++++----------- 1 file 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 $/; - - }; - $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 $/; + + }; + $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 -- cgit v1.2.3