view release on metacpan or search on metacpan
lib/Mojolicious/Plugin/Data/Validate/WithYAML.pm
t/author-pod-coverage.t
t/author-pod-syntax.t
t/conf/finfo.yml
t/conf/hello.yml
t/conf/step_test.yml
t/conf/test.yml
t/fieldinfo.t
t/fieldinfo_no_config.t
t/test.yml
t/validate.t
t/validate_config.t
t/validate_steps.t
{
"abstract" : "validate form input with Data::Validate::WithYAML",
"author" : [
"Renee Baecker <reneeb@cpan.org>"
],
"dynamic_config" : 0,
"generated_by" : "Dist::Zilla version 6.010, CPAN::Meta::Converter version 2.150010",
"license" : [
"artistic_2"
],
"meta-spec" : {
"url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
---
abstract: 'validate form input with Data::Validate::WithYAML'
author:
- 'Renee Baecker <reneeb@cpan.org>'
build_requires:
Pod::Coverage::TrustPod: '0'
Test::LongString: '0.16'
Test::More: '0'
configure_requires:
ExtUtils::MakeMaker: '0'
dynamic_config: 0
generated_by: 'Dist::Zilla version 6.010, CPAN::Meta::Converter version 2.150010'
Makefile.PL view on Meta::CPAN
# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.010.
use strict;
use warnings;
use 5.008;
use ExtUtils::MakeMaker;
my %WriteMakefileArgs = (
"ABSTRACT" => "validate form input with Data::Validate::WithYAML",
"AUTHOR" => "Renee Baecker <reneeb\@cpan.org>",
"CONFIGURE_REQUIRES" => {
"ExtUtils::MakeMaker" => 0
},
"DISTNAME" => "Mojolicious-Plugin-Data-Validate-WithYAML",
"LICENSE" => "artistic_2",
"MIN_PERL_VERSION" => "5.008",
"NAME" => "Mojolicious::Plugin::Data::Validate::WithYAML",
"PREREQ_PM" => {
"Data::Validate::WithYAML" => "0.17",
NAME
Mojolicious::Plugin::Data::Validate::WithYAML - validate form input
with Data::Validate::WithYAML
VERSION
version 0.06
SYNOPSIS
In your startup method:
);
}
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
}
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.
AUTHOR
Renee Baecker <reneeb@cpan.org>
COPYRIGHT AND LICENSE
eg/test.psgi view on Meta::CPAN
plugin('Data::Validate::WithYAML' => {
conf_path => app->home->child( '..', 't', 'conf' )->to_string,
error_prefix => 'TEST_',
});
any '/' => \&test;
sub test {
my $self = shift;
my %errors = $self->validate( 'hello' );
$self->app->log->debug( $self->dumper( \%errors ) );
$self->render( json => { test => 1 } );
};
app->start;
lib/Mojolicious/Plugin/Data/Validate/WithYAML.pm view on Meta::CPAN
package Mojolicious::Plugin::Data::Validate::WithYAML;
# ABSTRACT: validate form input with Data::Validate::WithYAML
use strict;
use warnings;
use parent 'Mojolicious::Plugin';
use Carp;
use Data::Validate::WithYAML;
use Mojo::File qw(path);
our $VERSION = 0.06;
sub register {
my ($self, $app, $config) = @_;
$config->{conf_path} = $app->home if !$config->{conf_path};
$config->{no_steps} = 1 if !defined $config->{no_steps};
$app->helper( 'validate' => sub {
my ($c, $file, $step) = @_;
my $validator = _validator( $file, $config );
my %params = %{ $c->req->params->to_hash };
my @args = $step ? $step : ();
my %errors = $validator->validate( @args, %params );
my $prefix = exists $config->{error_prefix} ?
$config->{error_prefix} :
'ERROR_';
my %prefixed_errors = map{ ( "$prefix$_" => $errors{$_} ) } keys %errors;
return %prefixed_errors;
});
lib/Mojolicious/Plugin/Data/Validate/WithYAML.pm view on Meta::CPAN
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Mojolicious::Plugin::Data::Validate::WithYAML - validate form input with Data::Validate::WithYAML
=head1 VERSION
version 0.06
=head1 SYNOPSIS
In your C<startup> method:
sub startup {
lib/Mojolicious/Plugin/Data/Validate/WithYAML.pm view on Meta::CPAN
);
}
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
}
lib/Mojolicious/Plugin/Data/Validate/WithYAML.pm view on Meta::CPAN
message: name is required
password:
type: required
plugin: PasswordPolicy
website:
type: optional
plugin: URL
=head1 HELPERS
=head2 validate
my %errors = $controller->validate( $yaml_name );
Validates the parameters. Optional parameter is I<$yaml_name>. If I<$yaml_name> is ommitted, the subroutine name (e.g. "register") is used.
=head1 AUTHOR
Renee Baecker <reneeb@cpan.org>
=head1 COPYRIGHT AND LICENSE
This software is Copyright (c) 2013 by Renee Baecker.
t/conf/hello.yml view on Meta::CPAN
---
email:
type: required
regex: ^[\w.-]+\@.+\..{2,5}$
message: 'Email is not correct'
plz:
type: required
regex: ^\d{4,5}$
no_validate: 1
message: 'Invalid zip code'
country:
type: required
regex: ^[A-Z]{2,3}$
greeting:
enum:
- Herr
- Frau
- Firma
age:
t/conf/step_test.yml view on Meta::CPAN
---
step1:
email:
type: required
regex: ^[\w.-]+\@.+\..{2,5}$
message: 'Email is not correct'
plz:
type: required
regex: ^\d{4,5}$
no_validate: 1
message: 'Invalid zip code'
country:
type: required
regex: ^[A-Z]{2,3}$
greeting:
enum:
- Herr
- Frau
- Firma
age:
t/conf/test.yml view on Meta::CPAN
---
email:
type: required
regex: ^[\w.-]+\@.+\..{2,5}$
message: 'Email is not correct'
plz:
type: required
regex: ^\d{4,5}$
no_validate: 1
message: 'Invalid zip code'
country:
type: required
regex: ^[A-Z]{2,3}$
greeting:
enum:
- Herr
- Frau
- Firma
age:
---
Test:
email:
type: required
regex: ^[\w.-]+\@.+\..{2,5}$
message: 'Email is not correct'
plz:
type: required
regex: ^\d{4,5}$
no_validate: 1
message: 'Invalid zip code'
country:
type: required
regex: ^[A-Z]{2,3}$
greeting:
enum:
- Herr
- Frau
- Firma
age:
t/validate.t view on Meta::CPAN
## Webapp START
plugin('Data::Validate::WithYAML' => {
conf_path => app->home->child( 'conf' )->to_string,
error_prefix => 'TEST_',
});
any '/' => sub {
my $self = shift;
my %errors = $self->validate( 'test' );
$self->render( json => \%errors );
};
any '/hello' => \&hello;
sub hello {
my $self = shift;
my %errors = $self->validate;
$self->render( json => \%errors );
}
## Webapp END
my $t = Test::Mojo->new;
my %positive_check = ();
my %positive = (
email => 'test@test.de',
t/validate_config.t view on Meta::CPAN
is $error, '';
}
done_testing();
{
package
FieldInfoTest;
sub test {
$app->validate(@_);
}
}
t/validate_steps.t view on Meta::CPAN
plugin('Data::Validate::WithYAML' => {
conf_path => app->home->child( 'conf' )->to_string,
error_prefix => 'TEST_',
no_steps => 0,
});
any '/' => sub {
my $self = shift;
my %errors = $self->validate( step_test => 'step1' );
$self->render( json => \%errors );
};
## Webapp END
my $t = Test::Mojo->new;
my %positive_check = ();
my %positive = (
email => 'test@test.de',