summaryrefslogtreecommitdiffstats
path: root/lib/Reply/Plugin/Colors.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Reply/Plugin/Colors.pm')
-rw-r--r--lib/Reply/Plugin/Colors.pm91
1 files changed, 35 insertions, 56 deletions
diff --git a/lib/Reply/Plugin/Colors.pm b/lib/Reply/Plugin/Colors.pm
index aa7e1ef..56c145d 100644
--- a/lib/Reply/Plugin/Colors.pm
+++ b/lib/Reply/Plugin/Colors.pm
@@ -1,9 +1,9 @@
-package Reply::Plugin::Colors;
+package main;
use strict;
use warnings;
# ABSTRACT: colorize output
-use base 'Reply::Plugin';
+use mop;
use Term::ANSIColor;
BEGIN {
@@ -17,9 +17,9 @@ BEGIN {
; .replyrc
[Colors]
- error = bright red
- warning = bright yellow
- result = bright green
+ error_color = bright red
+ warning_color = bright yellow
+ result_color = bright green
=head1 DESCRIPTION
@@ -32,62 +32,41 @@ C<result> options.
=cut
-sub new {
- my $class = shift;
- my %opts = @_;
+class Reply::Plugin::Colors extends Reply::Plugin {
+ has $error_color = 'red';
+ has $warning_color = 'yellow';
+ has $result_color = 'green';
- my $self = $class->SUPER::new(@_);
- $self->{error} = $opts{error} || 'red';
- $self->{warning} = $opts{warning} || 'yellow';
- $self->{result} = $opts{result} || 'green';
-
- return $self;
-}
-
-sub compile {
- my $self = shift;
- my ($next, @args) = @_;
-
- local $SIG{__WARN__} = sub { $self->print_warn(@_) };
- $next->(@args);
-}
-
-sub execute {
- my $self = shift;
- my ($next, @args) = @_;
-
- local $SIG{__WARN__} = sub { $self->print_warn(@_) };
- $next->(@args);
-}
-
-sub print_error {
- my $self = shift;
- my ($next, $error) = @_;
-
- print color($self->{error});
- $next->($error);
- local $| = 1;
- print color('reset');
-}
+ method compile ($next, @args) {
+ local $SIG{__WARN__} = sub { $self->print_warn(@_) };
+ $next->(@args);
+ }
-sub print_result {
- my $self = shift;
- my ($next, @result) = @_;
+ method execute ($next, @args) {
+ local $SIG{__WARN__} = sub { $self->print_warn(@_) };
+ $next->(@args);
+ }
- print color($self->{result});
- $next->(@result);
- local $| = 1;
- print color('reset');
-}
+ method print_error ($next, $error) {
+ print color($error_color);
+ $next->($error);
+ local $| = 1;
+ print color('reset');
+ }
-sub print_warn {
- my $self = shift;
- my ($warning) = @_;
+ method print_result ($next, @result) {
+ print color($result_color);
+ $next->(@result);
+ local $| = 1;
+ print color('reset');
+ }
- print color($self->{warning});
- print $warning;
- local $| = 1;
- print color('reset');
+ method print_warn ($warning) {
+ print color($warning_color);
+ print $warning;
+ local $| = 1;
+ print color('reset');
+ }
}
=for Pod::Coverage