X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FController%2FDBIC%2FAPI%2FRequestArguments.pm;h=7b961b4819ecb689b10664a403a9fbad05f098bf;hb=3d85db11441182964cf35818ed25265eec1b74e2;hp=f85a4e2f625cd91507c9ff979ea59a29b686b15b;hpb=d666a194afbf36c50785acff4e7fb4e04e534374;p=catagits%2FCatalyst-Controller-DBIC-API.git diff --git a/lib/Catalyst/Controller/DBIC/API/RequestArguments.pm b/lib/Catalyst/Controller/DBIC/API/RequestArguments.pm index f85a4e2..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 @@ -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 { @$_ }