From b0d2db3addd470dcd839cd14ecca6ab0bfebd5c5 Mon Sep 17 00:00:00 2001 From: Ricardo Signes Date: Wed, 31 Jul 2024 10:10:23 +1000 Subject: [PATCH] Web filter: provide a bracketed type for JSON::Typist value That is: make very clear whether "foo" is a Perl string or a JSON::Typist string. --- lib/Data/Printer/Filter/Web.pm | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/lib/Data/Printer/Filter/Web.pm b/lib/Data/Printer/Filter/Web.pm index 37cec54..b59bc45 100644 --- a/lib/Data/Printer/Filter/Web.pm +++ b/lib/Data/Printer/Filter/Web.pm @@ -21,16 +21,27 @@ sub _parse_json_boolean { filter 'JSON::NotString' => sub { _parse_json_boolean($_[0]->{value}, $_[1]) }; # JSON::Typist -filter 'JSON::Typist::String' => sub { - my ($obj, $ddp) = @_; - require Data::Printer::Common; - my $ret = Data::Printer::Common::_process_string($ddp, "$obj", 'string'); - my $quote = $ddp->maybe_colorize($ddp->scalar_quotes, 'quotes'); - return $quote . $ret . $quote; +filter 'JSON::Typist::Number' => sub { + my ($object, $ddp) = @_; + return $ddp->maybe_colorize($$object, 'number') + . ' ' + . $ddp->maybe_colorize('[', 'brackets') + . $ddp->maybe_colorize('jnum', 'number') + . $ddp->maybe_colorize(']', 'brackets'); }; -filter 'JSON::Typist::Number' => sub { - return $_[1]->maybe_colorize($_[0], 'number'); +filter 'JSON::Typist::String' => sub { + my ($object, $ddp) = @_; + + require Data::Printer::Common; + my $str = Data::Printer::Common::_process_string($ddp, $$object, 'string'); + my $quote = $ddp->maybe_colorize($ddp->scalar_quotes, 'quotes'); + + return $quote . $str . $quote + . ' ' + . $ddp->maybe_colorize('[', 'brackets') + . $ddp->maybe_colorize('jstr', 'string') + . $ddp->maybe_colorize(']', 'brackets'); }; # NOTE: boolean is used by Pegex::JSON