Skip Menu |
 

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the HTML-FormHandler CPAN distribution.

Report information
The Basics
Id: 48130
Status: resolved
Priority: 0/
Queue: HTML-FormHandler

People
Owner: Nobody in particular
Requestors: rsrchboy [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 0.26
Fixed in: (no value)



Subject: RFE: field stringification
Download (untitled) / with headers
text/plain 224b
It would be nice if HTML::FormHandler::Field (and its descendent classes) stringified properly, so that things like: my $user = $form->field('username'); print "My username is: $user\n"; would "just work". Thanks! :)
Download (untitled) / with headers
text/plain 728b
It's not possible to have it work exactly as you request. The field('name') method returns a field object. There's no way to tell that the scalar into which you're storing the result wants a string instead. It would be possible to overload the field object (see http://search.cpan.org/~nwclark/perl-5.8.9/lib/overload.pm) to stringify in cases like: print "The user is " . $form->field('user') . "\n"; But the value of the field is very easily gotten with: my $user = $form->field('user')->value; So I don't see that being able to stringify is very useful, since all it does is save seven characters of typing. If this is something that you really want, you could add a convenience method to your own FormHandler classes.
Subject: Re: [rt.cpan.org #48130] RFE: field stringification
Date: Tue, 28 Jul 2009 15:46:28 -0700
To: bug-HTML-FormHandler [...] rt.cpan.org
From: Chris Weyl <rsrchboy [...] cpan.org>
Download (untitled) / with headers
text/plain 1.2k
On Tue, Jul 28, 2009 at 8:07 AM, Gerda Shank via RT < bug-HTML-FormHandler@rt.cpan.org> wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=48130 > > > It's not possible to have it work exactly as you request. The > field('name') method returns a field object. There's no way to tell that > the scalar into which you're storing the result wants a string instead. > > It would be possible to overload the field object (see > http://search.cpan.org/~nwclark/perl-5.8.9/lib/overload.pm<http://search.cpan.org/%7Enwclark/perl-5.8.9/lib/overload.pm>) > to stringify > in cases like: > > print "The user is " . $form->field('user') . "\n"; > > But the value of the field is very easily gotten with: > > my $user = $form->field('user')->value; > > So I don't see that being able to stringify is very useful, since all it > does is save seven characters of typing. If this is something that you > really want, you could add a convenience method to your own FormHandler > classes. >
Sorry, I should have been more clear... I had meant to suggest the overloading of the field object to reduce it to it's value(). It would have been convenient to have out of the box, but I certainly can do it in my own classes. -Chris -- Chris Weyl Ex astris, scientia
From: mintywalker [...] gmail.com
Download (untitled) / with headers
text/plain 942b
On Thu Jul 23 18:07:18 2009, RSRCHBOY wrote: Show quoted text
> It would be nice if HTML::FormHandler::Field (and its descendent > classes) stringified properly, so that things like: > > my $user = $form->field('username'); > > print "My username is: $user\n"; > > would "just work".
What about my $user = $form->value('username'); which would be sugar for: sub value { my ($form, $fieldname) = @_; return $form->field($fieldname)->value; } It'd probably need to be smarter than that to handle multi valued by returning an array in array context, an array ref for multiple values called in scalar context, or a scalar if it's a single value. The advantage is that you get the shorter sugared syntax, yet it's explicit that what you're getting is the the value, not the Field object. It seems that "value" is already a method on the FormHandler object, so perhaps the name is wrong, but it's just sugar ... val('fieldname') perhaps?
Download (untitled) / with headers
text/plain 250b
Made a quick attempt to do stringification and lots of things broke.If somebody wants to submit a patch that passes the tests I'll take a look. The suggestion to provide a value method is actually a different issue. Will take it under consideration.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.