Validation::Class::Plugin::JavascriptObjects - Generate Javascript Objects from you Validation Classes
version 0.02
# THIS PLUGIN IS UNTESTED AND MAY BE SUBJECT TO DESIGN CHANGES!!! use Validation::Class::Simple; # given my $rules = Validation::Class::Simple->new( fields => { username => { required => 1 }, password => { required => 1 }, } ); # when my $objects = $rules->plugin('javascript_objects'); print $objects->render(namespace => 'form.signup', include => [qw/errors/]); # should output var form.signup = { "password": { "errors": ["password is required"] }, "username": { "errors": ["username is required"] } };
Validation::Class::Plugin::JavascriptObjects is a plugin for Validation::Class which can leverage your validation class field definitions to render JavaScript objects for the purpose of introspection.
The render method converts the attached validation class into a javascript object for introspection purposes. This method accepts a list of key/value pairs as options.
$self->render; # or $self->render( namespace => 'Foo.Bar', exclude => [qw/pattern/] ); # or $self->render( namespace => 'Foo.Baz', include => [qw/minlength maxlength required/] );
Al Newkirk <anewkirk@ana.io>
This software is copyright (c) 2011 by Al Newkirk.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Validation::Class::Plugin::JavascriptObjects, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Validation::Class::Plugin::JavascriptObjects
CPAN shell
perl -MCPAN -e shell install Validation::Class::Plugin::JavascriptObjects
For more information on module installation, please visit the detailed CPAN module installation guide.