K
Koszalek Opalek
My code creates new objects and then populates them with
data, like this:
my $joe = Dude->new();
my $tom = Dude->new();
my $ann = Dude->new();
my $jane = Dude->new();
$joe->fill(
name => "joe",
friends => [ $ann, $tom ]
);
$jane->fill(
name => "jane",
friends => [ $ann ]
);
You will notice that the name field is always the same as
the variable that stores the object. What kind of magic
would I have to use in the constructor (or in the fill()
method) so that the name of the object does not have
to be specified explicitly? In other words, I would like to
be able to say:
$joe->fill(
friends => [ $ann, tom ]
);
$jane->fill(
friends => [ $ann ]
);
and still have the name field set. This saves typing and
makes sure the variable name and the name field match.
Is this possible?
Koszalek
data, like this:
my $joe = Dude->new();
my $tom = Dude->new();
my $ann = Dude->new();
my $jane = Dude->new();
$joe->fill(
name => "joe",
friends => [ $ann, $tom ]
);
$jane->fill(
name => "jane",
friends => [ $ann ]
);
You will notice that the name field is always the same as
the variable that stores the object. What kind of magic
would I have to use in the constructor (or in the fill()
method) so that the name of the object does not have
to be specified explicitly? In other words, I would like to
be able to say:
$joe->fill(
friends => [ $ann, tom ]
);
$jane->fill(
friends => [ $ann ]
);
and still have the name field set. This saves typing and
makes sure the variable name and the name field match.
Is this possible?
Koszalek