X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Controller-DBIC-API.git;a=blobdiff_plain;f=lib%2FCatalyst%2FController%2FDBIC%2FAPI%2FRequestArguments.pm;h=7b961b4819ecb689b10664a403a9fbad05f098bf;hp=e9e213982cd18b39252b329a55b64b4ca1f0ad42;hb=533075c7cc1bfd0ed993d273314ad46f0d85401b;hpb=d273984026646e5b57c052deef3fcb9121122060 diff --git a/lib/Catalyst/Controller/DBIC/API/RequestArguments.pm b/lib/Catalyst/Controller/DBIC/API/RequestArguments.pm index e9e2139..7b961b4 100644 --- a/lib/Catalyst/Controller/DBIC/API/RequestArguments.pm +++ b/lib/Catalyst/Controller/DBIC/API/RequestArguments.pm @@ -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 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 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 for details on how the format work }, ); -=attribute_public search_parameters is:ro, isa: L +=attribute_public search_parameters is:ro, isa: L search_parameters stores the formatted search parameters that will be passed to ->search @@ -448,18 +462,21 @@ request_data holds the raw (but deserialized) data for ths request is => 'ro', isa => HashRef, writer => '_set_request_data', + predicate => 'has_request_data', trigger => sub { my ($self, $new) = @_; my $controller = $self->_controller; + return unless defined($new) && keys %$new; $self->_set_prefetch($new->{$controller->prefetch_arg}) if exists $new->{$controller->prefetch_arg}; $self->_set_select($new->{$controller->select_arg}) if exists $new->{$controller->select_arg}; $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 +490,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 +510,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 +553,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 +576,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 { @$_ }