Oogly

A Data validation idea that just might be ideal!
Download

Oogly Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Publisher Name:
  • Al Newkirk
  • Publisher web site:
  • http://search.cpan.org/~awncorp/

Oogly Tags


Oogly Description

A Data validation idea that just might be ideal! The Oogly module is a different approach to data validation, it attempts to simplify and centralize data validation rules to ensure DRY (don't repeat yourself) code.PLEASE NOTE! It is not the intent of this module to provide validation routines but instead to provide a simplistic validation flow-control and promote code reuse. The following is an example of that... use MyApp::Validation; my $app = MyApp::Validation->new(\%params); if ($app->validate('login', 'password')){ ... } else { print join "\n", @{$app->errors}; } package MyApp::Validation use Oogly qw/mixin field/; # define a mixin, a sortof template that can be included with other rules # by using the mixin directive mixin 'default' => { required => 1, min_length => 4, max_length => 255 }; # define a data validation rule for parameter `login` using the default # mixin where the `login` must be between 4-255 characters long and have # at least one letter and number field 'login' => { label => 'user login', mixin => 'default', validation => sub { my ($self, $this, $params) = @_; my ($name, $value) = ($this->{label}, $params->{login}); $self->error($this, "$name must contain at least one letter and number") unless ($value =~ // || $value =~ //); } }; # define a data validation rule for parameter `password` using the # previously defined field `login` as the mixin (template) field 'password' => { mixin_field => 'login', label => 'user password' };And now for my second and final act, using Oogly outside of a package. #!/usr/bin/perl use Oogly qw/:all/; my $i = Oogly( mixins => { default => { required => 1, min_length => 4, max_length => 255 } }, fields => { login => { label => 'user login', mixin => 'default', validation => sub { my ($self, $this, $params) = @_; my ($name, $value) = ($this->{name}, $params->{login}); $self->error($this, "field $name must contain at least one letter and number") if ($value !~ // && $value !~ //); } }, password => { mixin_field => 'login', label => 'user password' } }, ); # Important, store the new instance created by the $i->setup function $o = $i->setup({ login => 'root', password => '...' }); if ($o->validate) { ... } Requirements: · Perl


Oogly Related Software