Permalink
Browse files

* Switched to Module::Install

 * Added validation error bundling feature

git-svn-id: http://svn.unknownplace.org/public/library/perl/trunk/Catalyst-Plugin-FormValidator-Simple-Auto@405 325430d6-99fa-0310-bb67-a757393f56df
  • Loading branch information...
1 parent a920ea8 commit 33cfc9a87e465d2d9646d6d4fabaf588040ad1f6 typester committed Dec 22, 2006
Showing with 174 additions and 91 deletions.
  1. +0 −15 Build.PL
  2. +18 −2 MANIFEST
  3. +12 −0 MANIFEST.SKIP
  4. +12 −18 META.yml
  5. +11 −24 Makefile.PL
  6. +46 −14 README
  7. +75 −18 lib/Catalyst/Plugin/FormValidator/Simple/Auto.pm
View
@@ -1,15 +0,0 @@
-use Module::Build;
-
-# See perldoc Module::Build for details of how this works
-
-Module::Build->new(
- module_name => 'Catalyst::Plugin::FormValidator::Simple::Auto',
- license => 'perl',
- requires => {
- 'Catalyst' => '5.30',
- 'Catalyst::Plugin::FormValidator::Simple' => 0,
- 'UNIVERSAL::isa' => 0,
- 'YAML' => 0,
- },
- build_requires => { 'HTTP::Request::Common' => 0, },
-)->create_build_script;
View
@@ -1,14 +1,30 @@
-Build.PL
Changes
+inc/Module/Install.pm
+inc/Module/Install/Base.pm
+inc/Module/Install/Can.pm
+inc/Module/Install/Fetch.pm
+inc/Module/Install/Include.pm
+inc/Module/Install/Makefile.pm
+inc/Module/Install/Metadata.pm
+inc/Module/Install/TestBase.pm
+inc/Module/Install/Win32.pm
+inc/Module/Install/WriteAll.pm
+inc/Spiffy.pm
+inc/Test/Base.pm
+inc/Test/Base/Filter.pm
+inc/Test/Builder.pm
+inc/Test/Builder/Module.pm
+inc/Test/More.pm
lib/Catalyst/Plugin/FormValidator/Simple/Auto.pm
LICENSE
Makefile.PL
-MANIFEST
+MANIFEST This list of files
META.yml
README
t/01_load.t
t/02_basic.t
t/03_store_profile.t
+t/04_bundle_message.t
t/pod-coverage.t
t/pod.t
Todo
View
@@ -0,0 +1,12 @@
+\bRCS\b
+\bCVS\b
+^MANIFEST\.
+^Makefile$
+~$
+\.old$
+^blib/
+^pm_to_blib
+^MakeMaker-\d
+\.gz$
+\.cvsignore
+^9\d_.*\.t
View
@@ -1,24 +1,18 @@
----
-name: Catalyst-Plugin-FormValidator-Simple-Auto
-version: 0.08
-author:
- - 'Daisuke Murase <typester@cpan.org>'
abstract: Smart validation with FormValidator::Simple
+author: Daisuke Murase <typester@cpan.org>
+build_requires:
+ Test::More: 0
+distribution_type: module
+generated_by: Module::Install version 0.64
license: perl
-resources:
- license: http://dev.perl.org/licenses/
-requires:
+name: Catalyst-Plugin-FormValidator-Simple-Auto
+no_index:
+ directory:
+ - inc
+ - t
+requires:
Catalyst: 5.30
Catalyst::Plugin::FormValidator::Simple: 0
UNIVERSAL::isa: 0
YAML: 0
-build_requires:
- HTTP::Request::Common: 0
-provides:
- Catalyst::Plugin::FormValidator::Simple::Auto:
- file: lib/Catalyst/Plugin/FormValidator/Simple/Auto.pm
- version: 0.08
-generated_by: Module::Build version 0.2805
-meta-spec:
- url: http://module-build.sourceforge.net/META-spec-v1.2.html
- version: 1.2
+version: 0.09_01
View
@@ -1,27 +1,14 @@
-unless (eval "use Module::Build::Compat 0.02; 1" ) {
- print "This module requires Module::Build to install itself.\n";
+use inc::Module::Install;
+name 'Catalyst-Plugin-FormValidator-Simple-Auto';
+all_from 'lib/Catalyst/Plugin/FormValidator/Simple/Auto.pm';
- require ExtUtils::MakeMaker;
- my $yn = ExtUtils::MakeMaker::prompt
- (' Install Module::Build from CPAN?', 'y');
+build_requires 'Test::More';
- if ($yn =~ /^y/i) {
- require Cwd;
- require File::Spec;
- require CPAN;
+requires 'Catalyst' => '5.30';
+requires 'Catalyst::Plugin::FormValidator::Simple';
+requires 'UNIVERSAL::isa';
+requires 'YAML';
- # Save this 'cause CPAN will chdir all over the place.
- my $cwd = Cwd::cwd();
- my $makefile = File::Spec->rel2abs($0);
-
- CPAN::Shell->install('Module::Build::Compat');
-
- chdir $cwd or die "Cannot chdir() back to $cwd: $!";
- exec $^X, $makefile, @ARGV; # Redo now that we have Module::Build
- } else {
- warn " *** Cannot install without Module::Build. Exiting ...\n";
- exit 1;
- }
-}
-Module::Build::Compat->run_build_pl(args => \@ARGV);
-Module::Build::Compat->write_makefile();
+use_test_base;
+auto_include;
+WriteAll;
View
60 README
@@ -3,31 +3,35 @@ NAME
FormValidator::Simple
SYNOPSIS
+ Loading:
+
use Catalyst qw/
+ ConfigLoader
FormValidator::Simple
FormValidator::Simple::Auto
/;
-
- __PACKAGE__->config(
- validator => {
- messages => 'messages.yml',
- profiles => 'profiles.yml',
- # and other FormValidator::Simple config
- },
- );
-
-
- # profiles.yml
+
+ myapp.yml:
+
+ validator:
+ profiles: __path_to(profiles.yml)__
+ messages: __path_to(messages.yml)__
+ message_format: <span class="error">%s</span>
+ # and other FormValidator::Simple config
+
+ profiles.yml:
+
+ # profiles.yml
action1:
param1:
- NOT_BLANK
- ASCII
- [ 'LENGTH', 4, 10 ]
param2:
- NOT_BLANK
-
-
- # then your action
+
+ Then, using in your action:
+
sub action1 : Global {
my ($self, $c) = @_;
@@ -43,6 +47,34 @@ DESCRIPTION
You can define validation profiles into config or YAML file, and no
longer have to write it in actions.
+BUNDLING ERROR MESSAGES
+ With 0.08 or earlier version, you need define validator profiles and
+ error messages in separately.
+
+ So, you had to write two settings like this:
+
+ # profiles.yml
+ action1:
+ param1:
+ - NOT_BLANK
+
+ # messages.yml
+ action1:
+ param1:
+ NOT_BLANK: param1 is required!
+
+ It's bothered!
+
+ Since 0.09, you can place error messages in profiles config.
+
+ Above two configs is equals to:
+
+ # profiles.yml
+ action1:
+ param1:
+ - rule: NOT_BLANK
+ - message: param1 is required!
+
EXTENDED METHODS
setup
prepare
@@ -7,7 +7,7 @@ use Catalyst::Exception;
use UNIVERSAL::isa;
use YAML;
-our $VERSION = '0.08';
+our $VERSION = '0.09_01';
__PACKAGE__->mk_accessors(qw/validator_profile/);
@@ -17,20 +17,24 @@ Catalyst::Plugin::FormValidator::Simple::Auto - Smart validation with FormValida
=head1 SYNOPSIS
+Loading:
+
use Catalyst qw/
+ ConfigLoader
FormValidator::Simple
FormValidator::Simple::Auto
/;
-
- __PACKAGE__->config(
- validator => {
- messages => 'messages.yml',
- profiles => 'profiles.yml',
- # and other FormValidator::Simple config
- },
- );
-
-
+
+myapp.yml:
+
+ validator:
+ profiles: __path_to(profiles.yml)__
+ messages: __path_to(messages.yml)__
+ message_format: <span class="error">%s</span>
+ # and other FormValidator::Simple config
+
+profiles.yml:
+
# profiles.yml
action1:
param1:
@@ -39,9 +43,9 @@ Catalyst::Plugin::FormValidator::Simple::Auto - Smart validation with FormValida
- [ 'LENGTH', 4, 10 ]
param2:
- NOT_BLANK
-
-
- # then your action
+
+Then, using in your action:
+
sub action1 : Global {
my ($self, $c) = @_;
@@ -57,6 +61,35 @@ This plugin provide auto validation to Plugin::FormValidator::Simple.
You can define validation profiles into config or YAML file, and no longer have to write it in actions.
+=head1 BUNDLING ERROR MESSAGES
+
+With 0.08 or earlier version, you need define validator profiles and error messages in separately.
+
+So, you had to write two settings like this:
+
+ # profiles.yml
+ action1:
+ param1:
+ - NOT_BLANK
+
+ # messages.yml
+ action1:
+ param1:
+ NOT_BLANK: param1 is required!
+
+It's bothered!
+
+Since 0.09, you can place error messages in profiles config.
+
+Above two configs is equals to:
+
+ # profiles.yml
+ action1:
+ param1:
+ - rule: NOT_BLANK
+ - message: param1 is required!
+
+
=head1 EXTENDED METHODS
=head2 setup
@@ -65,24 +98,48 @@ You can define validation profiles into config or YAML file, and no longer have
sub setup {
my $c = shift;
+ my $config = $c->config->{validator};
Catalyst::Exception->throw( message =>
__PACKAGE__ . qq/: You need to load "Catalyst::Plugin::FormValidator::Simple"/ )
unless $c->isa('Catalyst::Plugin::FormValidator::Simple');
Catalyst::Exception->throw(
message => __PACKAGE__ . qq/: You must set validator profiles/ )
- unless $c->config->{validator}->{profiles};
+ unless $config->{profiles};
- if ( ref $c->config->{validator}->{profiles} ne 'HASH' ) {
+ if ( ref $config->{profiles} ne 'HASH' ) {
my $profiles = eval {
- YAML::LoadFile( $c->config->{validator}->{profiles} );
+ YAML::LoadFile( $config->{profiles} );
};
Catalyst::Exception->throw( message => __PACKAGE__ . qq/: $@/ ) if $@;
- $c->config->{validator}->{profiles} = $profiles;
+ $config->{profiles} = $profiles;
}
+ my $messages;
+ my $profiles = $config->{profiles};
+ for my $action ( keys %{ $profiles || {} } ) {
+ my $profile = $profiles->{$action} || {};
+
+ for my $param ( keys %$profile ) {
+ my $rules = $profile->{$param} || [];
+
+ for my $rule (@$rules) {
+
+ if ( ref $rule eq 'HASH'
+ and defined $rule->{rule} && defined $rule->{message} )
+ {
+ $messages->{$action}{$param}{ $rule->{rule} } = $rule->{message};
+ $rule = $rule->{rule};
+ }
+ }
+ }
+ }
+
+ # XXX: replace messages. ponder about hash merging
+ $config->{messages} = $messages if $messages;
+
# fix plugin order
{
no strict 'refs';

0 comments on commit 33cfc9a

Please sign in to comment.