Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

CGI.pm popup_menu labels bug?

by blogical (Pilgrim)
on Mar 26, 2006 at 15:05 UTC ( [id://539283]=perlquestion: print w/replies, xml ) Need Help??

blogical has asked for the wisdom of the Perl Monks concerning the following question:

Public review before I file a bug report:

I can't see why

CGI::popup_menu( -name => $_[0]->{fname}, -values => [ undef, @{ $_[0]->{field_meta}{$_[0]->{name}}{values} + }], -labels => $_[0]->{field_meta}{$_[0]->{name}}{labels}, -default => $_[0]->value, );
works as expected but
CGI::popup_menu( -name => $_[0]->{fname}, -values => [ undef, @{ $_[0]->{field_meta}{$_[0]->{name}}{values} + }], -default => $_[0]->value, -labels => $_[0]->{field_meta}{$_[0]->{name}}{labels}, );
doesn't have any labels. What could switching the order in a HASH matter? This is happening for two fields I have, one has two options and the other has over fifty, all values have labels except undef.

"One is enough. If you are acquainted with the principle, what do you care for the myriad instances and applications? To a philosopher, all news, as it is so called, is gossip, and they who edit and read it are old women over their tea."
- Henry David Thoreau, Walden

Replies are listed 'Best First'.
Re: CGI.pm popup_menu labels bug?
by Errto (Vicar) on Mar 26, 2006 at 16:40 UTC

    My guess is that the issue is that you're calling the value method in list context, and it's either is returning an empty list or a list of more than one element. As a result, popup_menu doesn't see any -labels argument and thus your popup menu has no labels.

    One minor technical point for the record. The list of arguments you're passing to popup_menu is just a list, not a hash, but presumably that function just reads its arguments into a hash anyway, so the effect is the same.

      Errto has got it, I think!
      #!perl -w use CGI::Util qw(rearrange); sub showval { return defined($_[0])?$_[0]:"<undef>" } sub testcall { my (@p) = @_; my($name,$values,$default,$labels,$attributes,$override,$tabindex, +@other) = rearrange([NAME,[VALUES,VALUE],[DEFAULT,DEFAULTS],LABELS, ATTRIBUTES,[OVERRIDE,FORCE],TABINDEX],@p); print "name = ", showval($name), "\n"; print "values = ", showval($values), "\n"; print "labels = ", showval($labels), "\n"; print "attributes = ", showval($attributes), "\n"; print "override = ", showval($override), "\n"; print "tabindex = ", showval($tabindex), "\n"; print "\@other = ", join(" ", @other), "\n"; } sub vooba { my @result = ("foo", "bar"); print "vooba: wantarray = ", wantarray, "\n"; return @result; } sub emptylist { my @result = (); return @result; } print "testcall1\n"; testcall( -name => "nameparm", -values => [ "array" ], -labels => "labels", -default => vooba(), ); print "\ntestcall2\n"; testcall( -name => "nameparm", -values => [ "array" ], -default => vooba(), -labels => "labels", ); print "\ntestcall3\n"; testcall( -name => "nameparm", -values => [ "array" ], -default => emptylist(), -labels => "labels", ); __END__
      Output:
      testcall1 vooba: wantarray = 1 name = nameparm values = ARRAY(0x225848) labels = labels attributes = <undef> override = <undef> tabindex = <undef> @other = bar testcall2 vooba: wantarray = 1 name = nameparm values = ARRAY(0x225848) labels = <undef> attributes = <undef> override = <undef> tabindex = <undef> @other = bar="-labels" testcall3 name = nameparm values = ARRAY(0x225848) labels = <undef> attributes = <undef> override = <undef> tabindex = <undef> @other =
        Dead on guys. *sigh* Fixed with a simple scalar($_[0]->value)

        "One is enough. If you are acquainted with the principle, what do you care for the myriad instances and applications?"
        - Henry David Thoreau, Walden

Re: CGI.pm popup_menu labels bug?
by lima1 (Curate) on Mar 26, 2006 at 15:40 UTC
      Not quite, but keen eyes. I need to call the method 'value', not get the value, of 'value'. They're related, but the value is an array ref, whereas the method returns either a joined string of values or an array.

      "One is enough. If you are acquainted with the principle, what do you care for the myriad instances and applications?"
      - Henry David Thoreau, Walden

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://539283]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (1)
As of 2024-07-19 06:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.