Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Hash-FieldHash CPAN distribution.

Report information
The Basics
Id: 68408
Status: resolved
Priority: 0/
Queue: Hash-FieldHash

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

Bug Information
Severity: Important
Broken in: 0.10
Fixed in: (no value)



Subject: Methods sometimes return values, sometimes objects
Hi I'm worried by the fact that a getter/setter, when called with a parameter, sets the value, but returns the object and not the value. 1) x.pl: #!/usr/bin/env perl package Module; use strict; use warnings; use Hash::FieldHash ':all'; fieldhash my %current => 'current'; fieldhash my %start => 'start'; # ----------------------------------------------- sub _init { my($self, $arg) = @_; $$arg{current} = ''; # Can't be set in new(). $$arg{start} ||= ''; # Can be set in new(). $self = from_hash($self, $arg); $self -> current($self -> start); return $self; } # End of _init. # ----------------------------------------------- sub new { my($class, %arg) = @_; my($self) = bless {}, $class; $self = $self -> _init(\%arg); return $self; } # End of new. # ----------------------------------------------- sub run { my($self) = @_; } # End of run. # ----------------------------------------------- package main; use strict; use warnings; # ----------------------------------------------- my($m) = Module -> new(start => 'One'); print "Test 1\n"; print "start: ", $m -> start, ". \n"; print "current: ", $m -> current, ". \n"; $m -> start('Two'); print "Test 2\n"; print "start: ", $m -> start, ". \n"; print "current: ", $m -> current, ". \n"; $m -> current($m -> start); print "Test 3\n"; print "start: ", $m -> start, ". \n"; print "current: ", $m -> current, ". \n"; $m -> start('Three'); print "Test 4\n"; print "start: ", $m -> start, ". \n"; print "current: ", $m -> current($m -> start), ". \n"; 2) x.log Test 1 start: One. current: One. Test 2 start: Two. current: One. Test 3 start: Two. current: Two. Test 4 start: Three. current: Module=HASH(0x1024e88). Why is the last line not Three? Is this by design or a bug :-)? My expectation is that the result should be Three. It's certainly very confusing. Cheers Ron
Hmm... I must admit that it might be confusing, but it is by design. Those setters that return the object itself are called as "chained setters" (cf. http://search.cpan.org/dist/Class-Accessor- Chained/lib/Class/Accessor/Chained.pm). So it is not a bug ;) -- Goro Fuji (gfx) GFUJI at CPAN.org
Subject: Re: [rt.cpan.org #68408] Methods sometimes return values, sometimes objects
Date: Thu, 26 May 2011 08:58:23 +1000
To: bug-Hash-FieldHash [...] rt.cpan.org
From: Ron Savage <ron [...] savage.net.au>
Hi Goro On Wed, 2011-05-25 at 09:50 -0400, Goro Fuji via RT wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=68408 > > > Hmm... I must admit that it might be confusing, but it is by design. > Those setters that return the object itself are called as "chained > setters" (cf. http://search.cpan.org/dist/Class-Accessor- > Chained/lib/Class/Accessor/Chained.pm). > So it is not a bug ;)
Ahhhhh. I'd forgotten that some people are quite keen on chaining. I'll have to make a note to myself about that. Perhaps you could add a note to the docs, although there's no need to release a new version just for that. Is it true to say that if a method is called with a parameter, Hash::FieldHash /always/ returns the object, whereas without it always returns the value? -- Ron Savage http://savage.net.au/ Ph: 0421 920 622
Mention to what accessors return in 0.12. Thanks. -- Goro Fuji (gfx) GFUJI at CPAN.org