summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-08-07 14:22:45 -0400
committerJesse Luehrs <doy@tozt.net>2013-09-03 16:50:14 -0400
commit1f191d9e1456ad2a734625b28e26d750974631c2 (patch)
treec0c4b8ad4f5950ab07b8962ccb2548111db6f36a
parent34ef46f40b283ae69f315fcefc1bf8297d2ec8d2 (diff)
downloadreply-1f191d9e1456ad2a734625b28e26d750974631c2.tar.gz
reply-1f191d9e1456ad2a734625b28e26d750974631c2.zip
convert Reply::App
-rw-r--r--lib/Reply/App.pm122
1 files changed, 62 insertions, 60 deletions
diff --git a/lib/Reply/App.pm b/lib/Reply/App.pm
index 26bd85c..f7fd590 100644
--- a/lib/Reply/App.pm
+++ b/lib/Reply/App.pm
@@ -1,8 +1,10 @@
-package Reply::App;
+package main;
use strict;
use warnings;
# ABSTRACT: command line app runner for Reply
+use mop;
+
use Getopt::Long 2.36 'GetOptionsFromArray';
use Reply;
@@ -26,68 +28,67 @@ Returns a new Reply::App instance. Takes no arguments.
=cut
-sub new { bless {}, shift }
+class Reply::App {
=method run(@argv)
-Parses the argument list given (typically from @ARGV), along with the user's configuration file, and attempts to start a Reply shell. A default configuration file will be generated for the user if none exists.
+Parses the argument list given (typically from @ARGV), along with the user's
+configuration file, and attempts to start a Reply shell. A default
+configuration file will be generated for the user if none exists.
=cut
-sub run {
- my $self = shift;
- my @argv = @_;
-
- Getopt::Long::Configure("gnu_getopt");
-
- my $cfgfile = '.replyrc';
- my $exitcode;
- my @modules;
- my $parsed = GetOptionsFromArray(
- \@argv,
- 'cfg:s' => \$cfgfile,
- 'l|lib' => sub { push @INC, 'lib' },
- 'b|blib' => sub { push @INC, 'blib/lib', 'blib/arch' },
- 'I:s@' => sub { push @INC, $_[1] },
- 'M:s@' => \@modules,
- 'version' => sub { $exitcode = 0; version() },
- 'help' => sub { $exitcode = 0; usage() },
- );
-
- if (!$parsed) {
- usage(1);
- $exitcode = 1;
- }
-
- return $exitcode if defined $exitcode;
-
- my $cfg = Reply::Config->new(file => $cfgfile);
-
- my %args = (config => $cfg);
- 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;
+ method run (@argv) {
+ Getopt::Long::Configure("gnu_getopt");
+
+ my $cfgfile = '.replyrc';
+ my $exitcode;
+ my @modules;
+ my $parsed = GetOptionsFromArray(
+ \@argv,
+ 'cfg:s' => \$cfgfile,
+ 'l|lib' => sub { push @INC, 'lib' },
+ 'b|blib' => sub { push @INC, 'blib/lib', 'blib/arch' },
+ 'I:s@' => sub { push @INC, $_[1] },
+ 'M:s@' => \@modules,
+ 'version' => sub { $exitcode = 0; $self->version },
+ 'help' => sub { $exitcode = 0; $self->usage },
+ );
+
+ if (!$parsed) {
+ $self->usage(1);
+ $exitcode = 1;
}
- else {
- warn "Couldn't write to $file";
- %args = ();
+
+ return $exitcode if defined $exitcode;
+
+ my $cfg = Reply::Config->new(file => $cfgfile);
+
+ my %args = (config => $cfg);
+ 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";
+ %args = ();
+ }
}
- }
- my $reply = Reply->new(%args);
- $reply->step("use $_") for @modules;
- $reply->run;
+ my $reply = Reply->new(%args);
+ $reply->step("use $_") for @modules;
+ $reply->run;
- return 0;
-}
+ return 0;
+ }
=method usage($exitcode)
@@ -96,10 +97,10 @@ printed to C<STDOUT>, otherwise it will be printed to C<STDERR>.
=cut
-sub usage {
- my $fh = $_[0] ? *STDERR : *STDOUT;
- print $fh " reply [-lb] [-I dir] [-M mod] [--version] [--help] [--cfg file]\n";
-}
+ method usage ($exitcode) {
+ my $fh = $exitcode ? *STDERR : *STDOUT;
+ print $fh " reply [-lb] [-I dir] [-M mod] [--version] [--help] [--cfg file]\n";
+ }
=method version($exitcode)
@@ -108,9 +109,10 @@ printed to C<STDOUT>, otherwise it will be printed to C<STDERR>.
=cut
-sub version {
- my $fh = $_[0] ? *STDERR : *STDOUT;
- print $fh "Reply version $Reply::VERSION\n";
+ method version ($exitcode) {
+ my $fh = $exitcode ? *STDERR : *STDOUT;
+ print $fh "Reply version $Reply::VERSION\n";
+ }
}
1;