Skip to content

Commit

Permalink
add IsValid::XML goodie plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
ghedo committed Aug 2, 2012
1 parent 72421fc commit ccdcc30
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/DDG/Goodie/IsValid/XML.pm
Original file line number Diff line number Diff line change
@@ -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 changes: 10 additions & 0 deletions t/IsValid.t
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit ccdcc30

Please sign in to comment.