add IsValid::XML goodie plugin
parent
72421fc467
commit
ccdcc30148
|
@ -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;
|
10
t/IsValid.t
10
t/IsValid.t
|
@ -19,4 +19,14 @@ ddg_goodie_test(
|
|||
'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;
|
||||
|
|
Loading…
Reference in New Issue