Giter Site home page Giter Site logo

mojolicious-plugin-validatemoose's Introduction

NAME
    Mojolicious::Plugin::ValidateMoose - Can validate using Moose objects

VERSION
    0.02

DESCRIPTION
    This module is handy if you want to validate POST/GET parameters using
    Moose classes.

SYNOPSIS
        package MyApp;
        use Mojo::Base 'Mojolicious';
        sub startup {
            my $self = shift;

            $self->plugin('Mojolicious::Plugin::ValidateMoose');

            # ...
        }

        package MyApp::Root;
        use Mojo::Base 'Mojolicious::Controller';
        sub foo {
            my $self = shift;

            if($self->req->method eq 'POST') {
                if(my $obj = $self->validate_moose('My::Moose::Class')) {
                    # input validate, and $obj created from My::Moose::Class
                    # with the params set as attributes
                }
            }
        }

HELPERS
  validate_moose
        $obj = $controller->validate_moose($moose_class, \%args);
        $obj = $controller->validate_moose($moose_obj, \%args);

    Will either update an existing or create a new Moose object, if all the
    attributes gets validated. If any of the attributes is not updated with
    the right value from "param()", this method will set
    "invalid_form_elements" in the stash to a datastructure like this:

        {
            $param_name_a => 'required', # fixed
            $param_name_b => 'moose exception message', # custom
        }

    Example moose exception message:

        Validation failed for 'Int' with value "asd"

    The method will return empty list if it fail to validate the input.

METHODS
  register
    Will register the methods undef "HELPERS" as Mojolicious helpers.

COPYRIGHT & LICENSE
    This library is free software. You can redistribute it and/or modify it
    under the same terms as Perl itself.

AUTHOR
    Jan Henning Thorsen - jhthorsen at cpan.org

mojolicious-plugin-validatemoose's People

Contributors

jhthorsen avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.