in reply to Re^2: use fields; # damnit
in thread use fields; # damnit
So, I am inspired, and I have been messing around with fields. But I am seeing some what seems to me to be odd behavior. (I am running perl 5.8.0 installed on Mac OS X, so maybe I need to update, if so, let me know.)
This compiles and runs with no error or warning. Am I doing something wrong, or am I just assuming too much?package Brain; use strict; use warnings; use fields qw/cells/; sub new { my $pkg = shift; my $self = $pkg->fields::new(); $self->{cells} = shift; $self; } package Dog; use strict; use warnings; use fields qw/intelligence/; sub new { my $pkg = shift; my $self = $pkg->fields::new(); my Brain $brain = Brain->new(shift); $self->{intelligence} = $brain; $self; } sub getBrain { my Dog $self = shift; return $self->{intelligence}; } package main; use strict; use warnings; my Dog $dog = Dog->new(10); my Dog $brain = $dog->getBrain(); my Brain $b = $brain;
Sorry for this question, but my Programming Perl book does not go into too much detail (at least not that I have come across yet) and the Damian OO book is at the office (and I am not). And looking over the docs for fields it is not clear either.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: use fields; # damnit
by tilly (Archbishop) on Aug 21, 2004 at 00:09 UTC | |
by stvn (Monsignor) on Aug 21, 2004 at 00:42 UTC | |
by tilly (Archbishop) on Aug 21, 2004 at 01:37 UTC | |
by stvn (Monsignor) on Aug 21, 2004 at 04:23 UTC | |
by adrianh (Chancellor) on Aug 21, 2004 at 08:21 UTC | |
| |
by Aristotle (Chancellor) on Aug 21, 2004 at 15:34 UTC | |
|
Re^4: use fields; # damnit
by nothingmuch (Priest) on Aug 21, 2004 at 09:08 UTC |