Changeset 13586
- Timestamp:
- 06/09/08 19:05:52 (5 years ago)
- Location:
- lang/perl/FormValidator-LazyWay/branches/rebuild
- Files:
-
- 1 removed
- 5 modified
- 1 copied
-
lib/FormValidator/LazyWay.pm (modified) (7 diffs)
-
lib/FormValidator/LazyWay/Utils.pm (modified) (1 diff)
-
t/lazyway-check-conv-profile.t (modified) (2 diffs)
-
t/lazyway-check-must-b-plural.t (deleted)
-
t/lazyway-check-remove-empty-fields.t (modified) (1 diff)
-
t/lazyway-check-required-fields.t (copied) (copied from lang/perl/FormValidator-LazyWay/branches/rebuild/t/lazyway-check-erquired-fields.t) (2 diffs)
-
t/utils-check-profile-syntax.t (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/FormValidator-LazyWay/branches/rebuild/lib/FormValidator/LazyWay.pm
r13550 r13586 30 30 my $result = {}; 31 31 my $storage = { 32 valid => FormValidator::LazyWay::Utils::get_input_as_hash($input), 33 missings => [], 34 overflows => [], 35 unknown => [], 36 invalid => {}, 32 valid => FormValidator::LazyWay::Utils::get_input_as_hash($input), 33 missing => [], 34 unknown => [], 35 invalid => {}, 37 36 }; 38 37 … … 40 39 41 40 my @subs = ( 41 42 42 # profileを扱いやすい型にコンバート 43 sub { $self->_conv_profile(@_) } , 43 sub { $self->_conv_profile(@_) }, 44 44 45 # デフォルトセット 45 46 sub { $self->_set_default(@_) }, 47 46 48 # 空白のフィールドのキーを消去 47 49 sub { $self->_remove_empty_fields(@_) }, 50 48 51 # 未定義のフィールドをセット、そしてvalidから消去 49 52 sub { $self->_set_unknown(@_) }, 53 50 54 # missingのフィールドをセット、そしてvalidから消去 51 55 sub { $self->_check_required_fields(@_) }, 52 # 複数定義(missing,overfolows)のフィールドをセット、そしてvalidから消去 53 # TODO : エラーメッセージに、指定数が入るようにできた方がいいなぁ。 54 sub { $self->_check_must_be_plural(@_) }, 56 55 57 # invalidチェックループ 56 58 sub { $self->_validation_block(@_) }, 59 57 60 # エラーメッセージセット 58 61 sub { $self->_set_error_message(@_) }, … … 77 80 my @fields = keys %{ $storage->{valid} }; 78 81 79 for my $field ( @fields) {82 for my $field (@fields) { 80 83 my $is_invalid = 0; 81 # missing , overflows , empty optional82 next unless exists $storage->{valid}{$field};83 84 84 } 85 # missing , empty optional 86 next unless exists $storage->{valid}{$field}; 85 87 86 }87 88 sub _check_must_be_plural {89 my $self = shift;90 my $storage = shift;91 my $profile = shift;92 93 foreach my $field ( keys %{ $profile->{must_be_plural} } ) {94 if ( ref $storage->{valid}{$field} eq 'ARRAY' ) {95 # TODO: missing or overflows96 unless (97 scalar @{ $storage->{valid}{$field} }98 == $profile->{must_be_plural}{$field} )99 {100 push @{ $storage->{overflows} }, $field;101 delete $storage->{valid}{$field};102 }103 }104 else {105 push @{ $storage->{overflows} }, $field;106 delete $storage->{valid}{$field};107 }108 88 } 109 89 … … 116 96 117 97 for my $field ( keys %{ $profile->{required} } ) { 118 push @{ $storage->{missing s} }, $field98 push @{ $storage->{missing} }, $field 119 99 unless exists $storage->{valid}{$field}; 120 100 delete $storage->{valid}{$field} … … 125 105 126 106 sub _conv_profile { 127 my $self = shift;128 my $storage = shift;129 my $profile = shift;107 my $self = shift; 108 my $storage = shift; 109 my $profile = shift; 130 110 my %new_profile = (); 131 %{ $new_profile{required}} = map { $_ => 1 }111 %{ $new_profile{required} } = map { $_ => 1 } 132 112 FormValidator::LazyWay::Utils::arrayify( $profile->{required} ); 133 %{ $new_profile{optional}} = map { $_ => 1 }113 %{ $new_profile{optional} } = map { $_ => 1 } 134 114 FormValidator::LazyWay::Utils::arrayify( $profile->{optional} ); 135 %{$new_profile{may_be_plural}} 136 = map { $_ => 1 } 137 FormValidator::LazyWay::Utils::arrayify( $profile->{may_be_plural} ); 138 %{$new_profile{must_be_plural}} 139 = map { $_ => 1 } 140 FormValidator::LazyWay::Utils::arrayify( $profile->{must_be_plural} ); 141 %{$profile} = ( %{$profile}, %new_profile ) ; 115 %{ $new_profile{want_array} } = map { $_ => 1 } 116 FormValidator::LazyWay::Utils::arrayify( $profile->{want_array} ); 117 %{$profile} = ( %{$profile}, %new_profile ); 142 118 } 143 119 … … 147 123 my $profile = shift; 148 124 149 @{ $storage->{unknown} } 150 = grep {151 not( exists $profile->{optional}{$_}or exists $profile->{required}{$_} )152 } keys %{ $storage->{valid} };125 @{ $storage->{unknown} } = grep { 126 not( exists $profile->{optional}{$_} 127 or exists $profile->{required}{$_} ) 128 } keys %{ $storage->{valid} }; 153 129 154 130 # and remove them from the list … … 156 132 delete $storage->{valid}{$field}; 157 133 } 158 159 134 160 135 } -
lang/perl/FormValidator-LazyWay/branches/rebuild/lib/FormValidator/LazyWay/Utils.pm
r13411 r13586 20 20 required 21 21 defaults 22 may_be_plural 23 must_be_plural 22 want_array 24 23 lang 25 24 / -
lang/perl/FormValidator-LazyWay/branches/rebuild/t/lazyway-check-conv-profile.t
r13550 r13586 1 1 use Test::Base; 2 use FormValidator::LazyWay; 3 use FindBin; 4 use File::Spec; 5 use lib File::Spec->catfile( $FindBin::Bin, 'lib' ); 2 6 3 7 plan tests => 1 * blocks; … … 5 9 run { 6 10 my $block = shift; 7 ok(0, 'please write test'); 11 my $profile = $block->profile; 12 FormValidator::LazyWay->_conv_profile( undef , $profile ); 13 is_deeply( $profile , $block->result ); 8 14 } 9 15 10 16 __END__ 11 17 === normal 18 --- profile eval 19 { 20 required => [qw/foo bar/], 21 optional => [qw/foo bar hoge/], 22 want_array => [qw/oppai/], 23 } 24 --- result eval 25 { 26 required => { 27 foo => 1, 28 bar => 1, 29 }, 30 optional => { 31 foo => 1, 32 bar => 1, 33 hoge => 1, 34 }, 35 want_array => { 36 oppai => 1, 37 }, 38 } -
lang/perl/FormValidator-LazyWay/branches/rebuild/t/lazyway-check-remove-empty-fields.t
r13428 r13586 14 14 is_deeply( $storage , $block->result ); 15 15 } 16 17 16 __END__ 18 17 === set default -
lang/perl/FormValidator-LazyWay/branches/rebuild/t/lazyway-check-required-fields.t
r13550 r13586 1 1 use Test::Base; 2 use FormValidator::LazyWay; 3 use FindBin; 4 use File::Spec; 5 use lib File::Spec->catfile( $FindBin::Bin, 'lib' ); 2 6 3 7 plan tests => 1 * blocks; … … 5 9 run { 6 10 my $block = shift; 7 ok(0, 'please write test'); 11 my $storage = $block->storage; 12 my $profile = $block->profile; 13 FormValidator::LazyWay->_conv_profile( $storage , $profile ); 14 FormValidator::LazyWay->_check_required_fields( $storage , $profile ); 15 is_deeply( $storage , $block->result ); 8 16 } 9 17 10 18 __END__ 11 19 === normal 20 --- profile eval 21 { 22 required => [qw/foo bar/], 23 } 24 --- storage eval 25 { 26 valid => { 27 foo =>'hoge', 28 moo =>'hoge', 29 }, 30 missing => [], 31 } 32 --- result eval 33 { 34 valid => { 35 foo =>'hoge', 36 moo => 'hoge', 37 }, 38 missing => [ 39 'bar', 40 ], 41 } -
lang/perl/FormValidator-LazyWay/branches/rebuild/t/utils-check-profile-syntax.t
r13409 r13586 6 6 7 7 ok( FormValidator::LazyWay::Utils::check_profile_syntax( 8 { constraints => [], 9 optional => [], 10 required => [], 11 defaults => [], 12 may_be_plural => [], 13 must_be_plural => [], 14 lang => [], 15 use_loose => [], 16 use_foo => [], 8 { constraints => [], 9 optional => [], 10 required => [], 11 defaults => [], 12 want_array => [], 13 lang => [], 14 use_loose => [], 15 use_foo => [], 17 16 } 18 17 )
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)