Skip Menu |

This queue is for tickets about the Class-MethodMaker CPAN distribution.

Report information
The Basics
Id: 19206
Status: rejected
Priority: 0/
Queue: Class-MethodMaker

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

Bug Information
Severity: Critical
Broken in: 2.08
Fixed in: (no value)



Subject: hash doesn't work as expected
I can't seem to find a way to retrieve a value from a "hash" element: --- package Foo; use strict; use Class::MethodMaker [ hash => [ 'hash' ], new => ['new'] ] ; package main; use strict; use Data::Dumper; my $f = Foo->new(); $f->hash(a => 'b'); # print Dumper($f->hash('a')); # Uneven number of elements error print Dumper($f->hash_get('a')); --- Knowing Class::MethodMaker < 2.00, I expected ->hash($key) to return $key's value, but it throws an error like "uneven number of elements given". hash_get($key) returns the entire hash. Shouldn't these return $key's corresponding value?
Hi! Thank you for your report. Sorry for answering that late. On Thu May 11 06:40:19 2006, DMAKI wrote: Show quoted text
> I can't seem to find a way to retrieve a value from a "hash" element: > > --- > > package Foo; > use strict; > use Class::MethodMaker > [ hash => [ 'hash' ], > new => ['new'] > ] > ; > > package main; > use strict; > use Data::Dumper; > > my $f = Foo->new(); > $f->hash(a => 'b'); > # print Dumper($f->hash('a')); # Uneven number of elements error > print Dumper($f->hash_get('a')); > > ---
I don't know version 1.x but at least in 2.x it is working as documented. What you try above is similar to this chapter http://search.cpan.org/~schwigon/Class-MethodMaker-2.12/lib/Class/MethodMaker.pm#Naming although there an array is used. Show quoted text
> Knowing Class::MethodMaker < 2.00, I expected ->hash($key) to return > $key's value, but it throws an error like "uneven number of elements > given". hash_get($key) returns the entire hash. Shouldn't these return > $key's corresponding value?
Not really; $f->hash() without arguments should return the value of, well, a member called "hash". Giving values inside the parens, $f->hash(FOO => $BAR), will set the value of the member called "hash". That's why it complains when you don't give it even number of elements. Your example will be more clear if you name the member "foo" instead of "hash": use Class::MethodMaker [ hash => [ 'foo' ], new => ['new'] ]; and then use $f->foo(...) everywhere. I will close the bug, because I'm quite certain about it. Anyway, of course I could also be horribly wrong. :-) Then feel free to reopen it again. Thanks. Kind regards, Steffen -- Steffen Schwigon <ss5@renormalist.net> Dresden Perl Mongers <http://dresden-pm.org/> Deutscher Perl-Workshop <http://www.perl-workshop.de/>