| 1 | package Reply::Plugin::TypeTiny; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | BEGIN { | ||
| 7 | $Reply::Plugin::TypeTiny::AUTHORITY = 'cpan:TOBYINK'; | ||
| 8 | $Reply::Plugin::TypeTiny::VERSION = '2.010001'; | ||
| 9 | } | ||
| 10 | |||
| 11 | $Reply::Plugin::TypeTiny::VERSION =~ tr/_//d; | ||
| 12 | |||
| 13 | require Reply::Plugin; | ||
| 14 | our @ISA = 'Reply::Plugin'; | ||
| 15 | |||
| 16 | use Scalar::Util qw(blessed); | ||
| 17 | use Term::ANSIColor; | ||
| 18 | |||
| 19 | sub mangle_error { | ||
| 20 | my $self = shift; | ||
| 21 | my ( $err ) = @_; | ||
| 22 | |||
| 23 | if ( blessed $err and $err->isa( "Error::TypeTiny::Assertion" ) ) { | ||
| 24 | my $explain = $err->explain; | ||
| 25 | if ( $explain ) { | ||
| 26 | print color( "cyan" ); | ||
| 27 | print "Error::TypeTiny::Assertion explain:\n"; | ||
| 28 | $self->_explanation( $explain, "" ); | ||
| 29 | local $| = 1; | ||
| 30 | print "\n"; | ||
| 31 | print color( "reset" ); | ||
| 32 | } | ||
| 33 | } #/ if ( blessed $err and ...) | ||
| 34 | |||
| 35 | return @_; | ||
| 36 | } #/ sub mangle_error | ||
| 37 | |||
| 38 | sub _explanation { | ||
| 39 | my $self = shift; | ||
| 40 | my ( $ex, $indent ) = @_; | ||
| 41 | |||
| 42 | for my $line ( @$ex ) { | ||
| 43 | if ( ref( $line ) eq q(ARRAY) ) { | ||
| 44 | print "$indent * Explain:\n"; | ||
| 45 | $self->_explanation( $line, "$indent " ); | ||
| 46 | } | ||
| 47 | else { | ||
| 48 | print "$indent * $line\n"; | ||
| 49 | } | ||
| 50 | } | ||
| 51 | } #/ sub _explanation | ||
| 52 | |||
| 53 | 1; | ||
| 54 | |||
| 55 | __END__ |