DBIx::...LWidget(3pm)
π DBIx::Class::HTMLWidget π
okay bestie, buckle up π this is the 3pm manual page for DBIx::Class::HTMLWidget, straight out of the User Contributed Perl Documentation. it's giving very specific, very useful, very niche. let's go. π
πΈ NAME πΈ
DBIx::Class::HTMLWidget β it's like FromForm, but make it DBIx::Class and HTML::Widget. iconic combo honestly β¨
π« SYNOPSIS π«
Before you even look at this, bestie, you need two things: a working DBIx::Class setup, and some actual knowledge of HTML::Widget and Catalyst. if you're sitting there like "what is she even talking about", go read the (sparse) docs of those modules. yes, sparse β that's a direct quote, the docs are lowkey minimal π. not my problem, i'm just the messenger.
package My::Model::DBIC::Pet;
use base 'DBIx::Class';
__PACKAGE__->load_components(qw/HTMLWidget Core/);
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('DBIC::Pet')->find($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
$item->fill_widget($w);
}
sub do_edit : Local {
my ($self,$c,$id)=@_;
# get the object from DB
my $item=$c->model('DBIC::Pet')->find($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) {
$item->populate_from_widget($result);
$c->res->redirect('/users/pet/'.$id);
}
}
like, look at that. DRY widget definition, edit form filled from the DB, form processed, errors checked, redirect on success. the whole flow is right there. ate. π₯
π¦ DESCRIPTION π¦
So it's basically Class::DBI::FromForm / Class::DBI::FromCGI energy, but with the glow-up: HTML::Widget does the form creation and validation, and DBIx::Class is your ORM. that's the whole vibe check. π«Ά
β¨ Methods β¨
π fill_widget
$dbic_object->fill_widget($widget);
It fills the values of a widget's elements with the values from the DBIC object. that's it. that's the job. no notes. π
π populate_from_widget
my $obj=$schema->resultset('pet)->new->populate_from_widget($result);
my $item->populate_from_widget($result);
Create or update a DBIx::Class row from a HTML::Widget::Result object. new row, existing row, she does both. versatile queen. π
π CAEVATS / POSSIBLE PROBLEMS π
yes the heading is spelled like that. i don't make the rules, i just preserve them. moving on.
π PostgreSQL π
ERROR: null value in column "private" violates not-null constraint
So what's happening here, bestie: we're trying to set a value to undef that genuinely should not be undef. this is typically a problem when you have a column such ass private boolean not null. yes. "such ass". preserved. π
good news though β there's a special-case for this exact situation. if you set data_type => boolean, is_nullable => 0 in your ResultSource definition, we update the value to 0 before attempting to insert or update. crisis averted, slay. β¨
ngl this one will bite you if you don't set those two attributes, so set them. fr fr.
π AUTHORS π
- Thomas Klausner,
<domm@cpan.org>,http://domm.zsi.at - Marcus Ramberg,
<mramberg@cpan.org> - Andreas Marienborg,
<omega@palle.net>
π¦ CONTRIBUTORS π¦
- Simon Elliott,
<cpan@browsing.co.uk> - Ashley Berlin
- Guillermo Sansovic
π LICENSE π
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. iykyk. π
and that's the whole page, bestie β no skips, no summaries, every last detail intact. this was the DBIx::...LWidget(3pm) page, brought to you by perl v5.32.0, dated 2021-01-25. she's a little vintage, she's a little niche, and she absolutely understood the assignment. periodt. πβ¨π«Ά
π¦ where this page comes from
- debian bookworm: libdbix-class-htmlwidget-perl 0.16-6 Β· GPL-1.0-or-later OR Artistic-1
- ubuntu jammy: libdbix-class-htmlwidget-perl 0.16-6 Β· GPL-1.0-or-later OR Artistic-1
- ubuntu noble: libdbix-class-htmlwidget-perl 0.16-6 Β· GPL-1.0-or-later OR Artistic-1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms