X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2FDevel-REPL.git;a=blobdiff_plain;f=lib%2FDevel%2FREPL%2FPlugin%2FColors.pm;h=4452e1476985cdda8d2e87d77fa2ae8c1eb16106;hp=aa87abfab62d430847b2565b56c15143dab59b09;hb=77327851f87a17466307e8fccdbf2e0d3c2e58dc;hpb=653a2194b52cb95e0a6549a2b794384ba7b583b5 diff --git a/lib/Devel/REPL/Plugin/Colors.pm b/lib/Devel/REPL/Plugin/Colors.pm index aa87abf..4452e14 100644 --- a/lib/Devel/REPL/Plugin/Colors.pm +++ b/lib/Devel/REPL/Plugin/Colors.pm @@ -1,8 +1,13 @@ +use strict; +use warnings; package Devel::REPL::Plugin::Colors; +# ABSTRACT: Add color to return values, warnings, and errors -use Moose::Role; +our $VERSION = '1.003030'; + +use Devel::REPL::Plugin; use Term::ANSIColor; -use namespace::clean -except => [ 'meta' ]; +use namespace::autoclean; has normal_color => ( is => 'rw', lazy => 1, @@ -14,7 +19,7 @@ has error_color => ( default => 'bold red', ); -around error_return => sub { +around format_error => sub { my $orig = shift; my $self = shift; return color($self->error_color) @@ -23,19 +28,22 @@ around error_return => sub { }; # we can't just munge @_ because that screws up DDS -around print => sub { +around format_result => sub { my $orig = shift; my $self = shift; - print {$self->out_fh} color($self->normal_color); - $orig->($self, @_); - print {$self->out_fh} color('reset'); + no warnings 'uninitialized'; + return join "", ( + color($self->normal_color), + $orig->($self, @_), + color('reset'), + ); }; # make arbitrary warns colored -- somewhat difficult because warn doesn't # get $self, so we localize $SIG{__WARN__} during eval so it can get # error_color -around execute => sub { +sub _wrap_warn { my $orig = shift; my $self = shift; @@ -51,19 +59,17 @@ around execute => sub { $orig->($self, @_); }; +around compile => \&_wrap_warn; +around execute => \&_wrap_warn; + 1; __END__ -=head1 NAME - -Devel::REPL::Plugin::Colors - add color to return values, warnings, and errors +=pod =head1 SYNOPSIS - #!/usr/bin/perl - - use lib './lib'; use Devel::REPL; my $repl = Devel::REPL->new;