Remove debugging code.
[catagits/Catalyst-Controller-DBIC-API.git] / lib / Catalyst / Controller / DBIC / API / RequestArguments.pm
index e9e2139..ad9280e 100644 (file)
@@ -90,6 +90,20 @@ page is what page to return while paging
         predicate => 'has_page',
     );
 
+=attribute_public offset is ro, isa: Int
+
+offset specifies where to start the paged result (think SQL LIMIT)
+
+=cut
+
+    has 'offset' =>
+    (
+        is => 'ro',
+        writer => '_set_offset',
+        isa => Int,
+        predicate => 'has_offset',
+    );
+
 =attribute_public ordered_by is: ro, isa: L<Catalyst::Controller::DBIC::API::Types/OrderedBy>
 
 ordered_by is passed to ->search to determine sorting
@@ -237,7 +251,7 @@ Like the synopsis in DBIC::API shows, you can declare a "template" of what is al
         },
     );
 
-=attribute_public search is: ro, isa: HashRef
+=attribute_public search is: ro, isa: L<Catalyst::Controller::DBIC::API::Types/SearchParameters>
 
 search contains the raw search parameters. Upon setting, a trigger will fire to format them, set search_parameters, and set search_attributes.
 
@@ -286,7 +300,7 @@ Please see L</generate_parameters_attributes> for details on how the format work
         },
     );
 
-=attribute_public search_parameters is:ro, isa: L<Catalyst::Controller::DBIC::API/Types/SearchParameters>
+=attribute_public search_parameters is:ro, isa: L<Catalyst::Controller::DBIC::API::Types/SearchParameters>
 
 search_parameters stores the formatted search parameters that will be passed to ->search
 
@@ -457,9 +471,10 @@ request_data holds the raw (but deserialized) data for ths request
             $self->_set_as($new->{$controller->as_arg}) if exists $new->{$controller->as_arg};
             $self->_set_grouped_by($new->{$controller->grouped_by_arg}) if exists $new->{$controller->grouped_by_arg};
             $self->_set_ordered_by($new->{$controller->ordered_by_arg}) if exists $new->{$controller->ordered_by_arg};
-            $self->_set_search($new->{$controller->search_arg}) if exists $new->{$controller->search_arg};
             $self->_set_count($new->{$controller->count_arg}) if exists $new->{$controller->count_arg};
             $self->_set_page($new->{$controller->page_arg}) if exists $new->{$controller->page_arg};
+            $self->_set_offset($new->{$controller->offset_arg}) if exists $new->{$controller->offset_arg};
+            $self->_set_search($new->{$controller->search_arg}) if exists $new->{$controller->search_arg};
         }
     );
 
@@ -473,7 +488,6 @@ format_search_parameters iterates through the provided params ArrayRef, calling
 
     method format_search_parameters => sub
     {
-        $DB::single = 1;
         my ($self, $params) = @_;
         
         my $genparams = [];
@@ -494,7 +508,6 @@ generate_column_parameters recursively generates properly aliased parameters for
 
     method generate_column_parameters => sub
     {
-        $DB::single = 1;
         my ($self, $source, $param, $join, $base) = @_;
         $base ||= 'me';
         my $search_params;
@@ -538,7 +551,6 @@ generate_parameters_attributes takes the raw search arguments and formats the pa
 
     method generate_parameters_attributes => sub
     {
-        $DB::single = 1;
         my ($self, $args) = @_;
 
         return ( $self->format_search_parameters($args), $self->search_attributes );
@@ -562,10 +574,21 @@ 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 => $self->page,
+            offset => $self->offset,
             join => $self->build_joins,
         };
 
+        if($self->has_page)
+        {
+            $search_attributes->{page} = $self->page;
+        }
+        elsif(!$self->has_page && defined($search_attributes->{offset}) && defined($search_attributes->{rows}))
+        {
+            $search_attributes->{page} = $search_attributes->{offset} / $search_attributes->{rows} + 1;
+            delete $search_attributes->{offset};
+        }
+        
+
         $search_attributes = 
         {   
             map { @$_ }