Re: OO question



On Feb 26, 11:20 am, paik...@xxxxxxxxxxxxxx (Dermot) wrote:
Hi All,

I am trying to work with the CGI::FormBuilder module in a Catalyst
environment. My question is more about OO programming than either of those 2
modules though.

I am trying to create a method/sub that will create a form to either edit or
add an entry. I am creating the initial object and depending on whether or
not the entry already exists, I want to set-up some aspects of my object
(making sense??). So I want to create the object, assign it to a variable
and make changes to it (or not) later depending on some condition. Here's an
abridged version of what I have done so far:

use strict;
use warnings;
...snip

sub edit : Local Form {
  my ($self, $c, $id) = @_;

# Here comes my form
my $fb = $self->formbuilder->field(
                name  => 'Users',
                type => 'select',
                options =>
                        [ map { [ $_ -> id, $_->code ] }
$c->model('Files::users')->all ],
                required => 1,
               #value => undef
        );
...
  if ($id) {
      $fb->{value} = $some_default_val;
  }

}

So I guess the question is what sort of structure have I created initially
with $fb and $self and does $fb->{value} make sense. Can I add an attribute
to an object after I've created it in this way.

Go back to basics. An object is just a hash[1], a reference to which
happens to be blessed into a specific class. But it's still just a
hash. Anything you can do to a normal hash, you can do to an object.
That includes adding new key/value pairs to it.

So yes, it's perfectly allowed. No reason you can't.

Paul Lalli

[1] in this case, of course. You're equally able to make an object
out of a reference to a scalar, an array, a filehandle, or pretty much
anything else...

.



Relevant Pages

  • Re: Solving the lib mismatch problem
    ... This section is pointed to by an entry in the section table with the ... The number of entries in the table is determined by DT_VERDEFNUM. ... This is an index into the string section referenced in the section ... Offset in the string section reference by the link in the section ...
    (comp.unix.programmer)
  • Re: PHP5 and class inheritance question
    ... A handle is not a pointer. ... a handle in php lets php lookup an entry in the symbol table. ... handle points to a symbol table entry where information is stored. ... as for pointer v. reference in a specific ...
    (comp.lang.php)
  • Re: ADAM:Delete an DN - What should happen?
    ... What you have is called "DN value" or "DN reference". ... automatically removed from all groups that he was a member of. ... > another area of ADAM ... > location to determine if the entry was actually gone and I ...
    (microsoft.public.windows.server.active_directory)
  • Re: The References Group: please help me with some problems
    ... just the other day I noticed that StyleEase didn't have a reference ... entry option for books that have both editors and translators. ... Thank you for clarifying the difference between Chicago and Turabian. ... you want to indent. ...
    (microsoft.public.word.docmanagement)
  • Re: ADAM:Delete an DN - What should happen?
    ... What do you mean by "until this oustanding reference ... >presence of linkId in the attribute definition. ... >> another area of ADAM ... >> Distinguished Name entry will be removed also without ...
    (microsoft.public.windows.server.active_directory)