[Catalyst-commits] r8307 - in CatalystX-CRUD/CatalystX-CRUD/trunk: . lib/CatalystX/CRUD lib/CatalystX/CRUD/Model

karpet at dev.catalyst.perl.org karpet at dev.catalyst.perl.org
Thu Aug 28 04:18:54 BST 2008


Author: karpet
Date: 2008-08-28 04:18:54 +0100 (Thu, 28 Aug 2008)
New Revision: 8307

Modified:
   CatalystX-CRUD/CatalystX-CRUD/trunk/Changes
   CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Controller.pm
   CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Model/Utils.pm
   CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/ModelAdapter.pm
Log:
+        * clean up old style $self->config->{value} to instead use $self->value in Controller
+        * add app_class() and model_meta() accessors to ModelAdapter 
+        * in base Controller, rename view_on_single_result() method to uri_for_view_on_single_result and make
+          accessor for the config value 'view_on_single_result'
+        * change all reserved param names in Model::Utils to use 'cxc-' prefix instead of '_'. Backwards compat
+          is preserved where possible.


Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/Changes
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/Changes	2008-08-27 19:23:12 UTC (rev 8306)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/Changes	2008-08-28 03:18:54 UTC (rev 8307)
@@ -143,6 +143,12 @@
         * fix uninit value warning in Controller
         * change REST create() : Local to _rest_create() : Path('create') to make it easier for
           create_form() to call create() in superclass.
+        * clean up old style $self->config->{value} to instead use $self->value in Controller
+        * add app_class() and model_meta() accessors to ModelAdapter 
+        * in base Controller, rename view_on_single_result() method to uri_for_view_on_single_result and make
+          accessor for the config value 'view_on_single_result'
+        * change all reserved param names in Model::Utils to use 'cxc-' prefix instead of '_'. Backwards compat
+          is preserved where possible.
 
 
 

Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Controller.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Controller.pm	2008-08-27 19:23:12 UTC (rev 8306)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Controller.pm	2008-08-28 03:18:54 UTC (rev 8307)
@@ -24,6 +24,7 @@
         allow_GET_writes
         naked_results
         page_size
+        view_on_single_result
         )
 );
 
@@ -639,13 +640,13 @@
     my $self = $class->next::method( $app_class, $args );
 
     # if model_adapter class is defined, load and instantiate it.
-    if ( $self->config->{model_adapter} ) {
-        Catalyst::Utils::ensure_class_loaded(
-            $self->config->{model_adapter} );
+    if ( $self->model_adapter ) {
+        Catalyst::Utils::ensure_class_loaded( $self->model_adapter );
         $self->model_adapter(
-            $self->config->{model_adapter}->new(
-                {   model_name => $self->config->{model_name},
-                    model_meta => $self->config->{model_meta}
+            $self->model_adapter->new(
+                {   model_name => $self->model_name,
+                    model_meta => $self->model_meta,
+                    app_class  => $app_class,
                 }
             )
         );
@@ -816,9 +817,9 @@
     1;
 }
 
-=head2 view_on_single_result( I<context>, I<results> )
+=head2 uri_for_view_on_single_result( I<context>, I<results> )
 
-Returns 0 unless the config() key of the same name is true.
+Returns 0 unless view_on_single_result returns true.
 
 Otherwise, calls the primary_key() value on the first object
 in I<results> and constructs a uri_for() value to the edit()
@@ -826,9 +827,9 @@
 
 =cut
 
-sub view_on_single_result {
+sub uri_for_view_on_single_result {
     my ( $self, $c, $results ) = @_;
-    return 0 unless $self->config->{view_on_single_result};
+    return 0 unless $self->view_on_single_result;
 
     # TODO require $results be a CatalystX::CRUD::Results object
     # so we can call next() instead of assuming array ref.
@@ -903,7 +904,8 @@
     if (   $results
         && $count == 1
         && $c->stash->{view_on_single_result}
-        && ( my $uri = $self->view_on_single_result( $c, $results ) ) )
+        && ( my $uri = $self->uri_for_view_on_single_result( $c, $results ) )
+        )
     {
         $c->log->debug("redirect for single_result") if $c->debug;
         $c->response->redirect($uri);

Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Model/Utils.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Model/Utils.pm	2008-08-27 19:23:12 UTC (rev 8306)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Model/Utils.pm	2008-08-28 03:18:54 UTC (rev 8307)
@@ -59,40 +59,42 @@
 
 =over
 
-=item _order
+=item cxc-order
 
 Sort order. Should be a SQL-friendly string parse-able by Sort::SQL.
 
-=item _sort
+=item cxc-sort
 
-Instead of _order, can pass one column name to sort by.
+Instead of cxc-order, can pass one column name to sort by.
 
-=item _dir
+=item cxc-dir
 
-With _sort, pass the direction in which to sort.
+With cxc-sort, pass the direction in which to sort.
 
-=item _page_size
+=item cxc-page_size
 
-For the Data::Pageset pager object. Defaults to page_size(). An upper limit of 200
-is implemented by default to reduce the risk of a user [unwittingly] creating a denial
+For the Data::Pageset pager object. 
+Defaults to page_size(). An upper limit of 200
+is implemented by default to reduce the risk of 
+a user [unwittingly] creating a denial
 of service situation.
 
-=item _page
+=item cxc-page
 
 What page the current request is coming from. Used to set the offset value
 in the query. Defaults to C<1>.
 
-=item _offset
+=item cxc-offset
 
 Pass explicit row to offset from in query. If not present, deduced from
-_page and _page_size.
+cxc-page and cxc-page_size.
 
-=item _no_page
+=item cxc-no_page
 
-Ignore _page_size, _page and _offset and do not return a limit
+Ignore cxc-page_size, cxc-page and cxc-offset and do not return a limit
 or offset value.
 
-=item _op
+=item cxc-op
 
 If set to C<OR> then the query columns will be marked as OR'd together,
 rather than AND'd together (the default).
@@ -104,9 +106,19 @@
 sub _which_sort {
     my ( $self, $c ) = @_;
     my $params = $c->req->params;
-    return $params->{'_order'} if defined $params->{'_order'};
-    return join( ' ', $params->{'_sort'}, $params->{'_dir'} )
-        if defined( $params->{'_sort'} ) && defined( $params->{'_dir'} );
+
+    # backwards compat
+    for my $p (qw( cxc-order _order )) {
+        return $params->{$p} if defined $params->{$p};
+    }
+
+    for my $p (qw( cxc-sort _sort )) {
+        my $dir = $params->{'cxc-dir'}
+            || $params->{'_dir'};
+        return join( ' ', $params->{$p}, $dir )
+            if defined( $params->{$p} ) && defined($dir);
+    }
+
     my %pks = $c->controller->get_primary_key($c);
     return join( ' ', map { $_ . ' DESC' } keys %pks );
 }
@@ -122,15 +134,16 @@
     my $params    = $c->req->params;
     my $sp        = Sort::SQL->string2array( $self->_which_sort($c) );
     my $s         = join( ' ', map { each %$_ } @$sp );
-    my $offset    = $params->{'_offset'};
-    my $page_size = $params->{'_page_size'}
+    my $offset    = $params->{'cxc-offset'} || $params->{'_offset'};
+    my $page_size = $params->{'cxc-page_size'}
+        || $params->{'_page_size'}
         || $c->controller->page_size
         || $self->page_size;
 
     # don't let users DoS us. unless they ask to (see _no_page).
     $page_size = 200 if $page_size > 200;
 
-    my $page = $params->{'_page'} || 1;
+    my $page = $params->{'cxc-page'} || $params->{'_page'} || 1;
 
     if ( !defined($offset) ) {
         $offset = ( $page - 1 ) * $page_size;
@@ -150,7 +163,7 @@
     );
 
     # undo what we've done if asked.
-    if ( $params->{'_no_page'} ) {
+    if ( $params->{'cxc-no_page'} ) {
         delete $query{limit};
         delete $query{offset};
     }
@@ -171,9 +184,10 @@
     for my $p ( sort keys %$q ) {
         my @v = @{ $q->{$p} };
         next unless grep {m/\S/} @v;
-        push( @s, "$p = " . join( ' or ', @v ) );
+        push( @s, "$p = " . join( ' OR ', @v ) );
     }
-    my $op = $self->context->req->params->{_op} || 'AND';
+    my $params = $self->context->req->params;
+    my $op = $params->{'cxc-op'} || $params->{'_op'} || 'AND';
     return join( " $op ", @s );
 }
 
@@ -208,11 +222,13 @@
     my $like = $self->use_ilike ? 'ilike' : 'like';
     my $treat_like_int
         = $self->can('treat_like_int') ? $self->treat_like_int : {};
+    my $params = $c->req->params;
+    my $oper = $params->{'cxc-op'} || $params->{'_op'};
     my $ORify
-        = ( exists $c->req->params->{_op} && $c->req->params->{_op} eq 'OR' )
+        = ( defined $oper && $oper eq 'OR' )
         ? 1
         : 0;
-    my $fuzzy = $c->req->params->{_fuzzy} || 0;
+    my $fuzzy = $params->{'cxc-fuzzy'} || $params->{'_fuzzy'} || 0;
 
     for my $p (@$field_names) {
 
@@ -272,13 +288,15 @@
     my ( $self, $count ) = @_;
     my $c      = $self->context;
     my $params = $c->req->params;
-    return if $params->{'_no_page'};
+    return if ( $params->{'cxc-no_page'} or $params->{'_no_page'} );
     return Data::Pageset->new(
         {   total_entries    => $count,
-            entries_per_page => $params->{'_page_size'}
+            entries_per_page => $params->{'cxc-page_size'}
+                || $params->{'_page_size'}
                 || $c->controller->page_size
                 || $self->page_size,
-            current_page => $params->{'_page'}
+            current_page => $params->{'cxc-page'}
+                || $params->{'_page'}
                 || 1,
             pages_per_set => 10,        #TODO make this configurable?
             mode          => 'slide',

Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/ModelAdapter.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/ModelAdapter.pm	2008-08-27 19:23:12 UTC (rev 8306)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/ModelAdapter.pm	2008-08-28 03:18:54 UTC (rev 8307)
@@ -8,7 +8,7 @@
 use Class::C3;
 use Carp;
 
-__PACKAGE__->mk_accessors(qw( model_name context ));
+__PACKAGE__->mk_accessors(qw( model_name model_meta context app_class ));
 
 =head1 NAME
 




More information about the Catalyst-commits mailing list