diff options
author | Julian Blake Kongslie <jblake@omgwallhack.org> | 2011-01-18 17:45:58 -0800 |
---|---|---|
committer | Julian Blake Kongslie <jblake@omgwallhack.org> | 2011-01-18 17:45:58 -0800 |
commit | 0c395cf4516981ef0f9b56a082d700f6fc4697e9 (patch) | |
tree | 987335c43446265bef20402899df6761d6c2cbdb /pinyweb/cgi-bin | |
parent | 9a6e827943644bd3c4b01c16beeabb65968aea9d (diff) | |
download | piny-code-0c395cf4516981ef0f9b56a082d700f6fc4697e9.tar.gz piny-code-0c395cf4516981ef0f9b56a082d700f6fc4697e9.zip |
Adding a CGI for doing AJAX-style live validation of constraints.
Diffstat (limited to 'pinyweb/cgi-bin')
-rwxr-xr-x | pinyweb/cgi-bin/checkconstraint.cgi | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/pinyweb/cgi-bin/checkconstraint.cgi b/pinyweb/cgi-bin/checkconstraint.cgi new file mode 100755 index 0000000..8db0903 --- /dev/null +++ b/pinyweb/cgi-bin/checkconstraint.cgi @@ -0,0 +1,41 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use CGI; +use JSON qw( encode_json ); +use Moose::Util::TypeConstraints qw( find_type_constraint ); + +use Piny; + +my $q = CGI->new( ); + +my $type = $q->param( 't' ); +my $value = $q->param( 'v' ); + +if ( not defined $type or not defined $value ) { + print "Status: 400 Bad Request\nContent-type: application/json\n\n"; + print encode_json( { "ok" => JSON::false, "msg" => "Unable to validate due to client-side error, please reload this page. Required parameter missing." } ); +} else { + + my $constraint = find_type_constraint( $type ); + + if ( not defined $constraint ) { + print "Status: 400 Bad Request\nContent-type: application/json\n\n"; + print encode_json( { "ok" => JSON::false, "msg" => "Unable to validate due to client-side error, please reload this page. Invalid constraint name." } ); + } else { + + print "Status: 200 OK\nContent-type: application/json\n\n"; + + my $error = $constraint->validate( $value ); + + if ( defined $error ) { + print encode_json( { "ok" => JSON::false, "msg" => $error } ); + } else { + print encode_json( { "ok" => JSON::true } ); + }; + + }; + +}; |