add IsValid::XML goodie plugin

master
Alessandro Ghedini 2012-08-02 21:06:09 +02:00
parent 72421fc467
commit ccdcc30148
2 changed files with 34 additions and 0 deletions

View File

@ -0,0 +1,24 @@
package DDG::Goodie::IsValid::XML;
use DDG::Goodie;
use Try::Tiny;
use XML::Simple;
zci answer_type => 'isvalid';
zci is_cached => 1;
triggers start => 'is valid xml', 'validate xml';
handle remainder => sub {
my $result = try {
XMLin($_);
return 'valid';
} catch {
return 'invalid';
};
return "Your XML is $result!";
};
1;

View File

@ -19,4 +19,14 @@ ddg_goodie_test(
'is valid json {"test" "lol"}' => test_zci('Your JSON is invalid!'), 'is valid json {"test" "lol"}' => test_zci('Your JSON is invalid!'),
); );
ddg_goodie_test(
[qw(DDG::Goodie::IsValid::XML)],
'is valid xml <test></test>' => test_zci('Your XML is valid!'),
);
ddg_goodie_test(
[qw(DDG::Goodie::IsValid::XML)],
'is valid xml <test>lol' => test_zci('Your XML is invalid!'),
);
done_testing; done_testing;