#!/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 } ); }; }; };