[Catalyst-commits] r8249 -
Catalyst-Controller-DBIC-API/1.001/trunk/lib/Catalyst/Controller/DBIC/API
jshirley at dev.catalyst.perl.org
jshirley at dev.catalyst.perl.org
Thu Aug 21 20:34:10 BST 2008
Author: jshirley
Date: 2008-08-21 20:34:10 +0100 (Thu, 21 Aug 2008)
New Revision: 8249
Modified:
Catalyst-Controller-DBIC-API/1.001/trunk/lib/Catalyst/Controller/DBIC/API/Base.pm
Log:
Two changes:
- Use HashRefInflator on the list method to speed things up
- Check explicit defined, in case implied check is false when object still exists
Modified: Catalyst-Controller-DBIC-API/1.001/trunk/lib/Catalyst/Controller/DBIC/API/Base.pm
===================================================================
--- Catalyst-Controller-DBIC-API/1.001/trunk/lib/Catalyst/Controller/DBIC/API/Base.pm 2008-08-21 14:46:39 UTC (rev 8248)
+++ Catalyst-Controller-DBIC-API/1.001/trunk/lib/Catalyst/Controller/DBIC/API/Base.pm 2008-08-21 19:34:10 UTC (rev 8249)
@@ -5,6 +5,8 @@
use warnings;
use base qw/Catalyst::Controller CGI::Expand/;
+use DBIx::Class::ResultClass::HashRefInflator;
+
__PACKAGE__->mk_accessors(qw(
class create_requires update_requires update_allows $self->rs_stash_key create_allows list_count list_returns list_grouped_by list_ordered_by rs_stash_key object_stash_key setup_list_method
));
@@ -90,8 +92,11 @@
sub format_list :Private {
my ($self, $c) = @_;
- my @ret = map { { $_->get_columns } } $c->stash->{$self->rs_stash_key}->all;
- $c->stash->{response}->{list} = \@ret;
+ # Create another result set here, so if someone looks at $self->rs_stash_key
+ # it still is what they expect (and not inflating to a hash ref)
+ my $rs = $c->stash->{$self->rs_stash_key}->search;
+ $rs->result_class('DBIx::Class::ResultClass::HashRefInflator');
+ $c->stash->{response}->{list} = [ $rs->all ];
}
sub create :Private {
@@ -115,7 +120,8 @@
my $req_params = (grep { ref $_ } values %{$c->req->params}) ? $c->req->params : $self->expand_hash($c->req->params);
$c->req->params($req_params);
- return unless ($c->stash->{$self->object_stash_key});
+ die "no object to update (looking at " . $self->object_stash_key . ")"
+ unless ( defined $c->stash->{$self->object_stash_key} );
unless (ref($c->stash->{update_allows} || $self->update_allows) eq 'ARRAY') {
die "update_allows must be an arrayref in config or stash";
@@ -138,7 +144,6 @@
sub validate_and_save_object {
my ($self, $c, $object) = @_;
-
my $params;
unless ($params = $self->validate($c, $object)) {
$c->log->debug("No value from validate, cowardly bailing out")
@@ -200,7 +205,7 @@
unless (defined $value) {
$self->push_error($c, { message => "No value supplied for ${key} and no default" });
}
- }
+ }
}
# TODO: do automatic col type checking here
More information about the Catalyst-commits
mailing list