[Jifty-commit] r2053 - in jifty/trunk/lib/Jifty: Action
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Sun Oct 22 20:21:49 EDT 2006
Author: audreyt
Date: Sun Oct 22 20:21:49 2006
New Revision: 2053
Modified:
jifty/trunk/lib/Jifty/Action/Record.pm
jifty/trunk/lib/Jifty/Param/Schema.pm
Log:
* Jifty::Param::Schema: Allow partial override of superclass's PARAMS
by simply declaring a sub "param" and fill them with the fields
you'd override.
* Jifty::Action::Record: Allow the same for user-generated param vs
CRUD actions.
Modified: jifty/trunk/lib/Jifty/Action/Record.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Action/Record.pm (original)
+++ jifty/trunk/lib/Jifty/Action/Record.pm Sun Oct 22 20:21:49 2006
@@ -281,7 +281,29 @@
$field_info->{$field} = $info;
}
- $self->_cached_arguments($field_info);
+ if ($self->can('PARAMS')) {
+ use Hash::Merge qw( merge );
+
+ # User-defined declarative schema fields can override default ones here
+ my $params = $self->PARAMS;
+
+ # We really, really want our sort_order to prevail over user-defined ones
+ # (as opposed to all other param fields). So we do exactly that here.
+ while (my ($key, $param) = each %$params) {
+ defined(my $sort_order = $param->sort_order) or next;
+
+ # The .99 below means that it's autogenerated by Jifty::Param::Schema.
+ if ($sort_order =~ /\.99$/) {
+ $param->sort_order($field_info->{$key}{sort_order});
+ }
+ }
+
+ $self->_cached_arguments(merge($field_info, $params));
+ }
+ else {
+ $self->_cached_arguments($field_info);
+ }
+
return $self->_cached_arguments();
}
Modified: jifty/trunk/lib/Jifty/Param/Schema.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Param/Schema.pm (original)
+++ jifty/trunk/lib/Jifty/Param/Schema.pm Sun Oct 22 20:21:49 2006
@@ -110,24 +110,22 @@
Class::Data::Inheritable::mk_classdata($from => qw/PARAMS/);
my @params = &declare($code);
- my $count = 1; # Start at 1, increment by 10
+
+ # The .99 here is a flag for Jifty::Action::Record to mark autogenerated orders
+ my $count = 10000.99;
foreach my $param (@params) {
next if !ref($param) or defined($param->sort_order);
$param->sort_order($count);
$count += 10;
}
- if ($from->can('SUPER::PARAMS')) {
-
-# 21:07 <obra> audreyt: how hard would it be to let declarative action subclasses modify or add arguments
-# 21:08 <audreyt> obra: line 121 Jifty::Param::Schema
-# 21:09 <audreyt> obra: semantically, add a hook there would do
-#
-
- unshift @params, %{ $from->can('SUPER::PARAMS')->() || {} }
+ if (my $super_params = $from->can('SUPER::PARAMS')) {
+ use Hash::Merge qw( merge );
+ $from->PARAMS(merge( $super_params->(), { @params } ));
+ }
+ else {
+ $from->PARAMS({ @params });
}
-
- $from->PARAMS({ @params });
no strict 'refs';
push @{$from . '::ISA'}, 'Jifty::Action';
More information about the Jifty-commit
mailing list