Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Catalyst: Users

Change in $c->engine->prepare_parameters

 

 

Catalyst users RSS feed   Index | Next | Previous | View Threaded


moseley at hank

Aug 3, 2012, 6:39 AM

Post #1 of 5 (335 views)
Permalink
Change in $c->engine->prepare_parameters

I have some older code that calls $c->prepare_parameters after making some
modification to the request. If that's an acceptable use is questionable,
but we have a change in behavior regardless from 5.90007 to 5.90008-TRIAL.

Essentially, now if you do some thing a bit odd like this:

$c->req->parameters( {} );
$c->prepare_parameters;


Then $c->req->parameters stays an empty hash. Previous to 5.90008-TRIAL
this would prepare the parameters again.


The documentation in C::Engine says:


> =head2 $self->prepare_parameters($c)


> sets up parameters from query and post parameters.


which is only true now when $req->parameters has not already been called.


And in 5.90008-TRIAL the prepare_parameters was moved to Catalyst::Request,
with the documentation:

=head2 $self->prepare_parameters()
>


Ensures that the body has been parsed, then builds the parameters, which are
> combined from those in the request and those in the body.


What it doesn't do any more is set $c->req->parameters when called
directly, only when called as a builder.


I don't think prepare_parameters should be both a builder AND a method.
What about this approach:

Change the Request parameters attribute to have a builder and a clearer:

has parameters => (
is => 'rw',
lazy => 1,
builder => '_build_parameters',
clearer => 'clear_parameters',
);


Then rename the existing "prepare_parameters" to "_build_parameters",
because that's what it is, and then add a new method:

sub prepare_parameters {
my $self = shift;
$self->clear_parameters;
return $self->parameters;
}


And likewise in the Engine.pm:

sub prepare_parameters {
my ( $self, $c ) = @_;
$c->request->clear_parameters;
return $c->request->parameters;
}




--
Bill Moseley
moseley [at] hank


bobtfish at bobtfish

Aug 4, 2012, 6:53 AM

Post #2 of 5 (319 views)
Permalink
Re: Change in $c->engine->prepare_parameters [In reply to]

On 3 Aug 2012, at 14:39, Bill Moseley wrote:

> What it doesn't do any more is set $c->req->parameters when called directly, only when called as a builder.
>
>
> I don't think prepare_parameters should be both a builder AND a method. What about this approach:

+1, except I think the clearer should be _clear_parameters - we don't want to add a new public method for this if it can be avoided.

Fancy making a 'proper' patch someone can apply which does these changes and updates the relevant doc?

Cheers
t0m


_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


moseley at hank

Aug 4, 2012, 7:37 AM

Post #3 of 5 (319 views)
Permalink
Re: Change in $c->engine->prepare_parameters [In reply to]

I'll work on a patch and docs, yes.

On Sat, Aug 4, 2012 at 6:53 AM, Tomas Doran <bobtfish [at] bobtfish> wrote:

>
> On 3 Aug 2012, at 14:39, Bill Moseley wrote:
>
> > What it doesn't do any more is set $c->req->parameters when called
> directly, only when called as a builder.
> >
> >
> > I don't think prepare_parameters should be both a builder AND a method.
> What about this approach:
>
> +1, except I think the clearer should be _clear_parameters - we don't want
> to add a new public method for this if it can be avoided.
>
> Fancy making a 'proper' patch someone can apply which does these changes
> and updates the relevant doc?
>
> Cheers
> t0m
>
>
> _______________________________________________
> List: Catalyst [at] lists
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive:
> http://www.mail-archive.com/catalyst [at] lists/
> Dev site: http://dev.catalyst.perl.org/
>



--
Bill Moseley
moseley [at] hank


moseley at hank

Aug 4, 2012, 6:19 PM

Post #4 of 5 (317 views)
Permalink
Re: Change in $c->engine->prepare_parameters [In reply to]

See attached.

Let me know if you want something else.

I'm mixed on of the clear should be private. I made it that way, but I
wonder if there could be a use case to reset the parameters so next time
$c->req->parameters is called they get built again. I guess in that case
why wouldn't they just call $c->prepare_parameters again?

On Sat, Aug 4, 2012 at 6:53 AM, Tomas Doran <bobtfish [at] bobtfish> wrote:

>
> On 3 Aug 2012, at 14:39, Bill Moseley wrote:
>
> > What it doesn't do any more is set $c->req->parameters when called
> directly, only when called as a builder.
> >
> >
> > I don't think prepare_parameters should be both a builder AND a method.
> What about this approach:
>
> +1, except I think the clearer should be _clear_parameters - we don't want
> to add a new public method for this if it can be avoided.
>
> Fancy making a 'proper' patch someone can apply which does these changes
> and updates the relevant doc?
>
> Cheers
> t0m
>
>
> _______________________________________________
> List: Catalyst [at] lists
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive:
> http://www.mail-archive.com/catalyst [at] lists/
> Dev site: http://dev.catalyst.perl.org/
>



--
Bill Moseley
moseley [at] hank
Attachments: prepare_parameters.diff (2.50 KB)
  live_engine_request_prepare_parameters.t (0.99 KB)


moseley at hank

Aug 7, 2012, 12:52 PM

Post #5 of 5 (305 views)
Permalink
Re: Change in $c->engine->prepare_parameters [In reply to]

Did this help?

On Sat, Aug 4, 2012 at 6:19 PM, Bill Moseley <moseley [at] hank> wrote:

> See attached.
>
> Let me know if you want something else.
>
> I'm mixed on of the clear should be private. I made it that way, but I
> wonder if there could be a use case to reset the parameters so next time
> $c->req->parameters is called they get built again. I guess in that case
> why wouldn't they just call $c->prepare_parameters again?
>
> On Sat, Aug 4, 2012 at 6:53 AM, Tomas Doran <bobtfish [at] bobtfish> wrote:
>
>>
>> On 3 Aug 2012, at 14:39, Bill Moseley wrote:
>>
>> > What it doesn't do any more is set $c->req->parameters when called
>> directly, only when called as a builder.
>> >
>> >
>> > I don't think prepare_parameters should be both a builder AND a method.
>> What about this approach:
>>
>> +1, except I think the clearer should be _clear_parameters - we don't
>> want to add a new public method for this if it can be avoided.
>>
>> Fancy making a 'proper' patch someone can apply which does these changes
>> and updates the relevant doc?
>>
>> Cheers
>> t0m
>>
>>
>> _______________________________________________
>> List: Catalyst [at] lists
>> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
>> Searchable archive:
>> http://www.mail-archive.com/catalyst [at] lists/
>> Dev site: http://dev.catalyst.perl.org/
>>
>
>
>
> --
> Bill Moseley
> moseley [at] hank
>



--
Bill Moseley
moseley [at] hank

Catalyst users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.