Hi, guys, I have been trying to create some custom constraints for my form attributes. I use Catalyst::Plugin::FormValidator
when I call my custom subroutine that handles a custom constraint, I notice it will not get the attribute value. I have looked up the docs for 1) Data::FormValidator::Constraints 2) Catalyst::Plugin::FormValidator and tutorial (Data::FormValidator::Tutorial ) and nothing seems to help. Looking at the tutorial (http://search.cpan.org/~purdy/Data-FormValidator-Tutorial-1.61/lib/Data/FormValidator/Tutorial.pm), I decided to build my own constraint subroutines. Here's what I refered to in the tute: --------------- TUTE Extract Start ------------------------ ... 'email' => \&my_domain_email(), ... sub my_domain_email { ... } --------------- TUTE Extract End ------------------------ And this is what I implemented: --------------- MyApp/Controller/User.pm Extract Start ---------------------- sub _get_validation_profile { my $required = [ qq{lc_abn}, qq{lc_company_name}, qq{mc_telephone}, qq{add_postcode}, qq{add_state}, qq{add_street}, qq{add_street_number}, qq{add_suburb}, qq{ba_postcode}, qq{ba_state}, qq{ba_street}, qq{ba_street_number}, qq{ba_suburb}, qq{lc_login_id}, qq{lc_password}, ]; my $optional = [ qq{mc_email}, qq{mc_first_name}, qq{mc_last_name}, qq{mc_mobile}, ]; my $defaults = { qq{add_country} => 'Australia', qq{ba_country} => 'Australia', }; my $constraints= { qq{mc_email} => email(), qq{lc_abn} => FV_min_length(5), qq{mc_telephone} => FV_min_length(9), qq{add_postcode} =>gozila::Controller::Shared->FV_postcode, qq{add_state} => gozila::Controller::Shared->FV_state, qq{add_street} => FV_min_length(5), qq{add_street_number} => sub { my $elem = shift; return ( $elem =~ m{\w+} ? 1 : 0 ); }, qq{add_suburb} => FV_min_length(2), qq{ba_postcode} => gozila::Controller::Shared->FV_postcode, qq{ba_state} => gozila::Controller::Shared->FV_state, qq{ba_street} => FV_min_length(5), qq{ba_street_number} => sub { my $elem = shift; return ( $elem =~ m{\w+} ? 1 : 0 ); }, qq{ba_suburb} => FV_min_length(2), qq{lc_login_id} => FV_min_length(5), qq{lc_password} => FV_min_length(5), }; return { 'required' => $required, 'optional' => $optional, 'defaults' => $defaults, 'constraints' => $constraints, }; } --------------- MyApp/Controller/User.pm Extract End ------------------------ --------------- MyApp/Controller/Shared.pm Extract Start -------------------- sub FV_postcode { my ($self, $given_postcode) = @_; Line: 100 return ( $given_postcode >= 200 ? 1 : 0 ); } sub FV_state { my ($self, $given_state) = @_; Line: 106 return ( $given_state =~ m{^(VIC|ACT|NSW|TAS|WA|SA|NT|QLD)$}smx ? 1 : 0 ); } --------------- MyApp/Controller/Shared.pm Extract End ---------------------- the fault here is that I get the error listed below which means that the subroutines which I have defined are not getting anything... Use of uninitialized value in numeric ge (>=) at /home/kakimoto/projects/myApp/t/../lib/myApp/Controller/Shared.pm line 100. Use of uninitialized value in pattern match (m//) at /home/kakimoto/projects/myApp/t/../lib/myApp/Controller/Shared.pm line 106. Use of uninitialized value in numeric ge (>=) at /home/kakimoto/projects/myApp/t/../lib/myApp/Controller/Shared.pm line 100. Use of uninitialized value in pattern match (m//) at /home/kakimoto/projects/myApp/t/../lib/myApp/Controller/Shared.pm line 106. Any ideas? Thank you:) _______________________________________________ List: [email protected] Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[email protected]/ Dev site: http://dev.catalyst.perl.org/
