remove IsValid::JSON from package
parent
eed8be5c0f
commit
5beba16631
3
dist.ini
3
dist.ini
|
@ -37,9 +37,6 @@ Convert::Braille = 0.05
|
|||
Math::Round = 0.06
|
||||
Convert::Morse = 0.05
|
||||
Net::IDN::Encode = 2.003
|
||||
; IsValid::JSON
|
||||
Try::Tiny = 0
|
||||
JSON = 0
|
||||
Astro::MoonPhase = 0
|
||||
Acme::rafl::Everywhere = 0.008
|
||||
Lingua::EN::Numbers::Ordinate = 1.02
|
||||
|
|
|
@ -1,46 +0,0 @@
|
|||
package DDG::Goodie::IsValid::JSON;
|
||||
# ABSTRACT: Check whether the submitted data is valid JSON.
|
||||
|
||||
use DDG::Goodie;
|
||||
|
||||
use Try::Tiny;
|
||||
use JSON qw(from_json);
|
||||
|
||||
primary_example_queries 'is valid {"test": "json"}';
|
||||
secondary_example_queries 'valid? ["test", "json"]';
|
||||
description 'validate JSON data';
|
||||
name 'IsValid::JSON';
|
||||
code_url 'https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DDG/Goodie/IsValid/JSON.pm';
|
||||
category 'programming';
|
||||
topics 'programming';
|
||||
|
||||
attribution github => ['https://github.com/ghedo', 'ghedo' ],
|
||||
web => ['http://ghedini.me', 'Alessandro Ghedini'];
|
||||
|
||||
zci answer_type => 'isvalid';
|
||||
zci is_cached => 1;
|
||||
|
||||
triggers any => 'json';
|
||||
|
||||
handle remainder => sub {
|
||||
return unless s/ ?(is )?valid\?? ?//gi;
|
||||
|
||||
my ($result, $error) = try {
|
||||
from_json $_;
|
||||
return 'valid!';
|
||||
} catch {
|
||||
$_ =~ /^(.* at character offset \d+ .*) at/;
|
||||
return ('invalid: ', $1);
|
||||
};
|
||||
|
||||
my $answer = "Your JSON is $result";
|
||||
my $answer_html = $answer;
|
||||
|
||||
$answer .= $error if $error;
|
||||
$answer_html .= "<pre style=\"font-size:12px;"
|
||||
. "margin-top:5px;\">$error</pre>" if $error;
|
||||
|
||||
return $answer, html => $answer_html
|
||||
};
|
||||
|
||||
1;
|
24
t/IsValid.t
24
t/IsValid.t
|
@ -1,24 +0,0 @@
|
|||
#!/usr/bin/env perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Test::More;
|
||||
use DDG::Test::Goodie;
|
||||
|
||||
zci answer_type => 'isvalid';
|
||||
zci is_cached => 1;
|
||||
|
||||
ddg_goodie_test(
|
||||
[qw(DDG::Goodie::IsValid::JSON)],
|
||||
'is valid json {"test":"lol"}' => test_zci(
|
||||
'Your JSON is valid!',
|
||||
html => 'Your JSON is valid!'
|
||||
),
|
||||
'is valid json {"test" "lol"}' => test_zci(
|
||||
'Your JSON is invalid: \':\' expected, at character offset 8 (before ""lol"}")',
|
||||
html => 'Your JSON is invalid: <pre style="font-size:12px;margin-top:5px;">\':\' expected, at character offset 8 (before ""lol"}")</pre>'
|
||||
)
|
||||
);
|
||||
|
||||
done_testing;
|
Loading…
Reference in New Issue