DBIx::...LWidget(3pm)

πŸ“¦
version 0.16 Β· 3 versions
, in debian bookworm, ubuntu jammy, ubuntu noble

πŸ’– 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