Permalink
Browse files

Make Term::ExtendedColor optional with better error

  • Loading branch information...
frioux committed Dec 17, 2012
1 parent 9b597cb commit c977872463248abbb9c6aeee81b2b6fa12453679
Showing with 18 additions and 7 deletions.
  1. +1 −0 Changes
  2. +0 −1 dist.ini
  3. +17 −6 lib/App/Adenosine/Plugin/Rainbow.pm
View
@@ -2,6 +2,7 @@ Revision history for {{$dist->name}}
{{$NEXT}}
+ * Make Term::ExtendedColor optional with better error
* Remove maint/ from CPAN dist (Tommy Stanton)
* Fix missing or too low prerews (Tommy Stanton)
* Do not require MRO::Compat for newer perls
View
@@ -47,5 +47,4 @@ YAML = 0
File::pushd = 0
FindBin = 0
Scalar::Util = 0
-Term::ExtendedColor = 0
Time::HiRes = 0
@@ -1,9 +1,20 @@
package App::Adenosine::Plugin::Rainbow;
use Moo;
-use Term::ExtendedColor ':all';
with 'App::Adenosine::Role::FiltersStdErr';
+use Module::Runtime 'require_module';
+use Try::Tiny;
+
+try {
+ require_module('Term::ExtendedColor')
+} catch {
+ die <<"ERR"
+Term::ExtendedColor must be installed to use ::Rainbow
+
+original error: $_
+ERR
+};
our %old_colormap = (
red => 1,
@@ -33,11 +44,11 @@ sub colorize {
if $arg->{$_} && exists $old_colormap{$arg->{$_}}
}
- $str = fg($arg->{fg}, $str ) if $arg->{fg};
- $str = bg($arg->{bg}, $str ) if $arg->{bg};
- $str = bold($str ) if $arg->{bold};
- $str = italic($str ) if $arg->{italic};
- $str = underline($str ) if $arg->{underline};
+ $str = Term::ExtendedColor::fg($arg->{fg}, $str ) if $arg->{fg};
+ $str = Term::ExtendedColor::bg($arg->{bg}, $str ) if $arg->{bg};
+ $str = Term::ExtendedColor::bold($str ) if $arg->{bold};
+ $str = Term::ExtendedColor::italic($str ) if $arg->{italic};
+ $str = Term::ExtendedColor::underline($str ) if $arg->{underline};
return $str;
}

0 comments on commit c977872

Please sign in to comment.