fixed failure because of Data::DPath >=0.41 by not using MooseX::Role::BuildInstanceO...
[catagits/Catalyst-Controller-DBIC-API.git] / lib / Catalyst / Controller / DBIC / API / RequestArguments.pm
index a2fee74..a6939f2 100644 (file)
@@ -6,47 +6,39 @@ use Catalyst::Controller::DBIC::API::Types(':all');
 use MooseX::Types::Moose(':all');
 use Scalar::Util('reftype');
 use Data::Dumper;
+use Catalyst::Controller::DBIC::API::Validator;
 use namespace::autoclean;
 
 use Catalyst::Controller::DBIC::API::JoinBuilder;
 
-=for Pod::Coverage check_rel
-
 =attribute_private search_validator
 
 A Catalyst::Controller::DBIC::API::Validator instance used solely to validate search parameters
 
 =cut
 
-with 'MooseX::Role::BuildInstanceOf' =>
-{
-    'target' => 'Catalyst::Controller::DBIC::API::Validator',
-    'prefix' => 'search_validator',
-};
-
 =attribute_private select_validator
 
 A Catalyst::Controller::DBIC::API::Validator instance used solely to validate select parameters
 
 =cut
 
-with 'MooseX::Role::BuildInstanceOf' =>
-{
-    'target' => 'Catalyst::Controller::DBIC::API::Validator',
-    'prefix' => 'select_validator',
-};
-
 =attribute_private prefetch_validator
 
 A Catalyst::Controller::DBIC::API::Validator instance used solely to validate prefetch parameters
 
 =cut
 
-with 'MooseX::Role::BuildInstanceOf' =>
-{
-    'target' => 'Catalyst::Controller::DBIC::API::Validator',
-    'prefix' => 'prefetch_validator',
-};
+has [qw( search_validator select_validator prefetch_validator )] => (
+    is => 'ro',
+    isa => 'Catalyst::Controller::DBIC::API::Validator',
+    lazy => 1,
+    builder => '_build_validator',
+);
+
+sub _build_validator {
+    return Catalyst::Controller::DBIC::API::Validator->new;
+}
 
 parameter static => ( isa => Bool, default => 0 );
 
@@ -199,13 +191,13 @@ Like the synopsis in DBIC::API shows, you can declare a "template" of what is al
         {
             my ($self, $new) = @_;
 
-            sub check_rel {
+            sub _check_rel {
                 my ($self, $rel, $static) = @_;
                 if(ArrayRef->check($rel))
                 {
                     foreach my $rel_sub (@$rel)
                     {
-                        $self->check_rel($rel_sub, $static);
+                        $self->_check_rel($rel_sub, $static);
                     }
                 }
                 elsif(HashRef->check($rel))
@@ -225,7 +217,7 @@ Like the synopsis in DBIC::API shows, you can declare a "template" of what is al
 
             foreach my $rel (@$new)
             {
-                $self->check_rel($rel, $p->static);
+                $self->_check_rel($rel, $p->static);
             }
         },
     );
@@ -518,8 +510,9 @@ generate_column_parameters recursively generates properly aliased parameters for
         # build up condition
         foreach my $column (keys %$param)
         {
-            if($source->has_relationship($column))
+            if ($source->has_relationship($column))
             {
+                # check if the value isn't a hashref
                 unless (ref($param->{$column}) && reftype($param->{$column}) eq 'HASH')
                 {
                     $search_params->{join('.', $base, $column)} = $param->{$column};
@@ -536,10 +529,22 @@ generate_column_parameters recursively generates properly aliased parameters for
                     )
                 }};
             }
-            else
+            elsif ($source->has_column($column))
             {
                 $search_params->{join('.', $base, $column)} = $param->{$column};
             }
+            # might be a sql function instead of a column name
+            # e.g. {colname => {like => '%foo%'}}
+            else
+            {
+                # but only if it's not a hashref
+                unless (ref($param->{$column}) && reftype($param->{$column}) eq 'HASH') {
+                    $search_params->{join('.', $base, $column)} = $param->{$column};
+                }
+                else {
+                    die "$column is neither a relationship nor a column\n";
+                }
+            }
         }
 
         return $search_params;
@@ -576,6 +581,7 @@ This builder method generates the search attributes
             as => $self->as || ((scalar(@{$static->as})) ? $static->as : undef),
             prefetch => $self->prefetch || $static->prefetch || undef,
             rows => $self->count || $static->count,
+            page => $static->page,
             offset => $self->offset,
             join => $self->build_joins,
         };