Net::LDAP::HTMLWidget - Like FromForm but with Net::LDAP and HTML::Widget
You'll need a working Net::LDAP setup and some knowledge of HTML::Widget and Catalyst. If you have no idea what I'm talking about, check the (sparse) docs of those modules.
package My::Controller::Pet; # Catalyst-style # define the widget in a sub (DRY) sub widget_pet { my ($self,$c)=@_; my $w=$c->widget('pet')->method('get'); $w->element('Textfield','name')->label('Name'); $w->element('Textfield','age')->label('Age'); ... return $w; } # this renders an edit form with values filled in from the DB sub edit : Local { my ($self,$c,$id)=@_; # get the object my $item=$c->model('LDAP')->search(uid=>$id); $c->stash->{item}=$item; # get the widget my $w=$self->widget_pet($c); $w->action($c->uri_for('do_edit/'.$id)); # fill widget with data from DB Net::LDAP::HTMLWidget->fill_widget($item,$w); } sub do_edit : Local { my ($self,$c,$id)=@_; # get the object from DB my $item=$c->model('LDAP')->search(uid=>$id); $c->stash->{item}=$item; $ get the widget my $w=$self->widget_pet($c); $w->action($c->uri_for('do_edit/'.$id)); # process the form parameters my $result = $w->process($c->req); $c->stash->{'result'}=$result; # if there are no errors save the form values to the object unless ($result->has_errors) { Net::LDAP::HTMLWidget->populate_from_widget($item,$result); $c->res->redirect('/users/pet/'.$id); } }
Something like Class::DBI::FromForm / Class::DBI::FromCGI but using HTML::Widget for form creation and validation and Net::LDAP.
Fill the values of a widgets elements with the values of the LDAP object.
Updates the $item with new values from $result and updated using $ldap_connection.
As a result of utf-8 handling in general beeing a pain in the ass, we also provide an bad hack to work around certain odities.
We have a package scoped variabel called DECODE which, if set, will cause values from the ldap-server to be decoded from that encoding to perls internal string format before it gets added to the HTML::Widget
package MyApp::LDAP::Entry; use base qw/Net::LDAP::HTMLWidget/; $Net::LDAP::HTMLWidget::DECODE = 'utf-8'; 1;
Thomas Klausner, <domm@cpan.org>, http://domm.zsi.at Marcus Ramberg, <mramberg@cpan.org> Andreas Marienborg, <andremar@cpan.org>
This code is Copyright (c) 2003-2006 Thomas Klausner. All rights reserved.
You may use and distribute this module according to the same terms that Perl is distributed under.
To install Net::LDAP::HTMLWidget, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Net::LDAP::HTMLWidget
CPAN shell
perl -MCPAN -e shell install Net::LDAP::HTMLWidget
For more information on module installation, please visit the detailed CPAN module installation guide.