Skip to content

PerlServices/Mojolicious-Plugin-Data-Validate-WithYAML

Repository files navigation

Build Status Kwalitee status GitHub issues CPAN Cover Status

NAME

Mojolicious::Plugin::Data::Validate::WithYAML - validate form input with Data::Validate::WithYAML

VERSION

version 0.06

SYNOPSIS

In your startup method:

sub startup {
    my $self = shift;

    # more Mojolicious stuff

    $self->plugin(
        'Data::Validate::WithYAML',
        {
            error_prefix => 'ERROR_',        # optional
            conf_path    => '/opt/app/conf', # path to the dir where all the .ymls are (optional)
        }
    );
}

In your controller:

sub register {
    my $self = shift;

    # might be (age => 'You are too young', name => 'name is required')
    # or with error_prefix (ERROR_age => 'You are too young', ERROR_name => 'name is required')
    my %errors = $self->validate( 'registration' );

    if ( %errors ) {
       $self->stash( %errors );
       $self->render;
       return; 
    }

    # create new user
}

Your registration.yml

---
age:
  type: required
  message: You are too young
  min: 18
name:
  type: required
  message: name is required
password:
  type: required
  plugin: PasswordPolicy
website:
  type: optional
  plugin: URL

HELPERS

validate

my %errors = $controller->validate( $yaml_name );

Validates the parameters. Optional parameter is $yaml_name. If $yaml_name is ommitted, the subroutine name (e.g. "register") is used.

Development

The distribution is contained in a Git repository, so simply clone the repository

$ git clone git://github.com/perlservices/Mojolicious-Plugin-Data-Validate-WithYAML.git

and change into the newly-created directory.

$ cd Mojolicious-Plugin-Data-Validate-WithYAML

The project uses Dist::Zilla to build the distribution, hence this will need to be installed before continuing:

$ cpanm Dist::Zilla

To install the required prequisite packages, run the following set of commands:

$ dzil authordeps --missing | cpanm
$ dzil listdeps --author --missing | cpanm

The distribution can be tested like so:

$ dzil test

To run the full set of tests (including author and release-process tests), add the --author and --release options:

$ dzil test --author --release

AUTHOR

Renee Baecker reneeb@cpan.org

COPYRIGHT AND LICENSE

This software is Copyright (c) 2013 by Renee Baecker.

This is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)

About

Mojolicious plugin to validate form data with Data::Validate::WithYAML

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages