[Pas-dev] Another Propsal - Parameter Maps?
Status: Beta
Brought to you by:
mortis
From: Kyle R . B. <mo...@vo...> - 2003-03-26 14:22:14
|
package Com::Domain::Site::AccountSetup; use strict; use warnings; use Org::Bgw::Pas::Page; our @ISA = qw( Org::Bgw::Pas::Page ); Com::Domain::Site::AccountSetup->buildRequestParameterMap( 'first_name' => 'firstName', 'last_name' => 'lastName', 'middle' => 'middleName', ); # buildRequestParameterMap would do a few things, first it would use the # values of the passed pairs and effectivly call: # Com::Domain::Site::AccountSetup->makeGetSetMethods(qw( firstName lastName )); # for you. Second, it sets up a method (that will be called from # SUPER::request_init that moves parameters from the request object into # your object's get/set methods. sub execute { my($self) = @_; # now just use the params! they're already available in your get/set # methods } ######################################## ######################################## # # extension 1, allow for 'scurbbing' or mutating to take place: # Com::Domain::Site::AccountSetup->buildRequestParameterMap( 'first_name' => { 'slot' => 'firstName', 'mutator' => 'scrubName' }, 'last_name' => { 'slot' => 'lastName', 'mutator' => 'scrubName' }, 'middle' => { 'slot' => 'middleName', 'mutator' => 'scrubName' }, ); # this gets called for each defined param that has this method # as it's mutator - then the data returned by this method is # assigned to the appropriate get/set method (which again are # automatically created based on the 'slot' values from the mapping). sub scrubName { my($self,$data) = @_; $data =~ s/\d+//; return $data; } sub execute { my($self) = @_; # now just use the params! they're already available in your get/set # methods, and they've been passed through the scrubbing methods } -- ------------------------------------------------------------------------------ Wisdom and Compassion are inseparable. -- Christmas Humphreys mo...@vo... http://www.voicenet.com/~mortis ------------------------------------------------------------------------------ |