Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web filter: provide a bracketed type for JSON::Typist value #198

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions lib/Data/Printer/Filter/Web.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down