DBIx-Class-HTMLWidget-0.16/ 0000755 0000765 0000765 00000000000 10752310611 015021 5 ustar andreas andreas DBIx-Class-HTMLWidget-0.16/Changes 0000644 0000765 0000765 00000003567 10752310512 016327 0 ustar andreas andreas Revision history for DBIx-Class-HTMLWidget
0.16 2008-02-06
- Fix manifest
0.15 2008-02-05
- Note to self: COPYFILE_DISABLE=1
0.14 2008-02-05
- Missing dep
0.13 2008-02-05
- Bad dist 0.12
0.12 2008-02-05
- Special case columns data_type => boolean, is_nullable => 0 for postgres, as they
can't handle undef as value, they need 0.
0.11
- Backwards incompatible change: If an element has a value when fill_form is run, it
will not be overwritten with a new value.
0.10
- Fix problem with undefing values not properly updating on postgres
0.09
- Changed from using set_column($col, $value) to $col($value)
(Thanks to Matt S. Trout for report)
- Fix undef check to ignore refs, silencing DateTime comparison with string
(Thanks to Marcus Ramberg for report)
- Fix uninitialized warning
(Thanks to Marcus Ramberg)
0.08 2006-11-26 09:37
- Updated deps to make sure we use the latest HTML::Widget, with
multi-level support
- Fix for DBIx::Class::InflateColumn::DateTime and the one-to-many support
(Thanks to Guillermo Sansovic)
- More HTML-Widget fixes from omega.
0.07 2006-10-10 14:03
- Fix for checkboxes again
- properly use the new embedded structures
0.06 2006-06-22 14:33
- Fixes for embedded widgets and numerous other goodies (thanks omega!)
0.05 2006-06-03 18:43
- Blank out password fields.
- Iterates the Widget elements on insert for security reasons (thanks ash!)
0.04 ?
- Supports embedded widgets
0.03 2006-04-13 12:24
- Fixed outdated pod synopsis. (thanks dave)
- Fixed so empty values doesn't get set to 0. (thanks alex)
- Use get_column to avoid inflation instead.
0.02 2006-01-25 15:06
- Fix checkboxes
- Fix foreign keys.
0.01 2006-01-25 15:06
First version, released on an unsuspecting world.
DBIx-Class-HTMLWidget-0.16/lib/ 0000755 0000765 0000765 00000000000 10752310611 015567 5 ustar andreas andreas DBIx-Class-HTMLWidget-0.16/lib/DBIx/ 0000755 0000765 0000765 00000000000 10752310611 016355 5 ustar andreas andreas DBIx-Class-HTMLWidget-0.16/lib/DBIx/Class/ 0000755 0000765 0000765 00000000000 10752310611 017422 5 ustar andreas andreas DBIx-Class-HTMLWidget-0.16/lib/DBIx/Class/HTMLWidget.pm 0000644 0000765 0000765 00000014034 10752310564 021701 0 ustar andreas andreas package DBIx::Class::HTMLWidget;
use strict;
use warnings;
use Carp;
#use Data::Dump qw(dump);
our $VERSION = '0.16';
# pod after __END__
sub fill_widget {
my ($dbic,$widget)=@_;
croak('fill_widget needs a HTML::Widget object as argument')
unless ref $widget && $widget->isa('HTML::Widget');
my @real_elements = $widget->find_elements;
foreach my $element ( @real_elements ) {
my $name=$element->name;
next unless $name && $dbic->can($name) && $element->can('value');
next if ($element->value());
if($element->isa('HTML::Widget::Element::Checkbox')) {
$element->checked($dbic->$name?1:0);
} else {
if (ref $dbic->$name and $dbic->$name->can('id') and $dbic->$name->id) {
$element->value($dbic->$name->id);
} else {
$element->value($dbic->$name)
unless $element->isa('HTML::Widget::Element::Password');
}
}
}
}
sub populate_from_widget {
my ($dbic,$result)=@_;
croak('populate_from_widget needs a HTML::Widget::Result object as argument')
unless ref $result && $result->isa('HTML::Widget::Result');
# find all checkboxes
my %cb = map {$_->name => undef } grep { $_->isa('HTML::Widget::Element::Checkbox') }
$result->find_elements;
foreach my $col ( $dbic->result_source->columns ) {
my $col_info = $dbic->column_info($col);
my $value = scalar($result->param($col));
if ($col_info->{data_type} and $col_info->{data_type} =~ m/^timestamp|date|integer|numeric/i
and defined $value and $value eq '') {
$value = undef;
$dbic->$col(undef);
}
if (defined($value) and !ref($value) and $value eq 'undef') {
$dbic->$col(undef);
$value = undef;
}
if ($col_info->{data_type} and $col_info->{data_type} =~ m/boolean/i
&& exists $col_info->{is_nullable} && !$col_info->{is_nullable}
&& exists $cb{$col} && !defined($value)
&& $dbic->result_source->schema->storage->sqlt_type eq 'PostgreSQL') {
# We need to set the value to 0 if it is postgres
$value = 0;
}
$dbic->$col($value)
if defined $value || exists $cb{$col};
}
$dbic->insert_or_update;
return $dbic;
}
sub experimental_populate_from_widget {
my ($dbic,$result)=@_;
foreach (@{$result->{_elements}} ) {
# Its called a fair few times so save name
my $name = $_->name;
#prevent passwords being overwritten.
next if $_->isa('HTML::Widget::Element::Password') && $result->param($name) eq "";
$dbic->set_column($name, scalar $result->param($name))
if (defined $result->param($name) || $_->isa('HTML::Widget::Element::Checkbox')) &&
# Ignore this element if its readonly or not in the DBIC
!$_->{attributes}{readonly} && $dbic->has_column($name);
}
$dbic->insert_or_update;
return $dbic;
}
1;
__END__
=pod
=head1 NAME
DBIx::Class::HTMLWidget - Like FromForm but with DBIx::Class and HTML::Widget
=head1 SYNOPSIS
You'll need a working DBIx::Class 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::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);
}
}
=head1 DESCRIPTION
Something like Class::DBI::FromForm / Class::DBI::FromCGI but using
HTML::Widget for form creation and validation and DBIx::Class as a ORM.
=head2 Methods
=head3 fill_widget
$dbic_object->fill_widget($widget);
Fill the values of a widgets elements with the values of the DBIC object.
=head3 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
=head1 CAEVATS / POSSIBLE PROBLEMS
=head2 PostgreSQL
=head3 ERROR: null value in column "private" violates not-null constraint
This is a result of we trying to set a value to undef that should not be. This is typicaly
a problem when you have a colum such ass "private boolean not null". We have a special-case
for this, and 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
=head1 AUTHORS
Thomas Klausner, , http://domm.zsi.at
Marcus Ramberg,
Andreas Marienborg,
=head1 CONTRIBUTORS
Simon Elliott,
Ashley Berlin
Guillermo Sansovic
=head1 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.
=cut
DBIx-Class-HTMLWidget-0.16/Makefile.PL 0000644 0000765 0000765 00000000376 10752026772 017015 0 ustar andreas andreas use ExtUtils::MakeMaker;
WriteMakefile(
'NAME' => 'DBIx::Class::HTMLWidget',
'VERSION_FROM' => 'lib/DBIx/Class/HTMLWidget.pm',
'PREREQ_PM' => {
HTML::Widget => '1.10',
DBIx::Class => 0.05,
},
);
DBIx-Class-HTMLWidget-0.16/MANIFEST 0000644 0000765 0000765 00000000275 10752310612 016157 0 ustar andreas andreas Changes
lib/DBIx/Class/HTMLWidget.pm
Makefile.PL
MANIFEST
MANIFEST.skip
t/01use.t
t/02pod.t
t/03podcoverage.t
META.yml Module meta-data (added by MakeMaker)
DBIx-Class-HTMLWidget-0.16/MANIFEST.skip 0000644 0000765 0000765 00000000076 10752310543 017126 0 ustar andreas andreas .*\.tar\.gz$
.*\.tar$
blib
Makefile$
Makefile.old
MANIFEST.bak DBIx-Class-HTMLWidget-0.16/META.yml 0000644 0000765 0000765 00000000626 10752310611 016276 0 ustar andreas andreas # http://module-build.sourceforge.net/META-spec.html
#XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX#
name: DBIx-Class-HTMLWidget
version: 0.16
version_from: lib/DBIx/Class/HTMLWidget.pm
installdirs: site
requires:
DBIx::Class: 0.05
HTML::Widget: 1.10
distribution_type: module
generated_by: ExtUtils::MakeMaker version 6.30
DBIx-Class-HTMLWidget-0.16/t/ 0000755 0000765 0000765 00000000000 10752310611 015264 5 ustar andreas andreas DBIx-Class-HTMLWidget-0.16/t/01use.t 0000644 0000765 0000765 00000000130 10752026772 016414 0 ustar andreas andreas use strict;
use Test::More tests => 1;
BEGIN {
use_ok 'DBIx::Class::HTMLWidget';
}
DBIx-Class-HTMLWidget-0.16/t/02pod.t 0000644 0000765 0000765 00000000276 10752026772 016416 0 ustar andreas andreas use Test::More;
eval "use Test::Pod 1.14";
plan skip_all => 'Test::Pod 1.14 required' if $@;
plan skip_all => 'set TEST_POD to enable this test' unless $ENV{TEST_POD};
all_pod_files_ok();
DBIx-Class-HTMLWidget-0.16/t/03podcoverage.t 0000644 0000765 0000765 00000000325 10752026772 020126 0 ustar andreas andreas use Test::More;
eval "use Test::Pod::Coverage 1.04";
plan skip_all => 'Test::Pod::Coverage 1.04 required' if $@;
plan skip_all => 'set TEST_POD to enable this test' unless $ENV{TEST_POD};
all_pod_coverage_ok();