Thread

Posted on Tue Mar 4 21:58:55 2008 by cowanbill
Should GET-only accessor give an error message if given a parameter?
I defined a GET accessor (":Get(first_name)" below) and I then used that accessor with a parameter value. The "first_name" accessor retrieved the old field value and quietly ignored the parameter value, '*** SetValue ***'. No error message was given! This happened with OIO version 3.38, Perl 5.8.8 on Windows.
What is the correct behavior if GET-ONLY accessor are given parameter values?
Thanks, Bill
use strict; use warnings; package My_Class; { use Object::InsideOut ; my @first_name :Field :Arg(first_name) :Get(first_name) #-- Only define a getter, no setter! :Default('***Default***') ; } #-- end of package scope. package main; my $obj = My_Class->new(first_name => 'Larry'); #-- Note that this SET OPERATION does not give error. #-- The SET value is silently ignored! print "1. Object field is: ", $obj->first_name('*** SetValue ***'), "\n"; print "2. Object field is: ", $obj->first_name(), "\n"; print "**** Normal Exit **** \n"; exit; The output is: 1. Object field is: Larry 2. Object field is: Larry **** Normal Exit ****
.
Direct Responses: 7269 | Write a response
Posted on Tue Mar 4 22:08:32 2008 by jdhedden in response to 7268
Re: Should GET-only accessor give an error message if given a parameter?
The get accessors generated by OIO ignore any args sent to them. That's a very standard behavior. Either name the accessor with the 'get_' prefix, or documented that it is 'get only'.

If you want something to be done with args (or to generate an error), you'll need to write your own accessors.
Write a response