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=f490eedccddbcd58713434d5102672c17e0c4c3e;hp=7b961b4819ecb689b10664a403a9fbad05f098bf;hb=4a805f62625bb1e4152fd2ef25169ac6683ca611;hpb=533075c7cc1bfd0ed993d273314ad46f0d85401b diff --git a/lib/Catalyst/Controller/DBIC/API/RequestArguments.pm b/lib/Catalyst/Controller/DBIC/API/RequestArguments.pm index 7b961b4..f490eed 100644 --- a/lib/Catalyst/Controller/DBIC/API/RequestArguments.pm +++ b/lib/Catalyst/Controller/DBIC/API/RequestArguments.pm @@ -10,7 +10,6 @@ use namespace::autoclean; use Catalyst::Controller::DBIC::API::JoinBuilder; - =attribute_private search_validator A Catalyst::Controller::DBIC::API::Validator instance used solely to validate search parameters @@ -50,9 +49,9 @@ with 'MooseX::Role::BuildInstanceOf' => parameter static => ( isa => Bool, default => 0 ); role { - + my $p = shift; - + if($p->static) { requires qw/check_has_relation check_column_relation/; @@ -146,7 +145,7 @@ prefetch is passed to ->search to optimize the number of database fetches for jo ( is => 'ro', writer => '_set_prefetch', - isa => Prefetch, + isa => Prefetch, default => sub { $p->static ? [] : undef }, coerce => 1, trigger => sub @@ -191,20 +190,20 @@ Like the synopsis in DBIC::API shows, you can declare a "template" of what is al ( is => 'ro', writer => '_set_prefetch_allows', - isa => ArrayRef[ArrayRef|Str|HashRef], + isa => ArrayRef[ArrayRef|Str|HashRef], default => sub { [ ] }, predicate => 'has_prefetch_allows', trigger => sub { 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)) @@ -224,7 +223,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); } }, ); @@ -269,7 +268,7 @@ Please see L for details on how the format work trigger => sub { my ($self, $new) = @_; - + if($self->has_search_exposes and @{$self->search_exposes}) { foreach my $foo (@$new) @@ -292,7 +291,7 @@ Please see L for details on how the format work } } } - + my ($search_parameters, $search_attributes) = $self->generate_parameters_attributes($new); $self->_set_search_parameters($search_parameters); $self->_set_search_attributes($search_attributes); @@ -384,7 +383,7 @@ Please see L for more details. default => sub { $p->static ? [] : undef }, coerce => 1, trigger => sub - { + { my ($self, $new) = @_; if($self->has_select_exposes) { @@ -491,7 +490,7 @@ format_search_parameters iterates through the provided params ArrayRef, calling method format_search_parameters => sub { my ($self, $params) = @_; - + my $genparams = []; foreach my $param (@$params) @@ -512,7 +511,7 @@ generate_column_parameters recursively generates properly aliased parameters for { my ($self, $source, $param, $join, $base) = @_; $base ||= 'me'; - my $search_params; + my $search_params = {}; # build up condition foreach my $column (keys %$param) @@ -525,8 +524,7 @@ generate_column_parameters recursively generates properly aliased parameters for next; } - %$search_params = - %{ + $search_params = { %$search_params, %{ $self->generate_column_parameters ( $source->related_source($column), @@ -534,7 +532,7 @@ generate_column_parameters recursively generates properly aliased parameters for Catalyst::Controller::DBIC::API::JoinBuilder->new(parent => $join, name => $column), $column ) - }; + }}; } else { @@ -568,7 +566,7 @@ This builder method generates the search attributes { my ($self, $args) = @_; my $static = $self->_controller; - my $search_attributes = + my $search_attributes = { group_by => $self->grouped_by || ((scalar(@{$static->grouped_by})) ? $static->grouped_by : undef), order_by => $self->ordered_by || ((scalar(@{$static->ordered_by})) ? $static->ordered_by : undef), @@ -576,6 +574,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, }; @@ -589,15 +588,15 @@ This builder method generates the search attributes $search_attributes->{page} = $search_attributes->{offset} / $search_attributes->{rows} + 1; delete $search_attributes->{offset}; } - - $search_attributes = - { + + $search_attributes = + { map { @$_ } grep { - defined($_->[1]) - ? + defined($_->[1]) + ? (ref($_->[1]) && reftype($_->[1]) eq 'HASH' && keys %{$_->[1]}) || (ref($_->[1]) && reftype($_->[1]) eq 'ARRAY' && @{$_->[1]}) || length($_->[1]) @@ -612,7 +611,7 @@ This builder method generates the search attributes if ($search_attributes->{page} && !$search_attributes->{rows}) { die 'list_page can only be used with list_count'; } - + if ($search_attributes->{select}) { # make sure all columns have an alias to avoid ambiguous issues # but allow non strings (eg. hashrefs for db procs like 'count') @@ -621,7 +620,7 @@ This builder method generates the search attributes } return $search_attributes; - + }; };